From 221ed44538e2c78f765b81fba06765b46c3111e7 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Mon, 24 Jan 2022 19:59:45 +0100 Subject: [PATCH] Fix joining in frontend documentation. --- README.FRONTEND | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/README.FRONTEND b/README.FRONTEND index 6503d7d..35986d3 100644 --- a/README.FRONTEND +++ b/README.FRONTEND @@ -54,23 +54,44 @@ callback indicates that a chat message has been posted to the group, and `ondownstream` is called when the server pushes a stream to the client; see the section below about streams. -You may now connect to the server. +You may now connect to the server: ```javascript serverConnection.connect(`wss://${location.host}/ws`); ``` -You typically join a group and request media in the `onconnected` callback: +You typically join a group in the `onconnected` callback: ```javascript serverConnection.onconnected = function() { this.join(group, 'join', username, password); - this.request({'':['audio','video']}); } ``` -You should not attempt to push a stream to the server until it has granted -you the `present` permission through the `onjoined` callback. +After the server has replied to the join request, the `onjoined` callback +will trigger. There, you update your user interface and request incoming +streams: + +```javascript +serverConnection.onjoined = function(kind, group, perms, status, message) { + switch(kind) { + case 'join': + this.request({'':['audio','video']}); + // then update the UI, possibly taking perms.present into account + break; + case 'change': + // update the UI + break; + case 'redirect': + this.close(); + document.location.href = message; + break; + case 'fail': + // display the friendly error message + break; +} +``` + ## Sending and receiving chat messages @@ -85,6 +106,7 @@ You receive chat messages in the `onchat` callback. The server may request that you clear your chat window, in that case the `onclearchat` callback will trigger. + ## Other messages The `usermessage` method of the `ServerConnection` is similar to the