Commit 63e2b5a4 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implement 'noecho' field in client messages.

parent 9f67a03f
...@@ -233,6 +233,7 @@ A chat message may be sent using a `chat` message. ...@@ -233,6 +233,7 @@ A chat message may be sent using a `chat` message.
username: username, username: username,
dest: dest-id, dest: dest-id,
privileged: boolean, privileged: boolean,
noecho: false,
value: message value: message
} }
``` ```
...@@ -242,7 +243,9 @@ the clients in the group. If `source` is empty, then the message was ...@@ -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 originated by the server. The message is forwarded by the server without
interpretation, the server only validates that the `source` and `username` interpretation, the server only validates that the `source` and `username`
fields are authentic. The field `privileged` is set to true by the server 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 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. chat history, and is not expected to contain user-visible content.
......
...@@ -173,6 +173,7 @@ type clientMessage struct { ...@@ -173,6 +173,7 @@ type clientMessage struct {
Permissions *group.ClientPermissions `json:"permissions,omitempty"` Permissions *group.ClientPermissions `json:"permissions,omitempty"`
Group string `json:"group,omitempty"` Group string `json:"group,omitempty"`
Value interface{} `json:"value,omitempty"` Value interface{} `json:"value,omitempty"`
NoEcho bool `json:"noecho,omitempty"`
Time int64 `json:"time,omitempty"` Time int64 `json:"time,omitempty"`
SDP string `json:"sdp,omitempty"` SDP string `json:"sdp,omitempty"`
Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"` Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"`
...@@ -1209,10 +1210,15 @@ func handleClientMessage(c *webClient, m clientMessage) error { ...@@ -1209,10 +1210,15 @@ func handleClientMessage(c *webClient, m clientMessage) error {
Privileged: c.permissions.Op, Privileged: c.permissions.Op,
Time: tm, Time: tm,
Kind: m.Kind, Kind: m.Kind,
NoEcho: m.NoEcho,
Value: m.Value, Value: m.Value,
} }
if m.Dest == "" { 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 { if err != nil {
log.Printf("broadcast(chat): %v", err) log.Printf("broadcast(chat): %v", err)
} }
......
...@@ -176,6 +176,7 @@ function ServerConnection() { ...@@ -176,6 +176,7 @@ function ServerConnection() {
* @property {Object<string,boolean>} [permissions] * @property {Object<string,boolean>} [permissions]
* @property {string} [group] * @property {string} [group]
* @property {unknown} [value] * @property {unknown} [value]
* @property {boolean} [noecho]
* @property {string} [sdp] * @property {string} [sdp]
* @property {RTCIceCandidate} [candidate] * @property {RTCIceCandidate} [candidate]
* @property {Object<string,string>} [labels] * @property {Object<string,string>} [labels]
...@@ -477,8 +478,9 @@ ServerConnection.prototype.userAction = function(kind, dest, value) { ...@@ -477,8 +478,9 @@ ServerConnection.prototype.userAction = function(kind, dest, value) {
* @param {string} kind - The kind of application-specific message. * @param {string} kind - The kind of application-specific message.
* @param {string} dest - The id to send the message to, empty for broadcast. * @param {string} dest - The id to send the message to, empty for broadcast.
* @param {string} [value] - An optional parameter. * @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({ this.send({
type: 'usermessage', type: 'usermessage',
source: this.id, source: this.id,
...@@ -486,6 +488,7 @@ ServerConnection.prototype.userMessage = function(kind, dest, value) { ...@@ -486,6 +488,7 @@ ServerConnection.prototype.userMessage = function(kind, dest, value) {
username: this.username, username: this.username,
kind: kind, kind: kind,
value: value, value: value,
noecho: noecho,
}); });
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment