The server don't send back anymore messages to their sender
This commit is contained in:
@@ -674,8 +674,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
|
||||
var msg = undefined;
|
||||
// Create the string message
|
||||
var date = new Date().getTime();
|
||||
if (data.type === 'PING') {
|
||||
var date = new Date().getTime();
|
||||
msg = JSON.stringify([c.seq++, 'PING', date]);
|
||||
} else {
|
||||
msg = JSON.stringify([c.seq++, data.type, webChannel.id, data.msg]);
|
||||
@@ -686,10 +686,11 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
srvMsg.shift();
|
||||
srvMsg.unshift(webChannel.myID);
|
||||
srvMsg.unshift(0);
|
||||
webChannel.waitingAck[c.seq - 1] = srvMsg;
|
||||
webChannel.waitingAck[c.seq - 1] = { resolve: resolve, reject: reject, time: date, data: srvMsg };
|
||||
// Send the message to the server
|
||||
c.send(msg);
|
||||
}
|
||||
// resolve();
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
@@ -704,8 +705,6 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
}, {
|
||||
@@ -1108,7 +1107,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
this.NAME = this.constructor.name;
|
||||
this.protocol = _ServiceProvider2.default.get(cs.EXCHANGEPROTOCOL_SERVICE);
|
||||
this.defaults = {
|
||||
signaling: 'ws://localhost:9000'
|
||||
signaling: 'ws://localhost:9000',
|
||||
REQUEST_TIMEOUT: 5000
|
||||
};
|
||||
this.settings = Object.assign({}, this.defaults, options);
|
||||
}
|
||||
@@ -1122,6 +1122,19 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
return new Promise(function (resolve, reject) {
|
||||
var connection = undefined;
|
||||
var socket = new window.WebSocket(settings.signaling);
|
||||
setInterval(function () {
|
||||
if (socket.webChannel && socket.webChannel.waitingAck) {
|
||||
var waitingAck = socket.webChannel.waitingAck;
|
||||
for (var id in waitingAck) {
|
||||
var req = waitingAck[id];
|
||||
var now = new Date().getTime();
|
||||
if (now - req.time > settings.REQUEST_TIMEOUT) {
|
||||
delete socket.webChannel.waitingAck[id];
|
||||
req.reject({ type: 'TIMEOUT', message: 'waited ' + now - req.time + 'ms' });
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 5000);
|
||||
socket.seq = 1;
|
||||
socket.facade = options.facade || null;
|
||||
socket.onopen = function () {
|
||||
@@ -1345,15 +1358,15 @@ return /******/ (function(modules) { // webpackBootstrap
|
||||
if (msg[1] === 'ACK') {
|
||||
var seq = msg[0];
|
||||
if (webChannel.waitingAck[seq]) {
|
||||
var newMsg = webChannel.waitingAck[seq];
|
||||
if (parseInt(newMsg[3]) === newMsg[3]) {
|
||||
// PING message
|
||||
var waitingAck = webChannel.waitingAck[seq];
|
||||
waitingAck.resolve();
|
||||
var newMsg = waitingAck.data;
|
||||
if (newMsg[2] === 'PING') {
|
||||
// PING message : set the lag
|
||||
var lag = new Date().getTime() - newMsg[3];
|
||||
webChannel.getLag = function () {
|
||||
return lag;
|
||||
};
|
||||
} else {
|
||||
if (typeof webChannel.onmessage === "function") webChannel.onmessage(newMsg[1], newMsg[4]);
|
||||
}
|
||||
delete webChannel.waitingAck[seq];
|
||||
}
|
||||
|
||||
@@ -294,14 +294,17 @@ define([
|
||||
// Open a Chainpad session
|
||||
realtime = createRealtime();
|
||||
|
||||
// On sending message
|
||||
// Sending a message...
|
||||
realtime.onMessage(function(message) {
|
||||
// Prevent Chainpad from sending authentication messages since it is handled by Netflux
|
||||
// Filter messages sent by Chainpad to make it compatible with Netflux
|
||||
message = chainpadAdapter.msgOut(message, wc);
|
||||
if(message) {
|
||||
wc.send(message).then(function() {
|
||||
// Send the message back to Chainpad once it is sent to all peers if using the WebRTC protocol
|
||||
if(rtc) { onMessage(wc.myID, message); }
|
||||
// Send the message back to Chainpad once it is sent to the recipients.
|
||||
onMessage(wc.myID, message);
|
||||
}, function(err) {
|
||||
// The message has not been sent, display the error.
|
||||
console.error(err);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user