[SignalingServer] Fix a connection problem on message port 26/265026/1 submit/tizen/20211007.160021
authorHunseop Jeong <hs85.jeong@samsung.com>
Thu, 7 Oct 2021 08:33:03 +0000 (17:33 +0900)
committerHunseop Jeong <hs85.jeong@samsung.com>
Thu, 7 Oct 2021 08:33:03 +0000 (17:33 +0900)
The message port does not guarantee that the connection
has been disconnected when the page is reloaded. So, if
new connection occurs with the same socket id, the existing
connection is disconnected.

Change-Id: I0ed924821990129fe22d3adb752700bab0b28be7
Signed-off-by: Hunseop Jeong <hs85.jeong@samsung.com>
device_home/signaling_server/gen/app.js

index 5419924..44998f0 100644 (file)
@@ -177,8 +177,8 @@ function onConnection(socket) {
     );
 
     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,
@@ -333,6 +333,16 @@ if (supportMessagePort) {
     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();