ADD - integrate Yaca voice support (#5)

This commit is contained in:
Leon.Schmidt
2026-08-19 17:04:23 +02:00
committed by GitHub
parent 2aee913efc
commit 7985ca08d9
17 changed files with 355 additions and 25 deletions
+124 -5
View File
@@ -1,8 +1,10 @@
local call_provider_resources = {
yaca = "yaca-voice",
pma = "pma-voice",
saltychat = "saltychat",
}
local call_provider_aliases = {
["yaca-voice"] = "yaca",
["pma-voice"] = "pma",
salty = "saltychat",
}
@@ -17,6 +19,26 @@ local radio_provider_aliases = {
salty = "saltychat",
}
local function yaca_is_enabled()
if GetResourceState("yaca-voice") ~= "started" then
return false
end
local success, enabled = pcall(function()
return exports["yaca-voice"]:isEnabled()
end)
if not success then
Bridge.Debug(
"error",
"[sky_phone] Yaca could not report its availability: %s",
tostring(enabled),
{ always = true }
)
return false
end
return enabled == true
end
local function resolve_call_provider()
local configured = tostring(Config.Calls.VoiceProvider or "")
local selected = call_provider_aliases[configured] or configured
@@ -51,11 +73,17 @@ function Bridge.Calls.GetProvider()
end
function Bridge.Calls.IsAvailable()
return resolve_call_provider() ~= nil
local selected = resolve_call_provider()
return selected ~= nil and (selected ~= "yaca" or yaca_is_enabled())
end
function Bridge.Calls.SupportsSpeaker()
return Bridge.Speaker.IsEnabled() and resolve_call_provider() == "saltychat"
local selected = resolve_call_provider()
return Bridge.Speaker.IsEnabled() and (selected == "yaca" or selected == "saltychat")
end
function Bridge.Calls.SupportsMute()
return resolve_call_provider() == "yaca"
end
function Bridge.Calls.Start(identifier, player_handles)
@@ -63,6 +91,37 @@ function Bridge.Calls.Start(identifier, player_handles)
if selected == "pma" then
return true, selected
end
if selected == "yaca" then
if not yaca_is_enabled() then
return false, selected
end
local caller_source = tonumber(player_handles[1])
local target_source = tonumber(player_handles[2])
if not caller_source or not target_source then
Bridge.Debug(
"error",
"[sky_phone] Yaca refused call %s because a player source was invalid.",
tostring(identifier),
{ always = true }
)
return false, selected
end
local success, error_message = pcall(function()
exports["yaca-voice"]:callPlayer(caller_source, target_source, true)
end)
if not success then
Bridge.Debug(
"error",
"[sky_phone] Yaca could not start call %s: %s",
tostring(identifier),
tostring(error_message),
{ always = true }
)
return false, selected
end
return true, selected
end
if selected ~= "saltychat" then
return false, nil
end
@@ -85,6 +144,36 @@ end
function Bridge.Calls.Stop(identifier, player_handles, provider)
local selected = provider or resolve_call_provider()
if selected == "yaca" then
if GetResourceState("yaca-voice") ~= "started" then
return
end
local caller_source = tonumber(player_handles[1])
local target_source = tonumber(player_handles[2])
if not caller_source or not target_source then
Bridge.Debug(
"error",
"[sky_phone] Yaca could not stop call %s because a player source was invalid.",
tostring(identifier),
{ always = true }
)
return
end
local success, error_message = pcall(function()
exports["yaca-voice"]:callPlayer(caller_source, target_source, false)
end)
if not success then
Bridge.Debug(
"error",
"[sky_phone] Yaca could not stop call %s: %s",
tostring(identifier),
tostring(error_message),
{ always = true }
)
end
return
end
if selected ~= "saltychat" or GetResourceState("saltychat") ~= "started" then
return
end
@@ -108,17 +197,47 @@ function Bridge.Calls.SetSpeaker(player_source, enabled, provider)
return false
end
local selected = provider or resolve_call_provider()
if selected ~= "saltychat" or GetResourceState("saltychat") ~= "started" then
local resource_name = call_provider_resources[selected]
if (selected ~= "yaca" and selected ~= "saltychat")
or GetResourceState(resource_name) ~= "started"
then
return false
end
local success, error_message = pcall(function()
exports.saltychat:SetPhoneSpeaker(tonumber(player_source), enabled == true)
if selected == "yaca" then
exports["yaca-voice"]:enablePhoneSpeaker(tonumber(player_source), enabled == true)
else
exports.saltychat:SetPhoneSpeaker(tonumber(player_source), enabled == true)
end
end)
if not success then
Bridge.Debug(
"error",
"[sky_phone] SaltyChat could not update the phone speaker for source %s: %s",
"[sky_phone] %s could not update the phone speaker for source %s: %s",
selected == "yaca" and "Yaca" or "SaltyChat",
tostring(player_source),
tostring(error_message),
{ always = true }
)
return false
end
return true
end
function Bridge.Calls.SetMuted(player_source, enabled, provider)
local selected = provider or resolve_call_provider()
if selected ~= "yaca" or GetResourceState("yaca-voice") ~= "started" then
return false
end
local success, error_message = pcall(function()
exports["yaca-voice"]:muteOnPhone(tonumber(player_source), enabled == true)
end)
if not success then
Bridge.Debug(
"error",
"[sky_phone] Yaca could not update the phone mute state for source %s: %s",
tostring(player_source),
tostring(error_message),
{ always = true }