Disconnect from shared/service worker
This commit is contained in:
@@ -1143,6 +1143,14 @@ define([
|
||||
var driveEventClients = [];
|
||||
var messengerEventClients = [];
|
||||
|
||||
var dropChannel = function (chanId) {
|
||||
if (!Store.channels[chanId]) { return; }
|
||||
|
||||
if (Store.channels[chanId].wc) {
|
||||
Store.channels[chanId].wc.leave('');
|
||||
}
|
||||
delete Store.channels[chanId];
|
||||
};
|
||||
Store._removeClient = function (clientId) {
|
||||
var driveIdx = driveEventClients.indexOf(clientId);
|
||||
if (driveIdx !== -1) {
|
||||
@@ -1157,6 +1165,9 @@ define([
|
||||
if (chanIdx !== -1) {
|
||||
Store.channels[chanId].clients.splice(chanIdx, 1);
|
||||
}
|
||||
if (Store.channels[chanId].clients.length === 0) {
|
||||
dropChannel(chanId);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -125,6 +125,10 @@ var init = function (client, cb) {
|
||||
}, true);
|
||||
|
||||
self.tabs[client.id].msgEv = msgEv;
|
||||
|
||||
self.tabs[client.id].close = function () {
|
||||
Rpc._removeClient(client.id);
|
||||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -139,6 +143,11 @@ self.addEventListener('message', function (e) {
|
||||
init(e.source, function () {
|
||||
postMsg(e.source, 'SW_READY');
|
||||
});
|
||||
} else if (e.data === "CLOSE") {
|
||||
if (tabs[cId] && tabs[cId].close) {
|
||||
console.log('leave');
|
||||
tabs[cId].close();
|
||||
}
|
||||
} else if (self.tabs[cId] && self.tabs[cId].msgEv) {
|
||||
self.tabs[cId].msgEv.fire(e);
|
||||
}
|
||||
|
||||
@@ -127,6 +127,10 @@ var init = function (client, cb) {
|
||||
}, true);
|
||||
|
||||
client.msgEv = msgEv;
|
||||
|
||||
client.close = function () {
|
||||
Rpc._removeClient(client.id);
|
||||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -147,6 +151,11 @@ onconnect = function(e) {
|
||||
init(client, function () {
|
||||
postMsg(client, 'SW_READY');
|
||||
});
|
||||
} else if (e.data === "CLOSE") {
|
||||
if (client && client.close) {
|
||||
console.log('leave');
|
||||
client.close();
|
||||
}
|
||||
} else if (client && client.msgEv) {
|
||||
client.msgEv.fire(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user