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

Process missing messages during reconnection #323

Open
wants to merge 3 commits into
base: 4.2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/sdk/conference/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const SignalingState = {
CONNECTED: 3,
};

const protocolVersion = '1.0';
const protocolVersion = '1.0.1';

/* eslint-disable valid-jsdoc */
/**
Expand Down
33 changes: 32 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,27 @@ 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 @@ -193,4 +216,12 @@ export class SioSignaling extends EventModule.EventDispatcher {
clearTimeout(this._refreshReconnectionTicket);
this._refreshReconnectionTicket = null;
}

_incrementMessageSequence() {
if (this._messageSequence === maxSequence) {
this._messageSequence = 0;
} else {
this._messageSequence++;
}
}
}