);
for (const client of clients) {
- const socket = sockets.get(client);
- socket.emit('worker', {
+ const clientSocket = sockets.get(client);
+ clientSocket.emit('worker', {
event: 'join',
workerId: worker.id,
socketId: socket.id,
const id = value.id;
if (event === 'connect') {
+ // FIXME: The message port does not guarantee that the connection has
+ // been disconnected when the page is reloaded. Therefore, if a new
+ // connection occurs with the same id, the existing connection is
+ // disconnected.
+ if (sockets.has(id)) {
+ console.log(TAG, `Disconnect already connected socket: ${id}`);
+ const socket = sockets.get(id);
+ socket.handleEvents('disconnect');
+ }
+
const socket = new SocketTizen(id, localPort);
socket.on('connection', onConnection);
socket.connect();