Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Process missing messages during reconnection #468

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/sdk/conference/signaling.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {Base64} from '../base/base64.js';
'use strict';

const reconnectionAttempts = 10;
const maxSequence = 2147483647;

// eslint-disable-next-line require-jsdoc
function handleResponse(status, data, resolve, reject) {
Expand Down Expand Up @@ -39,6 +40,7 @@ export class SioSignaling extends EventModule.EventDispatcher {
this._reconnectTimes = 0;
this._reconnectionTicket = null;
this._refreshReconnectionTicket = null;
this._messageSequence = 0;
}

/**
Expand Down Expand Up @@ -69,6 +71,7 @@ export class SioSignaling extends EventModule.EventDispatcher {
data: data,
},
}));
this._incrementMessageSequence();
});
});
this._socket.on('reconnecting', () => {
Expand Down Expand Up @@ -102,7 +105,28 @@ export class SioSignaling extends EventModule.EventDispatcher {
data) => {
if (status === 'ok') {
this._reconnectTimes = 0;
this._onReconnectionTicket(data);
if (typeof data === 'object') {
if (Array.isArray(data.messages)) {
let isMissingStart = false;
for (const msg of data.messages) {
if (isMissingStart) {
this.dispatchEvent(
new EventModule.MessageEvent('data', {
message: {
notification: msg.event,
data: msg.data,
},
}));
this._incrementMessageSequence();
} else if (msg.seq === this._messageSequence) {
isMissingStart = true;
}
}
}
this._onReconnectionTicket(data.ticket);
} else {
this._onReconnectionTicket(data);
}
} else {
this.dispatchEvent(new EventModule.OwtEvent('disconnect'));
}
Expand Down Expand Up @@ -201,4 +225,19 @@ export class SioSignaling extends EventModule.EventDispatcher {
clearTimeout(this._refreshReconnectionTicket);
this._refreshReconnectionTicket = null;
}

/**
* @function _clearReconnectionTask
* @instance
* @desc Increase the message sequence.
* @memberof Owt.Conference.SioSignaling
* @private.
*/
_incrementMessageSequence() {
if (this._messageSequence === maxSequence) {
this._messageSequence = 0;
} else {
this._messageSequence++;
}
}
}