|
@@ -79,21 +79,19 @@ function filterNodeFromPresenceJSON(pres, nodeName) {
|
79
|
79
|
/**
|
80
|
80
|
* The name of the field used to recognize a chat message as carrying a JSON
|
81
|
81
|
* payload from another endpoint.
|
82
|
|
- * If the body of a chat message contains a valid JSON object, and the JSON has
|
83
|
|
- * this key, then the transported payload is contained in the 'payload'
|
84
|
|
- * property of the JSON object.
|
|
82
|
+ * If the json-message of a chat message contains a valid JSON object, and the
|
|
83
|
+ * JSON has this key, then it is a valid json-message to be sent.
|
85
|
84
|
*/
|
86
|
|
-export const JITSI_MEET_MUC_TOPIC = 'jitsi-meet-muc-msg-topic';
|
|
85
|
+export const JITSI_MEET_MUC_TYPE = 'type';
|
87
|
86
|
|
88
|
87
|
/**
|
89
|
88
|
* Check if the given argument is a valid JSON ENDPOINT_MESSAGE string by
|
90
|
|
- * parsing it and checking if it has a field called 'jitsi-meet-muc-msg-topic'
|
91
|
|
- * and a field called 'payload'
|
|
89
|
+ * parsing it and checking if it has a field called 'type'.
|
92
|
90
|
*
|
93
|
91
|
* @param {string} jsonString check if this string is a valid json string
|
94
|
|
- * and contains the special structure
|
|
92
|
+ * and contains the special structure.
|
95
|
93
|
* @returns {boolean, object} if given object is a valid JSON string, return
|
96
|
|
- * the json object. Otherwise, return false;
|
|
94
|
+ * the json object. Otherwise, returns false.
|
97
|
95
|
*/
|
98
|
96
|
function tryParseJSONAndVerify(jsonString) {
|
99
|
97
|
try {
|
|
@@ -107,15 +105,14 @@ function tryParseJSONAndVerify(jsonString) {
|
107
|
105
|
// so we must check for that, too.
|
108
|
106
|
// Thankfully, null is falsey, so this suffices:
|
109
|
107
|
if (json && typeof json === 'object') {
|
110
|
|
- const topic = json[JITSI_MEET_MUC_TOPIC];
|
111
|
|
- const payload = json.payload;
|
|
108
|
+ const type = json[JITSI_MEET_MUC_TYPE];
|
112
|
109
|
|
113
|
|
- if ((typeof topic !== 'undefined') && payload) {
|
114
|
|
- return payload;
|
|
110
|
+ if (typeof type !== 'undefined') {
|
|
111
|
+ return json;
|
115
|
112
|
}
|
116
|
113
|
|
117
|
114
|
logger.debug('parsing valid json but does not have correct '
|
118
|
|
- + 'structure', 'topic: ', topic, 'payload: ', payload);
|
|
115
|
+ + 'structure', 'topic: ', type);
|
119
|
116
|
}
|
120
|
117
|
} catch (e) {
|
121
|
118
|
|
|
@@ -708,14 +705,23 @@ export default class ChatRoom extends Listenable {
|
708
|
705
|
|
709
|
706
|
/**
|
710
|
707
|
* Send text message to the other participants in the conference
|
711
|
|
- * @param body
|
|
708
|
+ * @param message
|
|
709
|
+ * @param elementName
|
712
|
710
|
* @param nickname
|
713
|
711
|
*/
|
714
|
|
- sendMessage(body, nickname) {
|
|
712
|
+ sendMessage(message, elementName, nickname) {
|
715
|
713
|
const msg = $msg({ to: this.roomjid,
|
716
|
714
|
type: 'groupchat' });
|
717
|
715
|
|
718
|
|
- msg.c('body', body).up();
|
|
716
|
+ // We are adding the message in a packet extension. If this element
|
|
717
|
+ // is different from 'body', we add a custom namespace.
|
|
718
|
+ // e.g. for 'json-message' extension of message stanza.
|
|
719
|
+ if (elementName === 'body') {
|
|
720
|
+ msg.c(elementName, message).up();
|
|
721
|
+ } else {
|
|
722
|
+ msg.c(elementName, { xmlns: 'http://jitsi.org/jitmeet' }, message)
|
|
723
|
+ .up();
|
|
724
|
+ }
|
719
|
725
|
if (nickname) {
|
720
|
726
|
msg.c('nick', { xmlns: 'http://jabber.org/protocol/nick' })
|
721
|
727
|
.t(nickname)
|
|
@@ -723,20 +729,30 @@ export default class ChatRoom extends Listenable {
|
723
|
729
|
.up();
|
724
|
730
|
}
|
725
|
731
|
this.connection.send(msg);
|
726
|
|
- this.eventEmitter.emit(XMPPEvents.SENDING_CHAT_MESSAGE, body);
|
|
732
|
+ this.eventEmitter.emit(XMPPEvents.SENDING_CHAT_MESSAGE, message);
|
727
|
733
|
}
|
728
|
734
|
|
|
735
|
+ /* eslint-disable max-params */
|
729
|
736
|
/**
|
730
|
737
|
* Send private text message to another participant of the conference
|
731
|
738
|
* @param id id/muc resource of the receiver
|
732
|
|
- * @param body
|
|
739
|
+ * @param message
|
|
740
|
+ * @param elementName
|
733
|
741
|
* @param nickname
|
734
|
742
|
*/
|
735
|
|
- sendPrivateMessage(id, body, nickname) {
|
|
743
|
+ sendPrivateMessage(id, message, elementName, nickname) {
|
736
|
744
|
const msg = $msg({ to: `${this.roomjid}/${id}`,
|
737
|
745
|
type: 'chat' });
|
738
|
746
|
|
739
|
|
- msg.c('body', body).up();
|
|
747
|
+ // We are adding the message in packet. If this element is different
|
|
748
|
+ // from 'body', we add our custom namespace for the same.
|
|
749
|
+ // e.g. for 'json-message' message extension.
|
|
750
|
+ if (elementName === 'body') {
|
|
751
|
+ msg.c(elementName, message).up();
|
|
752
|
+ } else {
|
|
753
|
+ msg.c(elementName, { xmlns: 'http://jitsi.org/jitmeet' }, message)
|
|
754
|
+ .up();
|
|
755
|
+ }
|
740
|
756
|
if (nickname) {
|
741
|
757
|
msg.c('nick', { xmlns: 'http://jabber.org/protocol/nick' })
|
742
|
758
|
.t(nickname)
|
|
@@ -745,9 +761,10 @@ export default class ChatRoom extends Listenable {
|
745
|
761
|
}
|
746
|
762
|
|
747
|
763
|
this.connection.send(msg);
|
748
|
|
- this.eventEmitter.emit(XMPPEvents.SENDING_PRIVATE_CHAT_MESSAGE, body);
|
|
764
|
+ this.eventEmitter.emit(
|
|
765
|
+ XMPPEvents.SENDING_PRIVATE_CHAT_MESSAGE, message);
|
749
|
766
|
}
|
750
|
|
-
|
|
767
|
+ /* eslint-enable max-params */
|
751
|
768
|
|
752
|
769
|
/**
|
753
|
770
|
*
|
|
@@ -907,12 +924,15 @@ export default class ChatRoom extends Listenable {
|
907
|
924
|
.length) {
|
908
|
925
|
this.discoRoomInfo();
|
909
|
926
|
}
|
|
927
|
+ const jsonMessage = $(msg).find('>json-message').text();
|
|
928
|
+ const parsedJson = tryParseJSONAndVerify(jsonMessage);
|
910
|
929
|
|
911
|
|
- const jsonPayload = tryParseJSONAndVerify(txt);
|
912
|
|
-
|
913
|
|
- if (jsonPayload) {
|
|
930
|
+ // We emit this event if the message is a valid json, and is not
|
|
931
|
+ // delivered after a delay, i.e. stamp is undefined.
|
|
932
|
+ // e.g. - subtitles should not be displayed if delayed.
|
|
933
|
+ if (parsedJson && stamp === undefined) {
|
914
|
934
|
this.eventEmitter.emit(XMPPEvents.JSON_MESSAGE_RECEIVED,
|
915
|
|
- from, jsonPayload);
|
|
935
|
+ from, parsedJson);
|
916
|
936
|
|
917
|
937
|
return;
|
918
|
938
|
}
|