Add preference for /sonos endpoint
This commit is contained in:
@@ -5,5 +5,6 @@ object PreferenceKey {
|
|||||||
const val PORT = "preference_port"
|
const val PORT = "preference_port"
|
||||||
const val ENABLE_SAY_ENDPOINT = "preference_enable_say_endpoint"
|
const val ENABLE_SAY_ENDPOINT = "preference_enable_say_endpoint"
|
||||||
const val ENABLE_WAVE_ENDPOINT = "preference_enable_wave_endpoint"
|
const val ENABLE_WAVE_ENDPOINT = "preference_enable_wave_endpoint"
|
||||||
|
const val ENABLE_SONOS_ENDPOINT = "preference_enable_sonos_endpoint"
|
||||||
const val TTS = "preference_tts"
|
const val TTS = "preference_tts"
|
||||||
}
|
}
|
||||||
@@ -92,6 +92,10 @@ class WebServer(port: Int, private val context: Context) : NanoHTTPD(port),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun sonos(session: IHTTPSession): Response {
|
private fun sonos(session: IHTTPSession): Response {
|
||||||
|
if (!preferences.getBoolean(PreferenceKey.ENABLE_SONOS_ENDPOINT, true)) {
|
||||||
|
throw ResponseException(NOT_FOUND, "")
|
||||||
|
}
|
||||||
|
|
||||||
if (session.method != Method.POST) {
|
if (session.method != Method.POST) {
|
||||||
throw ResponseException(METHOD_NOT_ALLOWED, "")
|
throw ResponseException(METHOD_NOT_ALLOWED, "")
|
||||||
}
|
}
|
||||||
@@ -108,6 +112,10 @@ class WebServer(port: Int, private val context: Context) : NanoHTTPD(port),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun sonosCache(session: IHTTPSession): Response {
|
private fun sonosCache(session: IHTTPSession): Response {
|
||||||
|
if (!preferences.getBoolean(PreferenceKey.ENABLE_SONOS_ENDPOINT, true)) {
|
||||||
|
throw ResponseException(NOT_FOUND, "")
|
||||||
|
}
|
||||||
|
|
||||||
if (session.method != Method.GET) {
|
if (session.method != Method.GET) {
|
||||||
throw ResponseException(METHOD_NOT_ALLOWED, "")
|
throw ResponseException(METHOD_NOT_ALLOWED, "")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
<string name="preference_enable_say_endpoint_title">Enable /say endpoint</string>
|
<string name="preference_enable_say_endpoint_title">Enable /say endpoint</string>
|
||||||
<string name="preference_enable_wave_endpoint_summary">Allow HTTP clients to use /wave endpoint which enables them to retrieve TTS message as wave file</string>
|
<string name="preference_enable_wave_endpoint_summary">Allow HTTP clients to use /wave endpoint which enables them to retrieve TTS message as wave file</string>
|
||||||
<string name="preference_enable_wave_endpoint_title">Enable /wave endpoint</string>
|
<string name="preference_enable_wave_endpoint_title">Enable /wave endpoint</string>
|
||||||
|
<string name="preference_enable_sonos_endpoint_summary">Allow HTTP clients to use /sonos endpoint which enables them to send TTS messages directly to Sonos devices</string>
|
||||||
|
<string name="preference_enable_sonos_endpoint_title">Enable /sonos endpoint</string>
|
||||||
<string name="preference_tts_summary">Go to platform\'s TTS engine settings and adjust its parameters</string>
|
<string name="preference_tts_summary">Go to platform\'s TTS engine settings and adjust its parameters</string>
|
||||||
<string name="preference_tts_title">TTS engine settings</string>
|
<string name="preference_tts_title">TTS engine settings</string>
|
||||||
<string name="preference_category_tts">TTS engine</string>
|
<string name="preference_category_tts">TTS engine</string>
|
||||||
|
|||||||
@@ -24,6 +24,13 @@
|
|||||||
android:title="@string/preference_enable_wave_endpoint_title"
|
android:title="@string/preference_enable_wave_endpoint_title"
|
||||||
app:iconSpaceReserved="false" />
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:key="preference_enable_sonos_endpoint"
|
||||||
|
android:summary="@string/preference_enable_sonos_endpoint_summary"
|
||||||
|
android:title="@string/preference_enable_sonos_endpoint_title"
|
||||||
|
app:iconSpaceReserved="false" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/preference_category_tts" app:iconSpaceReserved="false">
|
<PreferenceCategory android:title="@string/preference_category_tts" app:iconSpaceReserved="false">
|
||||||
|
|||||||
Reference in New Issue
Block a user