Skip to content
This repository has been archived by the owner on Aug 13, 2018. It is now read-only.

Commit

Permalink
#33 Some messages not picked up
Browse files Browse the repository at this point in the history
  • Loading branch information
janodvarko committed Mar 29, 2016
1 parent 0de2274 commit ce805da
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
30 changes: 18 additions & 12 deletions data/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
25 changes: 22 additions & 3 deletions lib/wsm-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -252,7 +254,7 @@ const WsmPanel = Class(
/**
* Parse JSON
*/
decodeJsonPacket: function (data) {
decodeJsonPacket: function(data) {
try {
return JSON.parse(data);
} catch (err) {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit ce805da

Please sign in to comment.