From bc7bd36ba20ee4e134ad0133c849d335e86eacaf Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Wed, 12 Aug 2020 13:51:31 +0200 Subject: [PATCH] Restructure user notifications. --- static/sfu.js | 17 ++++++++++++----- webclient.go | 7 +++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/static/sfu.js b/static/sfu.js index e3c9928..7c01dd9 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -678,7 +678,7 @@ function serverConnect() { gotPermissions(m.permissions); break; case 'user': - gotUser(m.id, m.username, m.del); + gotUser(m.id, m.kind, m.username); break; case 'chat': addToChatbox(m.id, m.username, m.kind, m.value); @@ -900,11 +900,18 @@ function resetUsers() { delUser(id, users[id]); } -function gotUser(id, name, del) { - if(del) - delUser(id, name); - else +function gotUser(id, kind, name) { + switch(kind) { + case 'add': addUser(id, name); + break; + case 'delete': + delUser(id, name); + break; + default: + console.warn('Unknown user kind', kind); + break; + } } function displayUsername() { diff --git a/webclient.go b/webclient.go index 77dfc59..1e67dde 100644 --- a/webclient.go +++ b/webclient.go @@ -112,11 +112,15 @@ func (c *webClient) Credentials() clientCredentials { } func (c *webClient) pushClient(id, username string, add bool) error { + kind := "add" + if !add { + kind = "delete" + } return c.write(clientMessage{ Type: "user", + Kind: kind, Id: id, Username: username, - Del: !add, }) } @@ -181,7 +185,6 @@ type clientMessage struct { Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"` Renegotiate bool `json:"renegotiate,omitempty"` Labels map[string]string `json:"labels,omitempty"` - Del bool `json:"del,omitempty"` Request rateMap `json:"request,omitempty"` }