From ce805daa484d0834778fcbee6ba86e8c390d33af Mon Sep 17 00:00:00 2001 From: Jan Odvarko Date: Tue, 29 Mar 2016 15:08:38 +0200 Subject: [PATCH] #33 Some messages not picked up --- data/view.js | 30 ++++++++++++++++++------------ lib/wsm-panel.js | 25 ++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/data/view.js b/data/view.js index 63d6ac4..1d98b78 100644 --- a/data/view.js +++ b/data/view.js @@ -87,21 +87,27 @@ var WebSocketsView = createView(PanelView, * about the mapping event -> method. */ frameReceived: function(frame) { - frame = JSON.parse(decodeURIComponent(escape(frame))); - frame.received = true; - frame.type = "frame"; - frame.data.webSocketSerialID = frame.webSocketSerialID; - - this.lazyAdd(frame); + try { + frame = JSON.parse(decodeURIComponent(escape(frame))); + frame.received = true; + frame.type = "frame"; + frame.data.webSocketSerialID = frame.webSocketSerialID; + this.lazyAdd(frame); + } catch (err) { + console.log(err); + } }, frameSent: function(frame) { - frame = JSON.parse(decodeURIComponent(escape(frame))); - frame.sent = true; - frame.type = "frame"; - frame.data.webSocketSerialID = frame.webSocketSerialID; - - this.lazyAdd(frame); + try { + frame = JSON.parse(decodeURIComponent(escape(frame))); + frame.sent = true; + frame.type = "frame"; + frame.data.webSocketSerialID = frame.webSocketSerialID; + this.lazyAdd(frame); + } catch (err) { + console.log(err); + } }, lazyAdd: function(frame) { diff --git a/lib/wsm-panel.js b/lib/wsm-panel.js index e01a960..299fdbb 100644 --- a/lib/wsm-panel.js +++ b/lib/wsm-panel.js @@ -205,12 +205,14 @@ const WsmPanel = Class( onFrameReceived: function(frame) { this.decodePacket(frame, frame.data.payload); - this.postContentMessage("frameReceived", JSON.stringify(frame)); + this.postContentMessage("frameReceived", + convertFromUnicode(JSON.stringify(frame))); }, onFrameSent: function(frame) { this.decodePacket(frame, frame.data.payload); - this.postContentMessage("frameSent", JSON.stringify(frame)); + this.postContentMessage("frameSent", + convertFromUnicode(JSON.stringify(frame))); }, decodePacket: function(data, payload) { @@ -252,7 +254,7 @@ const WsmPanel = Class( /** * Parse JSON */ - decodeJsonPacket: function (data) { + decodeJsonPacket: function(data) { try { return JSON.parse(data); } catch (err) { @@ -289,6 +291,23 @@ const WsmPanel = Class( } }); +function convertFromUnicode(text) { + if (!text) { + return ""; + } + + try { + var conv = Cc["@mozilla.org/intl/scriptableunicodeconverter"] + .createInstance(Ci.nsIScriptableUnicodeConverter); + conv.charset = "UTF-8"; + return conv.ConvertFromUnicode(text); + } catch (err) { + console.error(err); + } + + return ""; +}; + // Registration const myTool = new Tool({ name: "MyTool",