[Pkg-voip-commits] [janus] 77/163: Added configurable ping/pong to WebSockets transport (see #986)

Jonas Smedegaard dr at jones.dk
Sat Oct 28 01:22:12 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/0.2.5-1
in repository janus.

commit b9ece6a0374f46f7896d1ab819408dbe17a02269
Author: Lorenzo Miniero <lminiero at gmail.com>
Date:   Fri Sep 1 16:29:40 2017 +0200

    Added configurable ping/pong to WebSockets transport (see #986)
---
 conf/janus.transport.websockets.cfg.sample.in |  3 +++
 transports/janus_websockets.c                 | 39 +++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/conf/janus.transport.websockets.cfg.sample.in b/conf/janus.transport.websockets.cfg.sample.in
index 2625c4d..7e57448 100644
--- a/conf/janus.transport.websockets.cfg.sample.in
+++ b/conf/janus.transport.websockets.cfg.sample.in
@@ -3,6 +3,9 @@
 [general]
 json = indented				; Whether the JSON messages should be indented (default),
 							; plain (no indentation) or compact (no indentation and no spaces)
+;pingpong_trigger = 5		; After how many seconds of idle, a PING should be sent
+;pingpong_timeout = 5		; After how many seconds of not getting a PONG, a timeout should be detected
+
 ws = yes					; Whether to enable the WebSockets API
 ws_port = 8188				; WebSockets server port
 ;ws_interface = eth0		; Whether we should bind this server to a specific interface only
diff --git a/transports/janus_websockets.c b/transports/janus_websockets.c
index 7523c32..6487dcf 100644
--- a/transports/janus_websockets.c
+++ b/transports/janus_websockets.c
@@ -292,6 +292,7 @@ static const char *janus_websockets_reason_string(enum libwebsocket_callback_rea
 		CASE_STR(LWS_CALLBACK_UNLOCK_POLL);
 		CASE_STR(LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY);
 		CASE_STR(LWS_CALLBACK_USER);
+		CASE_STR(LWS_CALLBACK_RECEIVE_PONG);
 		default:
 			break;
 	}
@@ -467,6 +468,28 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
 			list = NULL;
 		}
 
+		/* Check if we need to enable the transport level ping/pong mechanism */
+		int pingpong_trigger = 0, pingpong_timeout = 0;
+		item = janus_config_get_item_drilldown(config, "general", "pingpong_trigger");
+		if(item && item->value) {
+			pingpong_trigger = atoi(item->value);
+			if(pingpong_trigger < 0) {
+				JANUS_LOG(LOG_WARN, "Invalid value for pingpong_trigger (%d), ignoring...\n", pingpong_trigger);
+				pingpong_trigger = 0;
+			}
+		}
+		item = janus_config_get_item_drilldown(config, "general", "pingpong_timeout");
+		if(item && item->value) {
+			pingpong_timeout = atoi(item->value);
+			if(pingpong_timeout < 0) {
+				JANUS_LOG(LOG_WARN, "Invalid value for pingpong_timeout (%d), ignoring...\n", pingpong_timeout);
+				pingpong_timeout = 0;
+			}
+		}
+		if((pingpong_trigger && !pingpong_timeout) || (!pingpong_trigger && pingpong_timeout)) {
+			JANUS_LOG(LOG_WARN, "pingpong_trigger and pingpong_timeout not both set, ignoring...\n");
+		}
+
 		/* Setup the Janus API WebSockets server(s) */
 		item = janus_config_get_item_drilldown(config, "general", "ws");
 		if(!item || !item->value || !janus_is_true(item->value)) {
@@ -506,6 +529,10 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
 			info.gid = -1;
 			info.uid = -1;
 			info.options = 0;
+			if(pingpong_trigger > 0 && pingpong_timeout > 0) {
+				info.ws_ping_pong_interval = pingpong_trigger;
+				info.timeout_secs = pingpong_timeout;
+			}
 			/* Create the WebSocket context */
 #ifdef HAVE_LIBWEBSOCKETS_NEWAPI
 			wss = lws_create_context(&info);
@@ -571,6 +598,10 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
 #else
 				info.options = 0;
 #endif
+				if(pingpong_trigger > 0 && pingpong_timeout > 0) {
+					info.ws_ping_pong_interval = pingpong_trigger;
+					info.timeout_secs = pingpong_timeout;
+				}
 				/* Create the secure WebSocket context */
 #ifdef HAVE_LIBWEBSOCKETS_NEWAPI
 				swss = lws_create_context(&info);
@@ -624,6 +655,10 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
 			info.gid = -1;
 			info.uid = -1;
 			info.options = 0;
+			if(pingpong_trigger > 0 && pingpong_timeout > 0) {
+				info.ws_ping_pong_interval = pingpong_trigger;
+				info.timeout_secs = pingpong_timeout;
+			}
 			/* Create the WebSocket context */
 #ifdef HAVE_LIBWEBSOCKETS_NEWAPI
 			admin_wss = lws_create_context(&info);
@@ -689,6 +724,10 @@ int janus_websockets_init(janus_transport_callbacks *callback, const char *confi
 #else
 				info.options = 0;
 #endif
+				if(pingpong_trigger > 0 && pingpong_timeout > 0) {
+					info.ws_ping_pong_interval = pingpong_trigger;
+					info.timeout_secs = pingpong_timeout;
+				}
 				/* Create the secure WebSocket context */
 #ifdef HAVE_LIBWEBSOCKETS_NEWAPI
 				admin_swss = lws_create_context(&info);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/janus.git



More information about the Pkg-voip-commits mailing list