From cae06e43dc719967ba65a2795a067419ebae621c Mon Sep 17 00:00:00 2001 From: WANGXIAOMIN-HIK Date: Wed, 22 Jul 2026 09:52:37 +0800 Subject: [PATCH 1/6] Add close signaling method to WebRTC signaling protocol Co-Authored-By: Claude --- doc/WebRTC.xml | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/doc/WebRTC.xml b/doc/WebRTC.xml index c50fccf1f..3ad3ee693 100644 --- a/doc/WebRTC.xml +++ b/doc/WebRTC.xml @@ -729,7 +729,45 @@ - + +
+ close + An ONVIF compliant signaling server, device and client shall support this + command to actively terminate a streaming session. + A signaling server shall relay this command unaltered to the peer. Upon + receiving the close command the device shall stop media streaming and release + resources such as ICE candidates and TURN connections. + + + request + + session [string] + The ID assigned by the signaling server to the session. + reason optional [string] + A short description of why the session is closed. + + + + response + + <none> + + + + faults + + 400 Bad Request + Invalid session ID. + 404 Not Found + The session does not exist. + + + + The close command is idempotent: if the session has already been closed, the + signaling server shall return a successful response rather than 404, so a client + can retry safely after a network interruption. The 404 fault applies only when the + session ID was never valid. +
error An ONVIF compliant signaling server, device and client shall support sending or receiving notifications signaling that an error has occurred. From d69b4d99bccdb44ec462b918215d7bf12969a46a Mon Sep 17 00:00:00 2001 From: WANGXIAOMIN-HIK Date: Wed, 22 Jul 2026 09:57:01 +0800 Subject: [PATCH 2/6] Add close exchange to WebRTC example flow Co-Authored-By: Claude --- doc/WebRTC.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/WebRTC.xml b/doc/WebRTC.xml index 3ad3ee693..aa7288140 100644 --- a/doc/WebRTC.xml +++ b/doc/WebRTC.xml @@ -897,6 +897,11 @@ Client -> Server: { "method": "extend", "params": {"session": "s1", "authorizati "id": 4} Server -> Client: { "error": {"code": -32601, "message": "Method not found"}, "id": "4"} ... +Client -> Server: { "method": "close", "params": {"session": "s1"}, "id": 5} +Server -> Device: { "method": "close", "params": {"session": "s1"}, "id": 5} +Device -> Server: { "result": {}, "id": 5} +Server -> Client: { "result": {}, "id": 5} +... Device -> Server: { "error": {"code": 1001, "message": "Insufficient resources"}} Server -> Client: { "error": {"code": 1001, "message": "Insufficient resources"}} From f8ff11b0a6d61c57dce1f66cb30ecb56cda6e627 Mon Sep 17 00:00:00 2001 From: WANGXIAOMIN-HIK Date: Wed, 22 Jul 2026 10:01:12 +0800 Subject: [PATCH 3/6] Add close cross-reference to trickle section's session-termination note The trickle section's closing note discusses terminating the WebSocket session and states the only reason to keep the connection is to extend. With the new close command, there is a second reason: to actively release device resources (ICE candidates, TURN connections) before teardown. Point readers to section_close. Co-Authored-By: Claude --- doc/WebRTC.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/WebRTC.xml b/doc/WebRTC.xml index aa7288140..da1432e2a 100644 --- a/doc/WebRTC.xml +++ b/doc/WebRTC.xml @@ -661,6 +661,9 @@ client and device. After the session has been established the client can terminate the WebSocket session to the signaling server and the peer-to-peer connection will not be affected. The only reason to keep the connection to the server is if the client needs to extend the session. + To actively release device resources such as ICE candidates and TURN connections, the + client may send the close command (see ) + before terminating the WebSocket session.
extend From e05298dd64c50ee3671b7f7827b6a20953a36114 Mon Sep 17 00:00:00 2001 From: WANGXIAOMIN-HIK Date: Thu, 13 Aug 2026 19:24:57 +0800 Subject: [PATCH 4/6] Add close command description for resource release and session signaling --- doc/WebRTC.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/WebRTC.xml b/doc/WebRTC.xml index da1432e2a..5b38d4dc4 100644 --- a/doc/WebRTC.xml +++ b/doc/WebRTC.xml @@ -770,6 +770,18 @@ signaling server shall return a successful response rather than 404, so a client can retry safely after a network interruption. The 404 fault applies only when the session ID was never valid. + The close command is an optimization for prompt, graceful resource release and + explicit session-lifecycle signaling; it is not the sole mechanism by which resources + are reclaimed. A client may disappear at any time without sending close (for example, a + browser tab being closed by a user, or a network failure), in which case the close + command will never arrive. Devices and signaling servers shall therefore implement + automatic cleanup as a fallback: a signaling server shall detect a dropped WebSocket + connection (see the "Peer disconnected" error, ), and may enforce session expiration using the expiryTimeSeconds property of the + connect command together with the extend command. Upon such detection, the device shall + stop media streaming and release resources such as ICE candidates and TURN connections + exactly as if a close command had been received. Implementations shall not assume that a + close command will always be delivered.
error From 0cc96eb07446c06d36f14e84703d606f03ab5fee Mon Sep 17 00:00:00 2001 From: WANGXIAOMIN-HIK Date: Thu, 13 Aug 2026 19:35:25 +0800 Subject: [PATCH 5/6] Improve signaling handling for closed sessions and add behavior descriptions for trickle and extend commands --- doc/WebRTC.xml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/WebRTC.xml b/doc/WebRTC.xml index 5b38d4dc4..b798e0cc8 100644 --- a/doc/WebRTC.xml +++ b/doc/WebRTC.xml @@ -646,7 +646,8 @@ faults - <none> + No faults are defined for a malformed-but-transportable request; see + the handling of already-closed sessions below. @@ -657,6 +658,12 @@ NOTE: Note that ICE candidates can arrive before the SDP offer and the implementing client needs to handle this. + If a trickle command is received for a session that has already been closed, the + signaling server shall respond successfully to the requester and shall not relay the + candidate to the peer. This is an exception to the relay requirement above and accounts + for in-flight candidates that are still in transit when a session is being torn down; it + is consistent with the idempotent design of the close command, under which an + already-closed session is not treated as an error. If everything works as it should, a peer-to-peer WebRTC session can be set up between client and device. After the session has been established the client can terminate the WebSocket session to the signaling server and the peer-to-peer connection will not be @@ -697,9 +704,16 @@ The authorization token cannot be verified. The authorization token may not include the required claims, or has expired. 403 Forbidden The client is not authorized to connect to the provided peer. + 404 Not Found + The session does not exist or has already been closed. + Unlike the close command, which is idempotent by design, an extend command + received for a session that has already been closed shall be rejected with 404, so the + client is not left believing a dead session is still alive. An extend for an + already-closed session is a state-change request with no valid target, not a retryable + notification.
extend - Signaling Server to Device @@ -782,6 +796,9 @@ stop media streaming and release resources such as ICE candidates and TURN connections exactly as if a close command had been received. Implementations shall not assume that a close command will always be delivered. + Behavior for trickle and extend commands received after a session has closed is + defined in their respective sections; implementations shall not assume the peer has seen + the close before such messages arrive.
error From c87ca8c888b2dfa697f9ed86ce98c696131ac74f Mon Sep 17 00:00:00 2001 From: WANGXIAOMIN-HIK Date: Thu, 20 Aug 2026 15:40:47 +0800 Subject: [PATCH 6/6] Update WebRTC signaling flow diagram: Adjust dimensions, add close command paths, and refine text elements --- doc/media/WebRTC/webrtc_signaling_flow.svg | 124 +++++++++++++++++---- 1 file changed, 105 insertions(+), 19 deletions(-) diff --git a/doc/media/WebRTC/webrtc_signaling_flow.svg b/doc/media/WebRTC/webrtc_signaling_flow.svg index 840ff8002..929a68140 100644 --- a/doc/media/WebRTC/webrtc_signaling_flow.svg +++ b/doc/media/WebRTC/webrtc_signaling_flow.svg @@ -2,10 +2,10 @@ trickle(SessionID, ICE-Candidate)trickle(SessionID, ICE-Candidate) + + + close(SessionID, Reason) + closed() + id="tspan-txt-close-req-sd" + style="fill:#000000;stroke:none;stroke-width:27.2272">close(SessionID, Reason) + + + () + () @@ -1294,7 +1380,7 @@ transform="matrix(0.964,0,0,0.9655,-636.069,-520.01)" id="path56-5" inkscape:connector-curvature="0" />