Enable Sonos devices discovering in config.lua | Allow networking in config.lua
This commit is contained in:
@@ -29,6 +29,8 @@ android {
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.7"
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.core:core-ktx:1.2.0'
|
||||
implementation 'org.nanohttpd:nanohttpd:2.2.0'
|
||||
|
||||
@@ -3,6 +3,9 @@ package com.bartlomiejpluta.ttsserver.core.lua.sandbox
|
||||
import android.content.Context
|
||||
import com.bartlomiejpluta.ttsserver.core.lua.lib.*
|
||||
import com.bartlomiejpluta.ttsserver.core.lua.loader.ConfigLoader
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.luaj.vm2.Globals
|
||||
import org.luaj.vm2.LoadState
|
||||
import org.luaj.vm2.compiler.LuaC
|
||||
@@ -23,7 +26,13 @@ class SandboxFactory(
|
||||
private val ttsLibrary: TTSLibrary,
|
||||
private val sonosLibrary: SonosLibrary
|
||||
) {
|
||||
fun createSandbox() = Globals().also { sandbox ->
|
||||
fun createSandbox() = runBlocking {
|
||||
withContext(Dispatchers.Default) {
|
||||
createLuaGlobals()
|
||||
}
|
||||
}
|
||||
|
||||
private fun createLuaGlobals() = Globals().also { sandbox ->
|
||||
loadStandardLibraries(sandbox)
|
||||
loadApplicationLibraries(sandbox)
|
||||
install(sandbox)
|
||||
|
||||
@@ -14,6 +14,18 @@ function silenceMode()
|
||||
else return from <= now or now <= to end
|
||||
end
|
||||
|
||||
function discoverSonosDevices()
|
||||
local output = {}
|
||||
local devices = sonos.discover()
|
||||
|
||||
for _, device in ipairs(devices) do
|
||||
output[device:getZoneGroupState():getName()] = device
|
||||
end
|
||||
|
||||
return output
|
||||
end
|
||||
|
||||
return {
|
||||
silenceMode = silenceMode
|
||||
}
|
||||
silenceMode = silenceMode,
|
||||
sonosDevices = discoverSonosDevices()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user