diff --git a/README.PROTOCOL b/README.PROTOCOL index bad519b..069be5f 100644 --- a/README.PROTOCOL +++ b/README.PROTOCOL @@ -233,6 +233,7 @@ A chat message may be sent using a `chat` message. username: username, dest: dest-id, privileged: boolean, + noecho: false, value: message } ``` @@ -242,7 +243,9 @@ the clients in the group. If `source` is empty, then the message was originated by the server. The message is forwarded by the server without interpretation, the server only validates that the `source` and `username` fields are authentic. The field `privileged` is set to true by the server -if the message was originated by a client with the `op` permission. +if the message was originated by a client with the `op` permission. The +field `noecho` is set by the client if it doesn't wish to receive a copy +of its own message. A user message is similar to a chat message, but is not conserved in the chat history, and is not expected to contain user-visible content. diff --git a/rtpconn/webclient.go b/rtpconn/webclient.go index 3cb5cef..07218a8 100644 --- a/rtpconn/webclient.go +++ b/rtpconn/webclient.go @@ -173,6 +173,7 @@ type clientMessage struct { Permissions *group.ClientPermissions `json:"permissions,omitempty"` Group string `json:"group,omitempty"` Value interface{} `json:"value,omitempty"` + NoEcho bool `json:"noecho,omitempty"` Time int64 `json:"time,omitempty"` SDP string `json:"sdp,omitempty"` Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"` @@ -1209,10 +1210,15 @@ func handleClientMessage(c *webClient, m clientMessage) error { Privileged: c.permissions.Op, Time: tm, Kind: m.Kind, + NoEcho: m.NoEcho, Value: m.Value, } if m.Dest == "" { - err := broadcast(g.GetClients(nil), mm) + var except group.Client + if m.NoEcho { + except = c + } + err := broadcast(g.GetClients(except), mm) if err != nil { log.Printf("broadcast(chat): %v", err) } diff --git a/static/protocol.js b/static/protocol.js index 611d0da..28c776f 100644 --- a/static/protocol.js +++ b/static/protocol.js @@ -176,6 +176,7 @@ function ServerConnection() { * @property {Object} [permissions] * @property {string} [group] * @property {unknown} [value] + * @property {boolean} [noecho] * @property {string} [sdp] * @property {RTCIceCandidate} [candidate] * @property {Object} [labels] @@ -477,8 +478,9 @@ ServerConnection.prototype.userAction = function(kind, dest, value) { * @param {string} kind - The kind of application-specific message. * @param {string} dest - The id to send the message to, empty for broadcast. * @param {string} [value] - An optional parameter. + * @param {boolean} [noecho] - If set, don't echo back the message to the sender. */ -ServerConnection.prototype.userMessage = function(kind, dest, value) { +ServerConnection.prototype.userMessage = function(kind, dest, value, noecho) { this.send({ type: 'usermessage', source: this.id, @@ -486,6 +488,7 @@ ServerConnection.prototype.userMessage = function(kind, dest, value) { username: this.username, kind: kind, value: value, + noecho: noecho, }); };