From 9a0b1c6abb9869179561745de671487df6198e92 Mon Sep 17 00:00:00 2001 From: Harunobu Ishii Date: Fri, 7 Jun 2024 17:30:56 -0400 Subject: [PATCH] codacy error being resolved --- lib/client/socket/events.js | 20 ++++++++++---------- lib/ext/jiff-client-websockets.js | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/client/socket/events.js b/lib/client/socket/events.js index 0309cd4ce..7b186eada 100644 --- a/lib/client/socket/events.js +++ b/lib/client/socket/events.js @@ -32,7 +32,7 @@ class SocketEvent { // parse message const json_msg = JSON.parse(msg); - const sender_id = json_msg['party_id']; + const sender_id = String(json_msg['party_id']); if (this.jiffClient.keymap[sender_id] != null) { this.jiffClient.handlers.receive_share(json_msg); @@ -66,7 +66,7 @@ class SocketEvent { callback(true); // send ack to server const json_msg = JSON.parse(msg); - const sender_id = json_msg['party_id']; + const sender_id = String(json_msg['party_id']); const encrypted = json_msg['encrypted']; if (this.jiffClient.keymap[sender_id] != null || encrypted !== true) { @@ -82,15 +82,15 @@ class SocketEvent { this.jiffClient.socket.on('crypto_provider', (msg, callback) => { callback(true); // send ack to server - this.jiffClient.handlers.receive_crypto_provider(JSON.parse(msg)); + this.jiffClient.handlers.receive_crypto_provider(JSON.parse(String(msg))); }); - this.jiffClient.socket.on('error', (msg) => { + this.jiffClient.socket.on('error', (_msg) => { try { - msg = JSON.parse(msg); + const msg = JSON.parse(_msg); this.jiffClient.handlers.error(msg['label'], msg['error']); } catch (error) { - this.jiffClient.handlers.error('socket.io', msg); + this.jiffClient.handlers.error('socket.io', _msg); } }); @@ -122,8 +122,8 @@ class SocketEvent { // Check if the parties to wait for are now known let parties_satisfied = this.jiffClient.__initialized || !initialization; for (let j = 0; j < parties.length; j++) { - const party_id = parties[j]; - if (this.jiffClient.keymap == null || this.jiffClient.keymap[party_id] == null) { + const party_id = parties[parseInt(j, 10)]; + if (this.jiffClient.keymap == null || this.jiffClient.keymap[String(party_id)] == null) { parties_satisfied = false; break; } @@ -145,7 +145,7 @@ class SocketEvent { */ resolve_messages_waiting_for_keys() { for (let party_id in this.jiffClient.keymap) { - if (!this.jiffClient.keymap.hasOwnProperty(party_id)) { + if (!this.jiffClient.keymap.hasOwnProperty(String(party_id))) { continue; } @@ -166,7 +166,7 @@ class SocketEvent { } } - this.jiffClient.messagesWaitingKeys[party_id] = null; + this.jiffClient.messagesWaitingKeys[String(party_id)] = null; } } } diff --git a/lib/ext/jiff-client-websockets.js b/lib/ext/jiff-client-websockets.js index 39c618082..7a16e7207 100644 --- a/lib/ext/jiff-client-websockets.js +++ b/lib/ext/jiff-client-websockets.js @@ -54,7 +54,7 @@ * not have as many protocols. Instead these functions are routed to * when a message is received and a protocol is manually parsed. */ - jiff.initSocket = function () { + jiff.socketEvent.initSocket = function () { const jiffClient = this; /* ws uses the 'open' protocol on connection. Should not conflict with the @@ -222,7 +222,7 @@ JIFFClientInstance.socket.send(JSON.stringify({ socketProtocol: 'initialization', data: msg })); }; - JIFFClientInstance.initSocket(); + JIFFClientInstance.socketEvent.initSocket(); }; /* Functions that overwrite client/socket/mailbox.js functionality */