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

Commit 4f0b0ba

Browse files
committed
Merge branch 'master' of github.com:firebug/websocket-monitor
2 parents 7fcfbd8 + 312f977 commit 4f0b0ba

File tree

9 files changed

+152
-29
lines changed

9 files changed

+152
-29
lines changed

data/actions/config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* See license.txt for terms of usage */
2+
3+
define(function(require, exports/*, module*/) {
4+
5+
"use strict";
6+
7+
const types = {
8+
UPDATE_CONFIG: "UPDATE_CONFIG",
9+
}
10+
11+
function updateConfig(key, newValue) {
12+
var data = {
13+
key,
14+
newValue
15+
};
16+
17+
return { type: types.UPDATE_CONFIG, data };
18+
}
19+
20+
// Exports from this module
21+
exports.updateConfig = updateConfig;
22+
exports.types = types;
23+
});
24+

data/components/frame-list.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ var FrameList = React.createClass({
8282
key: "frame-" + frame.id,
8383
frame: frame,
8484
selection: this.props.selection,
85-
dispatch: this.props.dispatch
85+
dispatch: this.props.dispatch,
86+
config: this.props.config
8687
}));
8788
}
8889

@@ -156,40 +157,37 @@ var FrameBubble = React.createFactory(React.createClass({
156157
// Render inline frame preview. There is just one preview displayed
157158
var preview;
158159

159-
if (!preview && frame.socketIo) {
160+
if (this.props.config.enableSocketIo !== false && frame.socketIo) {
160161
preview = TreeView({
161162
key: "preview-socketio",
162163
// We only show the data that is deemed interesting for the user in the
163164
// inline previews, not the socketIO metadata
164165
data: {"Socket IO": frame.socketIo.data},
165166
mode: "tiny"
166167
});
167-
}
168-
169-
if (!preview && frame.sockJs) {
168+
} else if (this.props.config.enableSockJs !== false && frame.sockJs) {
170169
preview = TreeView({
171170
key: "preview-sockjs",
172171
data: {"SockJS": frame.sockJs},
173172
mode: "tiny"
174173
});
175-
}
176-
177-
if (!preview && frame.json) {
174+
} else if (this.props.config.enableJson !== false && frame.json) {
178175
preview = TreeView({
179176
key: "preview-json",
180177
data: {"JSON": frame.json},
181178
mode: "tiny"
182179
});
183-
}
180+
} else if (this.props.config.enableMqtt !== false && frame.mqtt) {
184181

185-
if (!preview && frame.mqtt) {
186182
var mqtt = frame.mqtt;
187183
op = "MQTT " + mqtt.cmd;
184+
188185
if (mqtt.cmd === "publish") {
189186
payload = mqtt.topic;
190187
} else {
191188
payload = mqtt.messageId || mqtt.clientId || mqtt.returnCode;
192189
}
190+
193191
preview = TreeView({
194192
key: "preview-mqtt",
195193
data: {"MQTT": mqtt},

data/components/frame-table.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ var FrameTable = React.createClass({
5757
key: frame.id,
5858
selection: this.props.selection,
5959
frame: frame,
60-
dispatch: this.props.dispatch
60+
dispatch: this.props.dispatch,
61+
config: this.props.config
6162
}));
6263

6364
// Render summary info
@@ -166,24 +167,24 @@ var FrameRow = React.createFactory(React.createClass({
166167
var payload;
167168

168169
// Test support for inline previews.
169-
if (frame.socketIo) {
170+
if (this.props.config.enableSocketIo !== false && frame.socketIo) {
170171
payload = TreeView({
171172
key: "preview-socketio",
172173
// We only show the data that is deemed interesting for the user in the
173174
// inline previews, not the socketIO metadata
174175
data: {"Socket IO": frame.socketIo.data},
175176
});
176-
} else if (frame.sockJs) {
177+
} else if (this.props.config.enableSockJs !== false && frame.sockJs) {
177178
payload = TreeView({
178179
key: "preview-sockjs",
179180
data: {"SockJS": frame.sockJs},
180181
});
181-
} else if (frame.json) {
182+
} else if (this.props.config.enableJson !== false && frame.json) {
182183
payload = TreeView({
183184
key: "preview-json",
184185
data: {"JSON": frame.json},
185186
});
186-
} else if (frame.mqtt) {
187+
} else if (this.props.config.enableMqtt !== false && frame.mqtt) {
187188
payload = TreeView({
188189
key: "preview-mqtt",
189190
data: {"MQTT": frame.mqtt},

data/containers/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ var App = React.createClass({
101101
function mapStateToProps(state) {
102102
return {
103103
frames: state.frames,
104+
config: state.config,
104105
selection: state.frames.selection,
105106
perspective: state.perspective
106107
};

data/reducers/config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* See license.txt for terms of usage */
2+
3+
define(function(require, exports/*, module*/) {
4+
5+
"use strict";
6+
7+
const { types } = require("../actions/config");
8+
9+
const initialState = {};
10+
11+
function config(state = initialState, action) {
12+
switch (action.type) {
13+
case types.UPDATE_CONFIG:
14+
state[action.data.key] = action.data.newValue;
15+
16+
return state;
17+
18+
default:
19+
return state;
20+
}
21+
}
22+
23+
// Exports from this module
24+
exports.config = config;
25+
});
26+

data/reducers/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ const { combineReducers } = require("redux");
1010
// WebSockets Monitor
1111
const { frames } = require("./frames");
1212
const { perspective } = require("./perspective");
13+
const { config } = require("./config");
1314

1415
var rootReducer = combineReducers({
1516
frames,
16-
perspective
17+
perspective,
18+
config
1719
});
1820

1921
// Exports from this module

data/view.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ const { App } = createFactories(require("./containers/app"));
2121
const { configureStore } = require("./store/configure-store");
2222
const { addFrames, filterFrames, clear } = require("./actions/frames");
2323
const { showTableView, showListView } = require("./actions/perspective");
24+
const { updateConfig } = require("./actions/config");
2425

25-
var store = configureStore();
26+
/** Redux store, populated on view initialize */
27+
var store;
2628

2729
/**
2830
* This object represents a view that is responsible for rendering
@@ -53,6 +55,18 @@ var WebSocketsView = createView(PanelView,
5355

5456
// Render the top level application component.
5557
this.content = document.getElementById("content");
58+
59+
// Initialize the redux store with user preferences
60+
store = configureStore({
61+
config: {
62+
enableSocketIo: Options.get("enableSocketIo"),
63+
enableSockJs: Options.get("enableSockJs"),
64+
enableJson: Options.get("enableJson"),
65+
enableMqtt: Options.get("enableMqtt"),
66+
}
67+
});
68+
69+
// Render the app
5670
this.theApp = ReactDOM.render(Provider({store: store},
5771
App(config)
5872
), this.content);
@@ -152,15 +166,27 @@ var WebSocketsView = createView(PanelView,
152166

153167
onPrefChanged: function(event) {
154168
var prefName = event.prefName;
155-
if (prefName != "tabularView") {
156-
return;
157-
}
158169

159-
// Update the way how frames are displayed.
160-
if (event.newValue) {
161-
store.dispatch(showTableView());
162-
} else {
163-
store.dispatch(showListView());
170+
switch (prefName) {
171+
case "tabularView":
172+
173+
// Update the way how frames are displayed.
174+
if (event.newValue) {
175+
store.dispatch(showTableView());
176+
} else {
177+
store.dispatch(showListView());
178+
}
179+
break;
180+
case "enableSocketIo":
181+
case "enableSockJs":
182+
case "enableJson":
183+
case "enableMqtt":
184+
185+
// Place protocol toggle prefs into config store
186+
store.dispatch(updateConfig(prefName, event.newValue));
187+
break;
188+
default:
189+
break;
164190
}
165191
}
166192
});

lib/wsm-panel.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ const WsmPanel = Class(
228228
// Socket.IO Parser
229229

230230
decodeSocketIoPacket: function(data) {
231+
if (!prefs.enableSocketIo) {
232+
return;
233+
}
234+
231235
let result;
232236
try {
233237
var decoder = new socketIoParser.Decoder();
@@ -251,13 +255,21 @@ const WsmPanel = Class(
251255
* Parse Sock.JS
252256
*/
253257
decodeSockJsPacket: function(data) {
258+
if (!prefs.enableSockJs) {
259+
return;
260+
}
261+
254262
return sockJsParser.parse(data);
255263
},
256264

257265
/**
258266
* Parse JSON
259267
*/
260268
decodeJsonPacket: function(data) {
269+
if (!prefs.enableJson) {
270+
return;
271+
}
272+
261273
try {
262274
return JSON.parse(data);
263275
} catch (err) {
@@ -286,18 +298,22 @@ const WsmPanel = Class(
286298
* Parse MQTT using mqtt-packet parser
287299
*/
288300
decodeMqttPacket: function(data) {
301+
if (!prefs.enableMqtt) {
302+
return;
303+
}
304+
289305
try {
290306
var parser = mqttParser();
291307
// View binary ACString input data as bytes
292-
var buffer = new Buffer(data, 'binary');
308+
var buffer = new Buffer(data, "binary");
293309
var result = null;
294310

295-
parser.on('packet', function(packet) {
311+
parser.on("packet", function(packet) {
296312
// Assume there's only one MQTT packet in the Websocket frame
297313
result = packet;
298314
});
299315

300-
parser.on('error', function(packet) {
316+
parser.on("error", function(packet) {
301317
// TODO: should we display an error somewhere?
302318
});
303319

@@ -307,7 +323,7 @@ const WsmPanel = Class(
307323
if (result.cmd === "publish") {
308324
// Try to decode the payload binary buffer
309325
try {
310-
result.payload = result.payload.toString('utf8');
326+
result.payload = result.payload.toString("utf8");
311327
result.payload = JSON.parse(result.payload);
312328
} catch (err) {
313329
}

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,35 @@
5252
"description": "Display sent and received frames in tabular format",
5353
"type": "bool",
5454
"value": true
55+
},
56+
{
57+
"name": "enableSocketIo",
58+
"title": "Socket.IO support",
59+
"description": "Parse Socket.IO frames",
60+
"type": "bool",
61+
"value": true
62+
},
63+
{
64+
"name": "enableSockJs",
65+
"title": "SockJS support",
66+
"description": "Parse SockJS frames",
67+
"type": "bool",
68+
"value": true
69+
},
70+
{
71+
"name": "enableJson",
72+
"title": "JSON support",
73+
"description": "Parse JSON frames",
74+
"type": "bool",
75+
"value": true
76+
},
77+
{
78+
"name": "enableMqtt",
79+
"title": "MQTT support",
80+
"description": "Parse MQTT frames",
81+
"type": "bool",
82+
"value": true
5583
}
84+
5685
]
5786
}

0 commit comments

Comments
 (0)