From 710cc3cc14adb33aad321dd4e696be842ed0381e Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Tue, 25 Jan 2022 18:16:42 +0100 Subject: [PATCH] Add ability to set initial user status. Setting the status after joining (using the "setstatus" action) may cause multiple "user" messages to be sent to clients. Add the ability to set the initial status at join time. --- README.PROTOCOL | 3 ++- rtpconn/webclient.go | 13 ++++++++++++- static/protocol.js | 10 +++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.PROTOCOL b/README.PROTOCOL index 3642d3e..327f0e4 100644 --- a/README.PROTOCOL +++ b/README.PROTOCOL @@ -107,7 +107,8 @@ The `join` message requests that the sender join or leave a group: kind: 'join' or 'leave', group: group, username: username, - password: password + password: password, + status: status } ``` diff --git a/rtpconn/webclient.go b/rtpconn/webclient.go index a0a5792..461b472 100644 --- a/rtpconn/webclient.go +++ b/rtpconn/webclient.go @@ -1316,9 +1316,20 @@ func handleClientMessage(c *webClient, m clientMessage) error { } if c.group != nil { - return group.ProtocolError("cannot join multiple groups") + return group.ProtocolError( + "cannot join multiple groups", + ) } c.username = m.Username + if m.Status != nil { + s, ok := m.Status.(map[string]interface{}) + if !ok { + return group.ProtocolError( + "bad type for status", + ) + } + c.status = s + } g, err := group.AddClient(m.Group, c, group.ClientCredentials{ Username: m.Username, diff --git a/static/protocol.js b/static/protocol.js index 7550801..766be50 100644 --- a/static/protocol.js +++ b/static/protocol.js @@ -416,15 +416,19 @@ ServerConnection.prototype.connect = async function(url) { * @param {string} group - The name of the group to join. * @param {string} username - the username to join as. * @param {string} password - the password. + * @param {Object} [status] - the initial status of the user. */ -ServerConnection.prototype.join = function(group, username, password) { - this.send({ +ServerConnection.prototype.join = function(group, username, password, status) { + let m = { type: 'join', kind: 'join', group: group, username: username, password: password, - }); + }; + if(status) + m.status = status; + this.send(m); }; /**