|
|
@ -673,19 +673,21 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
|
var c = _step.value;
|
|
|
|
var c = _step.value;
|
|
|
|
|
|
|
|
|
|
|
|
var msg = undefined;
|
|
|
|
var msg = undefined;
|
|
|
|
|
|
|
|
// Create the string message
|
|
|
|
if (data.type === 'PING') {
|
|
|
|
if (data.type === 'PING') {
|
|
|
|
var date = new Date().getTime();
|
|
|
|
var date = new Date().getTime();
|
|
|
|
msg = JSON.stringify([0, 'PING', date]);
|
|
|
|
msg = JSON.stringify([c.seq++, 'PING', date]);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
msg = JSON.stringify([c.seq++, data.type, webChannel.id, data.msg]);
|
|
|
|
msg = JSON.stringify([c.seq++, data.type, webChannel.id, data.msg]);
|
|
|
|
if (data.type === 'MSG') {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the message with his sequence number to know what message has caused the reception of an ACK
|
|
|
|
|
|
|
|
// This is used in WebSocketProtocolService
|
|
|
|
var srvMsg = JSON.parse(msg);
|
|
|
|
var srvMsg = JSON.parse(msg);
|
|
|
|
srvMsg.shift();
|
|
|
|
srvMsg.shift();
|
|
|
|
srvMsg.unshift(webChannel.myID);
|
|
|
|
srvMsg.unshift(webChannel.myID);
|
|
|
|
srvMsg.unshift(0);
|
|
|
|
srvMsg.unshift(0);
|
|
|
|
webChannel.waitingAck[c.seq - 1] = srvMsg;
|
|
|
|
webChannel.waitingAck[c.seq - 1] = srvMsg;
|
|
|
|
}
|
|
|
|
// Send the message to the server
|
|
|
|
}
|
|
|
|
|
|
|
|
c.send(msg);
|
|
|
|
c.send(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
} catch (err) {
|
|
|
@ -1340,20 +1342,22 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
|
socket.send(JSON.stringify(msg));
|
|
|
|
socket.send(JSON.stringify(msg));
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (msg[1] === 'ACK' && parseInt(msg[2]) === msg[2]) {
|
|
|
|
|
|
|
|
var lag = new Date().getTime() - msg[2];
|
|
|
|
|
|
|
|
webChannel.getLag = function () {
|
|
|
|
|
|
|
|
return lag;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg[1] === 'ACK') {
|
|
|
|
if (msg[1] === 'ACK') {
|
|
|
|
var seq = msg[0];
|
|
|
|
var seq = msg[0];
|
|
|
|
if (webChannel.waitingAck[seq]) {
|
|
|
|
if (webChannel.waitingAck[seq]) {
|
|
|
|
var newMsg = webChannel.waitingAck[seq];
|
|
|
|
var newMsg = webChannel.waitingAck[seq];
|
|
|
|
delete webChannel.waitingAck[seq];
|
|
|
|
if (parseInt(newMsg[3]) === newMsg[3]) {
|
|
|
|
|
|
|
|
// PING message
|
|
|
|
|
|
|
|
var lag = new Date().getTime() - newMsg[3];
|
|
|
|
|
|
|
|
webChannel.getLag = function () {
|
|
|
|
|
|
|
|
return lag;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (typeof webChannel.onmessage === "function") webChannel.onmessage(newMsg[1], newMsg[4]);
|
|
|
|
if (typeof webChannel.onmessage === "function") webChannel.onmessage(newMsg[1], newMsg[4]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete webChannel.waitingAck[seq];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// We have received a new direct message from another user
|
|
|
|
// We have received a new direct message from another user
|
|
|
|
if (msg[2] === 'MSG' && msg[3] === socket.uid) {
|
|
|
|
if (msg[2] === 'MSG' && msg[3] === socket.uid) {
|
|
|
@ -1366,6 +1370,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
|
var msgHistory = JSON.parse(msg[4]);
|
|
|
|
var msgHistory = JSON.parse(msg[4]);
|
|
|
|
webChannel.onmessage(msgHistory[1], msgHistory[4]);
|
|
|
|
webChannel.onmessage(msgHistory[1], msgHistory[4]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (msg[2] === 'JOIN' && (webChannel.id == null || webChannel.id === msg[3])) {
|
|
|
|
if (msg[2] === 'JOIN' && (webChannel.id == null || webChannel.id === msg[3])) {
|
|
|
|
if (!webChannel.id) {
|
|
|
|
if (!webChannel.id) {
|
|
|
@ -1408,17 +1413,20 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
|
waitForOnJoining();
|
|
|
|
waitForOnJoining();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// We have received a new message in that channel from another peer
|
|
|
|
// We have received a new message in that channel from another peer
|
|
|
|
if (msg[2] === 'MSG' && msg[3] === webChannel.id) {
|
|
|
|
if (msg[2] === 'MSG' && msg[3] === webChannel.id) {
|
|
|
|
// Find the peer who sent the message and display it
|
|
|
|
// Find the peer who sent the message and display it
|
|
|
|
//TODO Use Peer instead of peer.id (msg[1]) :
|
|
|
|
//TODO Use Peer instead of peer.id (msg[1]) :
|
|
|
|
if (typeof webChannel.onmessage === "function") webChannel.onmessage(msg[1], msg[4]);
|
|
|
|
if (typeof webChannel.onmessage === "function") webChannel.onmessage(msg[1], msg[4]);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Someone else has left the channel, remove him from the list of peers
|
|
|
|
// Someone else has left the channel, remove him from the list of peers
|
|
|
|
if (msg[2] === 'LEAVE' && msg[3] === webChannel.id) {
|
|
|
|
if (msg[2] === 'LEAVE' && msg[3] === webChannel.id) {
|
|
|
|
//TODO Use Peer instead of peer.id (msg[1]) :
|
|
|
|
//TODO Use Peer instead of peer.id (msg[1]) :
|
|
|
|
if (typeof webChannel.onLeaving === "function") webChannel.onLeaving(msg[1], webChannel);
|
|
|
|
if (typeof webChannel.onLeaving === "function") webChannel.onLeaving(msg[1], webChannel);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
}, {
|
|
|
|