瀏覽代碼

fix: Skips sending an extra presence on join. (#1174)

* fix: Skips sending an extra presence on join.

* Renames the variable names.
dev1
Дамян Минков 5 年之前
父節點
當前提交
3c8d411c96
沒有連結到貢獻者的電子郵件帳戶。
共有 2 個檔案被更改,包括 15 行新增10 行删除
  1. 0
    4
      JitsiConference.js
  2. 15
    6
      modules/xmpp/ChatRoom.js

+ 0
- 4
JitsiConference.js 查看文件

839
  */
839
  */
840
 JitsiConference.prototype.setDisplayName = function(name) {
840
 JitsiConference.prototype.setDisplayName = function(name) {
841
     if (this.room) {
841
     if (this.room) {
842
-        // remove previously set nickname
843
-        this.room.removeFromPresence('nick');
844
-
845
         this.room.addToPresence('nick', {
842
         this.room.addToPresence('nick', {
846
             attributes: { xmlns: 'http://jabber.org/protocol/nick' },
843
             attributes: { xmlns: 'http://jabber.org/protocol/nick' },
847
             value: name
844
             value: name
2304
         return;
2301
         return;
2305
     }
2302
     }
2306
     this.startMutedPolicy = policy;
2303
     this.startMutedPolicy = policy;
2307
-    this.room.removeFromPresence('startmuted');
2308
     this.room.addToPresence('startmuted', {
2304
     this.room.addToPresence('startmuted', {
2309
         attributes: {
2305
         attributes: {
2310
             audio: policy.audio,
2306
             audio: policy.audio,

+ 15
- 6
modules/xmpp/ChatRoom.js 查看文件

162
                 }
162
                 }
163
             });
163
             });
164
         }
164
         }
165
+
166
+        this.presenceUpdateTime = Date.now();
165
     }
167
     }
166
 
168
 
167
     /**
169
     /**
223
         }
225
         }
224
 
226
 
225
         parser.json2packet(this.presMap.nodes, pres);
227
         parser.json2packet(this.presMap.nodes, pres);
228
+
229
+        // we store time we last synced presence state
230
+        this.presenceSyncTime = Date.now();
231
+
226
         this.connection.send(pres);
232
         this.connection.send(pres);
227
         if (fromJoin) {
233
         if (fromJoin) {
228
             // XXX We're pressed for time here because we're beginning a complex
234
             // XXX We're pressed for time here because we're beginning a complex
518
 
524
 
519
                 // Re-send presence in case any presence updates were added,
525
                 // Re-send presence in case any presence updates were added,
520
                 // but blocked from sending, during the join process.
526
                 // but blocked from sending, during the join process.
521
-                this.sendPresence();
527
+                // send the presence only if there was a modification after we had synced it
528
+                if (this.presenceUpdateTime >= this.presenceSyncTime) {
529
+                    this.sendPresence();
530
+                }
522
 
531
 
523
                 this.eventEmitter.emit(XMPPEvents.MUC_JOINED);
532
                 this.eventEmitter.emit(XMPPEvents.MUC_JOINED);
524
 
533
 
1143
     /* eslint-enable max-params */
1152
     /* eslint-enable max-params */
1144
 
1153
 
1145
     /**
1154
     /**
1146
-     *
1155
+     * Adds the key to the presence map, overriding any previous value.
1147
      * @param key
1156
      * @param key
1148
      * @param values
1157
      * @param values
1149
      */
1158
      */
1151
         values.tagName = key;
1160
         values.tagName = key;
1152
         this.removeFromPresence(key);
1161
         this.removeFromPresence(key);
1153
         this.presMap.nodes.push(values);
1162
         this.presMap.nodes.push(values);
1163
+        this.presenceUpdateTime = Date.now();
1154
     }
1164
     }
1155
 
1165
 
1156
     /**
1166
     /**
1157
-     * Retreives a value from the presence map.
1167
+     * Retrieves a value from the presence map.
1158
      *
1168
      *
1159
      * @param {string} key - The key to find the value for.
1169
      * @param {string} key - The key to find the value for.
1160
      * @returns {Object?}
1170
      * @returns {Object?}
1164
     }
1174
     }
1165
 
1175
 
1166
     /**
1176
     /**
1167
-     *
1177
+     * Removes a key from the presence map.
1168
      * @param key
1178
      * @param key
1169
      */
1179
      */
1170
     removeFromPresence(key) {
1180
     removeFromPresence(key) {
1171
         const nodes = this.presMap.nodes.filter(node => key !== node.tagName);
1181
         const nodes = this.presMap.nodes.filter(node => key !== node.tagName);
1172
 
1182
 
1173
         this.presMap.nodes = nodes;
1183
         this.presMap.nodes = nodes;
1184
+        this.presenceUpdateTime = Date.now();
1174
     }
1185
     }
1175
 
1186
 
1176
     /**
1187
     /**
1275
      * @param mute
1286
      * @param mute
1276
      */
1287
      */
1277
     addAudioInfoToPresence(mute) {
1288
     addAudioInfoToPresence(mute) {
1278
-        this.removeFromPresence('audiomuted');
1279
         this.addToPresence(
1289
         this.addToPresence(
1280
             'audiomuted',
1290
             'audiomuted',
1281
             {
1291
             {
1304
      * @param mute
1314
      * @param mute
1305
      */
1315
      */
1306
     addVideoInfoToPresence(mute) {
1316
     addVideoInfoToPresence(mute) {
1307
-        this.removeFromPresence('videomuted');
1308
         this.addToPresence(
1317
         this.addToPresence(
1309
             'videomuted',
1318
             'videomuted',
1310
             {
1319
             {

Loading…
取消
儲存