From be8ddc06a2f8d31ff67813e2a39025ab4d8a2675 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Sun, 5 Aug 2018 18:36:39 -0700 Subject: [PATCH] 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. --- plugins/rtmp-services/rtmp-common.c | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/plugins/rtmp-services/rtmp-common.c b/plugins/rtmp-services/rtmp-common.c index 9079e07ae..aa328f7fa 100644 --- a/plugins/rtmp-services/rtmp-common.c +++ b/plugins/rtmp-services/rtmp-common.c @@ -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);