From a2ab8c3686eaefb4813e989300e0fddaba328891 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sun, 23 Aug 2020 19:07:52 +0200 Subject: [PATCH] Remove up media when closing the socket. --- README.FRONTEND | 8 +++++--- static/sfu.js | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.FRONTEND b/README.FRONTEND index bb4e6ce..f7cf64c 100644 --- a/README.FRONTEND +++ b/README.FRONTEND @@ -36,9 +36,11 @@ serverConnection.onclearchat = ...; serverConnection.ondownstream = ...; ``` -The `onconnected` callback is called when we connect to the server; -`onclose` is the opposite of `onconnected`. `onusermessage` indicates -a message from the server that should be displayed to the user. +The `onconnected` callback is called when we connect to the server. The +`onclose` callback is called when the socket is closed; you should use it +to close all your outgoing streams (incoming streams will be closed by the +server). `onusermessage` indicates a message from the server that should +be displayed to the user. The other callbacks will only be called after you join a group. `onuser` is used to indicate that a user has joined or left the current group. diff --git a/static/sfu.js b/static/sfu.js index bec86f4..994d063 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -69,6 +69,7 @@ function gotConnected() { } function gotClose(code, reason) { + delUpMediaKind(null); setConnected(false); if(code != 1000) console.warn('Socket close', code, reason); @@ -395,10 +396,15 @@ function delUpMedia(c) { setButtonsVisibility() } +/** + * delUpMediaKind reoves all up media of the given kind. If kind is + * falseish, it removes all up media. + * @param {string} kind +*/ function delUpMediaKind(kind) { for(let id in serverConnection.up) { let c = serverConnection.up[id]; - if(c.kind != kind) + if(kind && c.kind != kind) continue c.close(true); delMedia(id);