rtmp-services: Ensure set URL exists within server list

If the user had a valid service selected, but the server that the user
originally was using is now (for whatever reason) no longer listed, the
rtmp-common service would still use that server rather than any of the
newer servers, and the user would have to physically go in to their
settings to reconfigure to get it to use that new server.

Instead, make sure that the server the user has selected exists within
the server list, and if it doesn't, use the first server in the list
instead by default.
This commit is contained in:
jp9000 2018-08-05 18:36:39 -07:00
parent a17c28223c
commit be8ddc06a2

View File

@ -26,6 +26,37 @@ static inline const char *get_string_val(json_t *service, const char *key);
extern void twitch_ingests_refresh(int seconds);
static void ensure_valid_url(struct rtmp_common *service, json_t *json,
obs_data_t *settings)
{
json_t *servers = json_object_get(json, "servers");
const char *top_url = NULL;
json_t *server;
size_t index;
if (!service->server || !servers || !json_is_array(servers))
return;
json_array_foreach (servers, index, server) {
const char *url = get_string_val(server, "url");
if (!url)
continue;
if (!top_url)
top_url = url;
if (astrcmpi(service->server, url) == 0)
return;
}
/* server was not found in server list, use first server instead */
if (top_url) {
bfree(service->server);
service->server = bstrdup(top_url);
obs_data_set_string(settings, "server", top_url);
}
}
static void rtmp_common_update(void *data, obs_data_t *settings)
{
struct rtmp_common *service = data;
@ -50,6 +81,8 @@ static void rtmp_common_update(void *data, obs_data_t *settings)
if (out)
service->output = bstrdup(out);
}
ensure_valid_url(service, serv, settings);
}
}
json_decref(root);