Browse Source

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.
jp9000 7 years ago
parent
commit
be8ddc06a2
1 changed files with 33 additions and 0 deletions
  1. 33 0
      plugins/rtmp-services/rtmp-common.c

+ 33 - 0
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);
 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)
 static void rtmp_common_update(void *data, obs_data_t *settings)
 {
 {
 	struct rtmp_common *service = data;
 	struct rtmp_common *service = data;
@@ -50,6 +81,8 @@ static void rtmp_common_update(void *data, obs_data_t *settings)
 				if (out)
 				if (out)
 					service->output = bstrdup(out);
 					service->output = bstrdup(out);
 			}
 			}
+
+			ensure_valid_url(service, serv, settings);
 		}
 		}
 	}
 	}
 	json_decref(root);
 	json_decref(root);