Debian Codegraph @

jetty-ee9/jetty-ee9-websocket/jetty-ee9-websocket-jakarta-server/src/test/resources/jsr-browser-debug-tool/websocket.js

raw
1 if (!window.WebSocket && window.MozWebSocket) {
2 window.WebSocket = window.MozWebSocket;
3 }
4
5 if (!window.WebSocket) {
6 alert("WebSocket not supported by this browser");
7 }
8
9 function $() {
10 return document.getElementById(arguments[0]);
11 }
12
13 function $F() {
14 return document.getElementById(arguments[0]).value;
15 }
16
17 function getKeyCode(ev) {
18 if (window.event)
19 return window.event.keyCode;
20 return ev.keyCode;
21 }
22
23 var wstool = {
24 connect: function () {
25 var location = document.location.toString().replace('http://', 'ws://')
26 .replace('https://', 'wss://');
27
28 wstool.info("Document URI: " + document.location);
29 wstool.info("WS URI: " + location);
30
31 this._scount = 0;
32
33 try {
34 this._ws = new WebSocket(location, "tool");
35 this._ws.onopen = this._onopen;
36 this._ws.onmessage = this._onmessage;
37 this._ws.onclose = this._onclose;
38 this._ws.onerror = this._onerror;
39 } catch (exception) {
40 wstool.info("Connect Error: " + exception);
41 }
42 },
43
44 close: function () {
45 this._ws.close();
46 },
47
48 _out: function (css, message) {
49 var console = $('console');
50 var spanText = document.createElement('span');
51 spanText.className = 'text ' + css;
52 spanText.innerHTML = message;
53 var lineBreak = document.createElement('br');
54 console.appendChild(spanText);
55 console.appendChild(lineBreak);
56 console.scrollTop = console.scrollHeight - console.clientHeight;
57 },
58
59 info: function (message) {
60 wstool._out("info", message);
61 },
62
63 error: function (message) {
64 wstool._out("error", message);
65 },
66
67 infoc: function (message) {
68 wstool._out("client", "[c] " + message);
69 },
70
71 infos: function (message) {
72 this._scount++;
73 wstool._out("server", "[s" + this._scount + "] " + message);
74 },
75
76 setState: function (enabled) {
77 $('connect').disabled = enabled;
78 $('close').disabled = !enabled;
79 $('info').disabled = !enabled;
80 $('time').disabled = !enabled;
81 $('many').disabled = !enabled;
82 $('manythreads').disabled = !enabled;
83 $('hello').disabled = !enabled;
84 $('there').disabled = !enabled;
85 $('json').disabled = !enabled;
86 },
87
88 _onopen: function () {
89 wstool.setState(true);
90 wstool.info("Websocket Connected");
91 },
92
93 _onerror: function (evt) {
94 wstool.setState(false);
95 wstool.error("Websocket Error: " + evt.data);
96 wstool.error("See Javascript Console for possible detailed error message");
97 },
98
99 _send: function (message) {
100 if (this._ws) {
101 this._ws.send(message);
102 wstool.infoc(message);
103 }
104 },
105
106 write: function (text) {
107 wstool._send(text);
108 },
109
110 _onmessage: function (m) {
111 if (m.data) {
112 wstool.infos(m.data);
113 }
114 },
115
116 _onclose: function (closeEvent) {
117 this._ws = null;
118 wstool.setState(false);
119 wstool.info("Websocket Closed");
120 wstool.info(" .wasClean = " + closeEvent.wasClean);
121
122 var codeMap = {};
123 codeMap[1000] = "(NORMAL)";
124 codeMap[1001] = "(ENDPOINT_GOING_AWAY)";
125 codeMap[1002] = "(PROTOCOL_ERROR)";
126 codeMap[1003] = "(UNSUPPORTED_DATA)";
127 codeMap[1004] = "(UNUSED/RESERVED)";
128 codeMap[1005] = "(INTERNAL/NO_CODE_PRESENT)";
129 codeMap[1006] = "(INTERNAL/ABNORMAL_CLOSE)";
130 codeMap[1007] = "(BAD_DATA)";
131 codeMap[1008] = "(POLICY_VIOLATION)";
132 codeMap[1009] = "(MESSAGE_TOO_BIG)";
133 codeMap[1010] = "(HANDSHAKE/EXT_FAILURE)";
134 codeMap[1011] = "(SERVER/UNEXPECTED_CONDITION)";
135 codeMap[1015] = "(INTERNAL/TLS_ERROR)";
136 var codeStr = codeMap[closeEvent.code];
137 wstool.info(" .code = " + closeEvent.code + " " + codeStr);
138 wstool.info(" .reason = " + closeEvent.reason);
139 }
140 };