|
| 1 | +/* See license.txt for terms of usage */ |
| 2 | + |
| 3 | +define(function(require, exports/*, module*/) { |
| 4 | + |
| 5 | +"use strict"; |
| 6 | + |
| 7 | +// ReactJS |
| 8 | +const React = require("react"); |
| 9 | + |
| 10 | +// Firebug SDK |
| 11 | +const { Str } = require("reps/core/string"); |
| 12 | + |
| 13 | +// WebSockets Monitor |
| 14 | +const { selectFrame } = require("../actions/selection"); |
| 15 | + |
| 16 | +// Constants |
| 17 | +const { table, thead, th, tbody, tr, td, tfoot, div } = React.DOM; |
| 18 | + |
| 19 | +/** |
| 20 | + * This components implements the main table layout for list of frames. |
| 21 | + */ |
| 22 | +var FrameTable = React.createClass({ |
| 23 | +/** @lends FrameTable */ |
| 24 | + |
| 25 | + displayName: "FrameTable", |
| 26 | + |
| 27 | + render: function() { |
| 28 | + var frames = this.props.frames.frames; |
| 29 | + |
| 30 | + // Render list frames. |
| 31 | + var rows = frames.map(frame => FrameRow({ |
| 32 | + selection: this.props.selection, |
| 33 | + frame: frame, |
| 34 | + dispatch: this.props.dispatch |
| 35 | + })); |
| 36 | + |
| 37 | + return ( |
| 38 | + table({className: "frameTable"}, |
| 39 | + thead({className: "frameTHead"}, |
| 40 | + tr({}, |
| 41 | + th({className: "direction"}), |
| 42 | + th({className: "socketId"}, Locale.$STR("websocketmonitor.SocketID")), |
| 43 | + th({className: "payloadSize"}, Locale.$STR("websocketmonitor.Size")), |
| 44 | + th({className: "payload"}, Locale.$STR("websocketmonitor.Payload")), |
| 45 | + th({className: "opcode"}, Locale.$STR("websocketmonitor.OpCode")), |
| 46 | + th({className: "bit"}, Locale.$STR("websocketmonitor.MaskBit")), |
| 47 | + th({className: "bit"}, Locale.$STR("websocketmonitor.FinBit")), |
| 48 | + th({className: "time"}, Locale.$STR("websocketmonitor.Time")) |
| 49 | + ) |
| 50 | + ), |
| 51 | + tbody({className: "frameTBody"}, |
| 52 | + rows |
| 53 | + )/*, |
| 54 | + tfoot({className: "frameTFoot"}, |
| 55 | + tr({}, |
| 56 | + td({colSpan: 5}, "Summary: ") |
| 57 | + ) |
| 58 | + )*/ |
| 59 | + ) |
| 60 | + ); |
| 61 | + } |
| 62 | +}); |
| 63 | + |
| 64 | +/** |
| 65 | + * Represents a row within the frame list. |
| 66 | + */ |
| 67 | +var FrameRow = React.createFactory(React.createClass({ |
| 68 | +/** @lends FrameRow */ |
| 69 | + |
| 70 | + displayName: "FrameRow", |
| 71 | + |
| 72 | + onClick: function() { |
| 73 | + if (this.props.frame != this.props.selection) { |
| 74 | + this.props.dispatch(selectFrame(this.props.frame)); |
| 75 | + } |
| 76 | + }, |
| 77 | + |
| 78 | + getOpCode: function() { |
| 79 | + var frame = this.props.frame; |
| 80 | + var data = frame.header ? frame.header : frame.maskBit; |
| 81 | + var opCode = parseInt(data.opCode, 10); |
| 82 | + |
| 83 | + switch (opCode) { |
| 84 | + case data.OPCODE_CONTINUATION: |
| 85 | + return "CONTINUATION"; |
| 86 | + case data.OPCODE_TEXT: |
| 87 | + return "TEXT"; |
| 88 | + case data.OPCODE_BINARY: |
| 89 | + return "BINARY"; |
| 90 | + case data.OPCODE_CLOSE: |
| 91 | + return "CLOSE"; |
| 92 | + case data.OPCODE_PING: |
| 93 | + return "PING"; |
| 94 | + case data.OPCODE_PONG: |
| 95 | + return "PONG"; |
| 96 | + } |
| 97 | + |
| 98 | + return "(unknown)"; |
| 99 | + }, |
| 100 | + |
| 101 | + render: function() { |
| 102 | + var frame = this.props.frame; |
| 103 | + var data = frame.header ? frame.header : frame.maskBit; |
| 104 | + var className = "frameRow " + (frame.header ? "send" : "receive"); |
| 105 | + var tooltipText = frame.header ? "Sent" : "Received"; |
| 106 | + |
| 107 | + if (this.props.selection == frame) { |
| 108 | + className += " selected"; |
| 109 | + } |
| 110 | + |
| 111 | + var payload = Str.cropString(data.payload, 50); |
| 112 | + var size = Str.formatSize(data.payload.length); |
| 113 | + var onClick = this.onClick.bind(this); |
| 114 | + var time = new Date(data.timeStamp / 1000); |
| 115 | + var timeText = time.getHours() + ":" + time.getMinutes() + |
| 116 | + ":" + time.getSeconds() + "." + time.getMilliseconds(); |
| 117 | + |
| 118 | + return ( |
| 119 | + tr({className: className, onClick: onClick}, |
| 120 | + td({className: "direction"}, |
| 121 | + div({title: tooltipText}) |
| 122 | + ), |
| 123 | + td({className: "socketId"}, frame.webSocketSerialID), |
| 124 | + td({className: "payloadSize"}, size), |
| 125 | + td({className: "payload"}, payload), |
| 126 | + td({className: "opcode"}, this.getOpCode()), |
| 127 | + td({className: "bit"}, data.maskBit ? "true" : "false"), |
| 128 | + td({className: "bit"}, data.finBit ? "true" : "false"), |
| 129 | + td({className: "time"}, timeText) |
| 130 | + ) |
| 131 | + ); |
| 132 | + } |
| 133 | +})); |
| 134 | + |
| 135 | +// Exports from this module |
| 136 | +exports.FrameTable = FrameTable; |
| 137 | +}); |
0 commit comments