Improve the detection of a disconnected peer to update the user list with the WebRTC service
This commit is contained in:
parent
77e7fb5724
commit
3a188625e0
@ -9,7 +9,6 @@ var run = module.exports.run = function(server) {
|
|||||||
socket.on('message', (data) => {
|
socket.on('message', (data) => {
|
||||||
try {
|
try {
|
||||||
let msg = JSON.parse(data)
|
let msg = JSON.parse(data)
|
||||||
console.log(msg);
|
|
||||||
if (msg.hasOwnProperty('key')) {
|
if (msg.hasOwnProperty('key')) {
|
||||||
for (let master of server.clients) {
|
for (let master of server.clients) {
|
||||||
if (master.key === msg.key) {
|
if (master.key === msg.key) {
|
||||||
@ -33,7 +32,6 @@ var run = module.exports.run = function(server) {
|
|||||||
socket.master = master
|
socket.master = master
|
||||||
master.joiningClients.push(socket)
|
master.joiningClients.push(socket)
|
||||||
let id = master.joiningClients.length - 1
|
let id = master.joiningClients.length - 1
|
||||||
console.log(id);
|
|
||||||
master.send(JSON.stringify({id, data: msg.data}))
|
master.send(JSON.stringify({id, data: msg.data}))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -222,9 +222,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
|
|
||||||
_createClass(WebChannel, [{
|
_createClass(WebChannel, [{
|
||||||
key: 'leave',
|
key: 'leave',
|
||||||
value: function leave() {
|
value: function leave() {}
|
||||||
this.topologyService.leave(this);
|
|
||||||
}
|
|
||||||
}, {
|
}, {
|
||||||
key: 'send',
|
key: 'send',
|
||||||
value: function send(data) {
|
value: function send(data) {
|
||||||
@ -491,6 +489,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
if (webChannel.channels.size === 0) {
|
if (webChannel.channels.size === 0) {
|
||||||
webChannel.channels.add(channel);
|
webChannel.channels.add(channel);
|
||||||
channel.onclose = function () {
|
channel.onclose = function () {
|
||||||
|
webChannel.onLeaving(channel.peerID);
|
||||||
webChannel.channels.delete(channel);
|
webChannel.channels.delete(channel);
|
||||||
};
|
};
|
||||||
resolve(channel.peerID);
|
resolve(channel.peerID);
|
||||||
@ -522,6 +521,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
var channel = webChannel.aboutToJoin.get(id);
|
var channel = webChannel.aboutToJoin.get(id);
|
||||||
webChannel.channels.add(webChannel.aboutToJoin.get(id));
|
webChannel.channels.add(webChannel.aboutToJoin.get(id));
|
||||||
channel.onclose = function () {
|
channel.onclose = function () {
|
||||||
|
webChannel.onLeaving(channel.peerID);
|
||||||
webChannel.channels.delete(channel);
|
webChannel.channels.delete(channel);
|
||||||
};
|
};
|
||||||
//webChannel.aboutToJoin.delete(id)
|
//webChannel.aboutToJoin.delete(id)
|
||||||
@ -602,8 +602,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
}, {
|
}, {
|
||||||
key: 'leave',
|
key: 'leave',
|
||||||
value: function leave(webChannel) {
|
value: function leave(webChannel) {
|
||||||
var protocol = _ServiceProvider2.default.get(cs.EXCHANGEPROTOCOL_SERVICE);
|
this.broadcast(webChannel);
|
||||||
this.broadcast(webChannel, protocol.message(cs.LEAVING, { id: webChannel.myID }));
|
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: '_generateID',
|
key: '_generateID',
|
||||||
@ -946,6 +945,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
e.channel.webChannel = webChannel;
|
e.channel.webChannel = webChannel;
|
||||||
e.channel.onmessage = _this3.protocol.onmessage;
|
e.channel.onmessage = _this3.protocol.onmessage;
|
||||||
webChannel.channels.add(e.channel);
|
webChannel.channels.add(e.channel);
|
||||||
|
e.channel.onclose = function () {
|
||||||
|
webChannel.onLeaving(e.channel.peerID);
|
||||||
|
webChannel.channels.delete(e.channel);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
connection.onicecandidate = function (e) {
|
connection.onicecandidate = function (e) {
|
||||||
@ -1158,9 +1161,6 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
case cs.GET_HISTORY:
|
case cs.GET_HISTORY:
|
||||||
webChannel.onPeerMessage(msg.id, msg.code);
|
webChannel.onPeerMessage(msg.id, msg.code);
|
||||||
break;
|
break;
|
||||||
case cs.LEAVING:
|
|
||||||
webChannel.onLeaving(msg.id);
|
|
||||||
break;
|
|
||||||
case cs.SERVICE_DATA:
|
case cs.SERVICE_DATA:
|
||||||
var service = _ServiceProvider2.default.get(msg.service);
|
var service = _ServiceProvider2.default.get(msg.service);
|
||||||
service.onmessage(channel, msg.data);
|
service.onmessage(channel, msg.data);
|
||||||
@ -1178,7 +1178,6 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
case cs.JOIN_FINISH:
|
case cs.JOIN_FINISH:
|
||||||
webChannel.topologyService.addFinish(webChannel, msg.id);
|
webChannel.topologyService.addFinish(webChannel, msg.id);
|
||||||
if (msg.id != webChannel.myID) {
|
if (msg.id != webChannel.myID) {
|
||||||
console.log('different id');
|
|
||||||
webChannel.onJoining(msg.id);
|
webChannel.onJoining(msg.id);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1196,9 +1195,6 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
case cs.GET_HISTORY:
|
case cs.GET_HISTORY:
|
||||||
msg.id = data.id;
|
msg.id = data.id;
|
||||||
break;
|
break;
|
||||||
case cs.LEAVING:
|
|
||||||
msg.id = data.id;
|
|
||||||
break;
|
|
||||||
case cs.SERVICE_DATA:
|
case cs.SERVICE_DATA:
|
||||||
msg.service = data.service;
|
msg.service = data.service;
|
||||||
msg.data = Object.assign({}, data.data);
|
msg.data = Object.assign({}, data.data);
|
||||||
|
|||||||
@ -281,10 +281,6 @@ define([
|
|||||||
onPeerMessage(peerId, type, wc);
|
onPeerMessage(peerId, type, wc);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.onunload = function() {
|
|
||||||
wc.leave();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Open a Chainpad session
|
// Open a Chainpad session
|
||||||
realtime = createRealtime();
|
realtime = createRealtime();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user