test.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset=utf-8 http-equiv="Content-Language" content="en"/>
  5. <script src="/lws-common.js"></script>
  6. <title>Minimal Websocket test app</title>
  7. <style type="text/css">
  8. span.title { font-size:18pt; font: Arial; font-weight:normal; text-align:center; color:#000000; }
  9. .browser { font-size:18pt; font: Arial; font-weight:normal; text-align:center; color:#ffff00; vertical-align:middle; text-align:center; background:#d0b070; padding:12px; -webkit-border-radius:10px; -moz-border-radius:10px; border-radius:10px;}
  10. .group2 { vertical-align:middle;
  11. text-align:center;
  12. background:#f0f0e0;
  13. padding:12px;
  14. -webkit-border-radius:10px;
  15. -moz-border-radius:10px;
  16. border-radius:10px; }
  17. .explain { vertical-align:middle;
  18. text-align:center;
  19. background:#f0f0c0; padding:12px;
  20. -webkit-border-radius:10px;
  21. -moz-border-radius:10px;
  22. border-radius:10px;
  23. color:#404000; }
  24. td.wsstatus { vertical-align:middle; width:200px; height:50px;
  25. text-align:center;
  26. background:#f0f0c0; padding:6px;
  27. -webkit-border-radius:8px;
  28. -moz-border-radius:8px;
  29. border-radius:8px;
  30. color:#404000; }
  31. .tdform { vertical-align:middle; width:200px; height:50px;
  32. text-align:center;
  33. background:#f0f0d0; padding:6px;
  34. -webkit-border-radius:8px;
  35. -moz-border-radius:8px; margin:10px;
  36. border-radius:8px;
  37. border: 1px solid black;
  38. border-collapse: collapse;font-size:18pt; font: Arial; font-weight:normal; text-align:center; color:#000000;
  39. color:#404000; }
  40. td.l { vertical-align:middle;
  41. text-align:center;
  42. background:#d0d0b0;
  43. padding:3px;
  44. -webkit-border-radius:3px;
  45. -moz-border-radius:3px;
  46. border-radius:3px; }
  47. .content { vertical-align:top; text-align:center; background:#fffff0; padding:12px; -webkit-border-radius:10px; -moz-border-radius:10px; border-radius:10px; }
  48. .canvas { vertical-align:top; text-align:center; background:#efefd0; padding:12px; -webkit-border-radius:10px; -moz-border-radius:10px; border-radius:10px; }
  49. .tabs {
  50. position: relative;
  51. min-height: 750px; /* This part sucks */
  52. clear: both;
  53. margin: 25px 0;
  54. }
  55. .tab {
  56. float: left;
  57. }
  58. .tab label {
  59. background: #eee;
  60. padding: 10px;
  61. border: 1px solid #ccc;
  62. margin-left: -1px;
  63. position: relative;
  64. left: 1px;
  65. }
  66. .tab [type=radio] {
  67. display: none;
  68. }
  69. .content {
  70. position: absolute;
  71. top: 28px;
  72. left: 0;
  73. background: white;
  74. right: 0;
  75. bottom: 0;
  76. padding: 20px;
  77. border: 1px solid #ccc;
  78. }
  79. [type=radio]:checked ~ label {
  80. background: white;
  81. border-bottom: 1px solid white;
  82. z-index: 2;
  83. }
  84. [type=radio]:checked ~ label ~ .content {
  85. z-index: 1;
  86. }
  87. </style>
  88. </head>
  89. <body>
  90. <header></header>
  91. <article>
  92. <table><tr><td>
  93. <table width=600px>
  94. <tr>
  95. <td valign=middle align=center>
  96. <a href="https://libwebsockets.org">
  97. <img src="libwebsockets.org-logo.png"></a></td><td>
  98. <section class="browser">Detected Browser:
  99. <div id=brow>...</div></section>
  100. </td>
  101. </tr>
  102. </table>
  103. </td></tr>
  104. <tr><td colspan=2 align=center>
  105. Click <a href="leaf.jpg" target="_blank">Here</a> to
  106. have the test server send a big picture by http.
  107. </td></tr>
  108. <tr><td colspan=2>
  109. <div class="tabs">
  110. <div class="tab">
  111. <input type="radio" id="tab-1" name="tab-group-1" checked>
  112. <label for="tab-1">Dumb Increment Demo</label>
  113. <div class="content">
  114. <div id="dumb" class="group2">
  115. <table>
  116. <tr>
  117. <td id=wsdi_statustd align=center class="wsstatus">
  118. <span id=wsdi_status>Websocket connection not initialized</span></td>
  119. <td><span class="title">dumb increment-protocol</span></td>
  120. </tr>
  121. <tr>
  122. <td class="explain" colspan=2>
  123. The incrementing number is coming from the server at 20Hz and is individual for
  124. each connection to the server... try opening a second browser window.
  125. <br/><br/>
  126. The button sends a message over the websocket link to ask the server
  127. to zero just this connection's number.
  128. </td>
  129. </tr>
  130. <tr>
  131. <td align=center><div id=number style="font-size:120%;"> </div></td>
  132. <td align=center>
  133. <input type=button id=offset value="Reset counter">
  134. <input type=button id=junk value="Send junk">
  135. </td>
  136. </tr>
  137. </table>
  138. </div>
  139. </div>
  140. </div>
  141. <div class="tab">
  142. <input type="radio" id="tab-2" name="tab-group-1">
  143. <label for="tab-2">Mirror Demo</label>
  144. <div class="content">
  145. <div id="mirror" class="group2">
  146. <table>
  147. <tr>
  148. <td colspan=1 id=wslm_statustd align=center class="wsstatus">
  149. <span id=wslm_status>Websocket connection not initialized</span>
  150. </td>
  151. <td>
  152. <span class="title">lws-mirror-protocol</span>
  153. </td>
  154. </tr>
  155. <tr>
  156. <td colspan=2>
  157. <div class="explain">
  158. Use the mouse to draw on the canvas below -- all other browser windows open
  159. on this page see your drawing in realtime and you can see any of theirs as
  160. well.
  161. <br/><br/>
  162. The lws-mirror protocol doesn't interpret what is being sent to it, it just
  163. re-sends it to every other websocket it has a connection with using that
  164. protocol, including the guy who sent the packet.
  165. <br/><br/>
  166. <b>libwebsockets-test-client</b> joins in by spamming circles on to this shared canvas when
  167. run.
  168. </div>
  169. </td>
  170. </tr>
  171. <tr>
  172. <td colspan=2>Drawing color:
  173. <select id="color">
  174. <option value=#000000>Black</option>
  175. <option value=#0000ff>Blue</option>
  176. <option value=#20ff20>Green</option>
  177. <option value=#802020>Dark Red</option>
  178. </select>
  179. </tr>
  180. <tr>
  181. <td colspan=2 width=500 height=320>
  182. <div id="wslm_drawing" style="background:white"></div>
  183. </td>
  184. </tr>
  185. </table>
  186. </div>
  187. </div>
  188. </div>
  189. <div class="tab">
  190. <input type="radio" id="tab-3" name="tab-group-1">
  191. <label for="tab-3">Close Testing</label>
  192. <div class="content">
  193. <div id="ot" class="group2">
  194. <table>
  195. <tr>
  196. <td>
  197. </td></tr>
  198. <tr><td id=ot_statustd align=center class="wsstatus">
  199. <span id=ot_status>Websocket connection not initialized</span>
  200. </td>
  201. <td colspan=2><span class="title">Open and close testing</span></td>
  202. </tr>
  203. <tr>
  204. <td class="explain" colspan=3 style="padding:3">
  205. To help with open and close testing, you can open and close a connection by hand using
  206. the buttons.<br>
  207. "<b>Close</b>" closes the connection from the browser with code 3000
  208. and reason 'Bye!".<br>
  209. "<b>Request Server Close</b>" sends a message asking the server to
  210. initiate the close, which it does with code 1001 and reason "Seeya".
  211. </td></tr>
  212. <tr>
  213. <td align=center><input type=button id=ot_open_btn value="Open"></td>
  214. <td align=center><input type=button id=ot_close_btn disabled value="Close" ></td>
  215. <td align=center><input type=button id=ot_req_close_btn disabled value="Request Server Close" ></td>
  216. </tr>
  217. </table>
  218. </div>
  219. </div>
  220. </div>
  221. <div class="tab">
  222. <input type="radio" id="tab-4" name="tab-group-1">
  223. <label for="tab-4">Server info</label>
  224. <div class="content">
  225. <div id="ot" class="group2">
  226. <table>
  227. <tr>
  228. <td id=s_statustd align=center class="wsstatus">
  229. <div id=s_status>Websocket connection not initialized</div>
  230. </td>
  231. <td colspan=1>
  232. <span class="title">Server Info</span>
  233. </td>
  234. </tr><tr>
  235. <td class="explain" colspan=2>
  236. This information is sent by the server over a ws[s] link and updated live
  237. whenever the information changes server-side.
  238. </td></tr>
  239. <tr>
  240. <td align=center colspan=2><div id=servinfo></div></td>
  241. </tr>
  242. <tr>
  243. <td align=center colspan=2><div id=conninfo style="border : solid 2px #e0d040; padding : 4px; width : 500px; height : 350px; overflow : auto; "></</div></td>
  244. </tr>
  245. </table>
  246. </div>
  247. </div>
  248. </div>
  249. <div class="tab">
  250. <input type="radio" id="tab-5" name="tab-group-1">
  251. <label for="tab-5">POST</label>
  252. <div class="content">
  253. <div id="ot" class="group2">
  254. <table width=100%>
  255. <tr>
  256. <td colspan=1>
  257. <span class="title">POST Form testing</span>
  258. </td>
  259. </tr><tr>
  260. <td class="explain" colspan=2>
  261. This tests POST handling in lws.
  262. </td></tr>
  263. <tr>
  264. <td align=center colspan=2 class=tdform><div id=postinfo style=form>
  265. FORM 1: send with urlencoded POST body args<br>
  266. <form action="formtest" method="post">
  267. <span style="font-size:12pt;">Some text: </span>
  268. <input type="text" name="text" value="Give me some text"><br>
  269. <input type="submit" name="send" value="Send the form">
  270. </form>
  271. </div></td>
  272. </tr>
  273. <script nonce="lwscaro">
  274. function check_file()
  275. {
  276. var f = document.getElementById('file').files[0];
  277. var max_len = 100000;
  278. var dis = 0;
  279. if (f) {
  280. if (f.size >= max_len) {
  281. dis = 1;
  282. document.getElementById('file_info').innerHTML =
  283. "<span style=\"color:red;font-weight:bold\">File larger than "+max_len+"</span>";
  284. } else
  285. document.getElementById('file_info').innerHTML =
  286. "File length "+f.size;
  287. } else
  288. dis = 1;
  289. document.getElementById('upload').disabled = dis;
  290. }
  291. </script>
  292. <tr>
  293. <td align=center colspan=2 class=tdform><div id=postinfo style=form>
  294. FORM 2: send with multipart/form-data<br>
  295. (can handle file upload, test limited to 100KB)<br>
  296. <form name=multipart action="formtest" method="post" enctype="multipart/form-data">
  297. <span style="font-size:12pt;">Some text: </span>
  298. <input type="text" name="text" value="Give me some text">
  299. <br>
  300. <input type="file" name="file" id="file" size="20">&nbsp;<span id=file_info style="font-size:12pt;"></span><br>
  301. <input type="submit" id="upload" name="upload" disabled=1 value="Upload">
  302. </form>
  303. </div></td>
  304. </tr>
  305. </table>
  306. </div>
  307. </div>
  308. </div>
  309. </div>
  310. </td></tr></table>
  311. Looking for support? <a href="https://libwebsockets.org">https://libwebsockets.org</a>, <a href="https://github.com/warmcat/libwebsockets">https://github.com/warmcat/libwebsockets</a></a><br/>
  312. Join the mailing list: <a href="https://libwebsockets.org/mailman/listinfo/libwebsockets">https://libwebsockets.org/mailman/listinfo/libwebsockets</a>
  313. </article>
  314. <script nonce="lwscaro">
  315. document.getElementById('file').onchange = check_file;
  316. document.getElementById('offset').onclick = reset;
  317. document.getElementById('junk').onclick = junk;
  318. document.getElementById('color').onclick = update_color;
  319. document.getElementById('ot_open_btn').onclick = ot_open;
  320. document.getElementById('ot_close_btn').onclick = ot_close;
  321. document.getElementById('ot_req_close_btn').onclick = ot_req_close;
  322. /*
  323. * We display untrusted stuff in html context... reject anything
  324. * that has HTML stuff in it
  325. */
  326. function san(s)
  327. {
  328. if (s.search("<") != -1)
  329. return "invalid string";
  330. return s;
  331. }
  332. lws_gray_out(true,{'zindex':'499'});
  333. /* BrowserDetect came from http://www.quirksmode.org/js/detect.html */
  334. var BrowserDetect = {
  335. init: function () {
  336. this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
  337. this.version = this.searchVersion(navigator.userAgent)
  338. || this.searchVersion(navigator.appVersion)
  339. || "an unknown version";
  340. this.OS = this.searchString(this.dataOS) || "an unknown OS";
  341. },
  342. searchString: function (data) {
  343. for (var i=0;i<data.length;i++) {
  344. var dataString = data[i].string;
  345. var dataProp = data[i].prop;
  346. this.versionSearchString = data[i].versionSearch || data[i].identity;
  347. if (dataString) {
  348. if (dataString.indexOf(data[i].subString) != -1)
  349. return data[i].identity;
  350. }
  351. else if (dataProp)
  352. return data[i].identity;
  353. }
  354. },
  355. searchVersion: function (dataString) {
  356. var index = dataString.indexOf(this.versionSearchString);
  357. if (index == -1) return;
  358. return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
  359. },
  360. dataBrowser: [
  361. {
  362. string: navigator.userAgent,
  363. subString: "Chrome",
  364. identity: "Chrome"
  365. },
  366. { string: navigator.userAgent,
  367. subString: "OmniWeb",
  368. versionSearch: "OmniWeb/",
  369. identity: "OmniWeb"
  370. },
  371. {
  372. string: navigator.vendor,
  373. subString: "Apple",
  374. identity: "Safari",
  375. versionSearch: "Version"
  376. },
  377. {
  378. prop: window.opera,
  379. identity: "Opera",
  380. versionSearch: "Version"
  381. },
  382. {
  383. string: navigator.vendor,
  384. subString: "iCab",
  385. identity: "iCab"
  386. },
  387. {
  388. string: navigator.vendor,
  389. subString: "KDE",
  390. identity: "Konqueror"
  391. },
  392. {
  393. string: navigator.userAgent,
  394. subString: "Firefox",
  395. identity: "Firefox"
  396. },
  397. {
  398. string: navigator.vendor,
  399. subString: "Camino",
  400. identity: "Camino"
  401. },
  402. { // for newer Netscapes (6+)
  403. string: navigator.userAgent,
  404. subString: "Netscape",
  405. identity: "Netscape"
  406. },
  407. {
  408. string: navigator.userAgent,
  409. subString: "MSIE",
  410. identity: "Explorer",
  411. versionSearch: "MSIE"
  412. },
  413. {
  414. string: navigator.userAgent,
  415. subString: "Gecko",
  416. identity: "Mozilla",
  417. versionSearch: "rv"
  418. },
  419. { // for older Netscapes (4-)
  420. string: navigator.userAgent,
  421. subString: "Mozilla",
  422. identity: "Netscape",
  423. versionSearch: "Mozilla"
  424. }
  425. ],
  426. dataOS : [
  427. {
  428. string: navigator.platform,
  429. subString: "Win",
  430. identity: "Windows"
  431. },
  432. {
  433. string: navigator.platform,
  434. subString: "Mac",
  435. identity: "Mac"
  436. },
  437. {
  438. string: navigator.userAgent,
  439. subString: "iPhone",
  440. identity: "iPhone/iPod"
  441. },
  442. {
  443. string: navigator.platform,
  444. subString: "Linux",
  445. identity: "Linux"
  446. }
  447. ]
  448. };
  449. BrowserDetect.init();
  450. document.getElementById("brow").textContent = " " + BrowserDetect.browser + " "
  451. + BrowserDetect.version +" " + BrowserDetect.OS +" ";
  452. var pos = 0;
  453. function get_appropriate_ws_url()
  454. {
  455. var pcol;
  456. var u = document.URL;
  457. /*
  458. * We open the websocket encrypted if this page came on an
  459. * https:// url itself, otherwise unencrypted
  460. */
  461. if (u.substring(0, 5) == "https") {
  462. pcol = "wss://";
  463. u = u.substr(8);
  464. } else {
  465. pcol = "ws://";
  466. if (u.substring(0, 4) == "http")
  467. u = u.substr(7);
  468. }
  469. u = u.split('/');
  470. /* + "/xxx" bit is for IE10 workaround */
  471. return pcol + u[0] + "/xxx";
  472. }
  473. document.getElementById("number").textContent = get_appropriate_ws_url();
  474. /* dumb increment protocol */
  475. var socket_di;
  476. if (typeof MozWebSocket != "undefined") {
  477. socket_di = new MozWebSocket(get_appropriate_ws_url(),
  478. "dumb-increment-protocol");
  479. } else {
  480. socket_di = new WebSocket(get_appropriate_ws_url(),
  481. "dumb-increment-protocol");
  482. }
  483. try {
  484. socket_di.onopen = function() {
  485. document.getElementById("wsdi_statustd").style.backgroundColor = "#40ff40";
  486. document.getElementById("wsdi_status").innerHTML =
  487. " <b>websocket connection opened</b><br>" +
  488. san(socket_di.extensions);
  489. }
  490. socket_di.onmessage =function got_packet(msg) {
  491. document.getElementById("number").textContent = msg.data + "\n";
  492. }
  493. socket_di.onclose = function(){
  494. document.getElementById("wsdi_statustd").style.backgroundColor = "#ff4040";
  495. document.getElementById("wsdi_status").textContent = " websocket connection CLOSED ";
  496. }
  497. } catch(exception) {
  498. alert('<p>Error' + exception);
  499. }
  500. var socket_status, jso, s;
  501. if (typeof MozWebSocket != "undefined") {
  502. socket_status = new MozWebSocket(get_appropriate_ws_url(),
  503. "lws-status");
  504. } else {
  505. socket_status = new WebSocket(get_appropriate_ws_url(),
  506. "lws-status");
  507. }
  508. try {
  509. socket_status.onopen = function() {
  510. document.getElementById("s_statustd").style.backgroundColor = "#40ff40";
  511. document.getElementById("s_status").innerHTML =
  512. " <b>websocket connection opened</b><br>" +
  513. san(socket_status.extensions);
  514. }
  515. socket_status.onmessage =function got_packet(msg) {
  516. var s;
  517. jso = JSON.parse(msg.data);
  518. document.getElementById("servinfo").innerHTML =
  519. "<table><tr><td class=l>Build info</td><td>"+
  520. san(jso.version) + "</td></tr>" +
  521. "<tr><td class=l>Server info</td><td>" +
  522. san(jso.hostname) + "</td></tr>" +
  523. "</table>";
  524. s="<table>";
  525. var n;
  526. for (n = 0; n < jso.conns.length; n++) {
  527. var d = new Date(parseInt(jso.conns[n].time) * 1000);
  528. s = s + "<tr><td class=l>client " + (n + 1) +
  529. "</td><td><b>" + san(jso.conns[n].peer) +
  530. "</b><br>" + san(d.toString()) +
  531. "<br>" + san(jso.conns[n].ua) +
  532. "</td></tr>";
  533. }
  534. s = s + "</table>";
  535. document.getElementById("conninfo").innerHTML = s;
  536. }
  537. socket_status.onclose = function(){
  538. document.getElementById("s_statustd").style.backgroundColor = "#ff4040";
  539. document.getElementById("s_status").textContent = " websocket connection CLOSED ";
  540. }
  541. } catch(exception) {
  542. alert('<p>Error' + exception);
  543. }
  544. function reset() {
  545. socket_di.send("reset\n");
  546. }
  547. function junk() {
  548. for(var word = ''; word.length < 9000; word += 'a'){}
  549. socket_di.send(word);
  550. }
  551. var socket_ot;
  552. function ot_open() {
  553. if (typeof MozWebSocket != "undefined") {
  554. socket_ot = new MozWebSocket(get_appropriate_ws_url(),
  555. "dumb-increment-protocol");
  556. } else {
  557. socket_ot = new WebSocket(get_appropriate_ws_url(),
  558. "dumb-increment-protocol");
  559. }
  560. try {
  561. socket_ot.onopen = function() {
  562. document.getElementById("ot_statustd").style.backgroundColor = "#40ff40";
  563. document.getElementById("ot_status").innerHTML = " <b>websocket connection opened</b><br>" + san(socket_di.extensions);
  564. document.getElementById("ot_open_btn").disabled = true;
  565. document.getElementById("ot_close_btn").disabled = false;
  566. document.getElementById("ot_req_close_btn").disabled = false;
  567. }
  568. socket_ot.onclose = function(e){
  569. document.getElementById("ot_statustd").style.backgroundColor = "#ff4040";
  570. document.getElementById("ot_status").textContent = " websocket connection CLOSED, code: " + e.code +
  571. ", reason: " + e.reason;
  572. document.getElementById("ot_open_btn").disabled = false;
  573. document.getElementById("ot_close_btn").disabled = true;
  574. document.getElementById("ot_req_close_btn").disabled = true;
  575. }
  576. } catch(exception) {
  577. alert('<p>Error' + exception);
  578. }
  579. }
  580. /* browser will close the ws in a controlled way */
  581. function ot_close() {
  582. socket_ot.close(3000, "Bye!");
  583. }
  584. /* we ask the server to close the ws in a controlled way */
  585. function ot_req_close() {
  586. socket_ot.send("closeme\n");
  587. }
  588. /* lws-mirror protocol */
  589. var down = 0;
  590. var no_last = 1;
  591. var last_x = 0, last_y = 0;
  592. var ctx;
  593. var socket_lm;
  594. var color = "#000000";
  595. if (typeof MozWebSocket != "undefined") {
  596. socket_lm = new MozWebSocket(get_appropriate_ws_url(),
  597. "lws-mirror-protocol");
  598. } else {
  599. socket_lm = new WebSocket(get_appropriate_ws_url(),
  600. "lws-mirror-protocol");
  601. }
  602. try {
  603. socket_lm.onopen = function() {
  604. document.getElementById("wslm_statustd").style.backgroundColor = "#40ff40";
  605. document.getElementById("wslm_status").innerHTML =
  606. " <b>websocket connection opened</b><br>" +
  607. san(socket_lm.extensions);
  608. lws_gray_out(false);
  609. }
  610. socket_lm.onmessage =function got_packet(msg) {
  611. j = msg.data.split(';');
  612. f = 0;
  613. while (f < j.length - 1) {
  614. i = j[f].split(' ');
  615. if (i[0] == 'd') {
  616. ctx.strokeStyle = i[1];
  617. ctx.beginPath();
  618. ctx.moveTo(+(i[2]), +(i[3]));
  619. ctx.lineTo(+(i[4]), +(i[5]));
  620. ctx.stroke();
  621. }
  622. if (i[0] == 'c') {
  623. ctx.strokeStyle = i[1];
  624. ctx.beginPath();
  625. ctx.arc(+(i[2]), +(i[3]), +(i[4]), 0, Math.PI*2, true);
  626. ctx.stroke();
  627. }
  628. f++;
  629. }
  630. }
  631. socket_lm.onclose = function(){
  632. document.getElementById("wslm_statustd").style.backgroundColor = "#ff4040";
  633. document.getElementById("wslm_status").textContent = " websocket connection CLOSED ";
  634. lws_gray_out(true,{'zindex':'499'});
  635. }
  636. } catch(exception) {
  637. alert('<p>Error' + exception);
  638. }
  639. var canvas = document.createElement('canvas');
  640. canvas.height = 300;
  641. canvas.width = 480;
  642. ctx = canvas.getContext("2d");
  643. document.getElementById('wslm_drawing').appendChild(canvas);
  644. canvas.addEventListener('mousemove', ev_mousemove, false);
  645. canvas.addEventListener('mousedown', ev_mousedown, false);
  646. canvas.addEventListener('mouseup', ev_mouseup, false);
  647. offsetX = offsetY = 0;
  648. element = canvas;
  649. if (element.offsetParent) {
  650. do {
  651. offsetX += element.offsetLeft;
  652. offsetY += element.offsetTop;
  653. } while ((element = element.offsetParent));
  654. }
  655. function update_color() {
  656. color = document.getElementById("color").value;
  657. }
  658. function ev_mousedown (ev) {
  659. down = 1;
  660. }
  661. function ev_mouseup(ev) {
  662. down = 0;
  663. no_last = 1;
  664. }
  665. function ev_mousemove (ev) {
  666. var x, y;
  667. if (ev.offsetX) {
  668. x = ev.offsetX;
  669. y = ev.offsetY;
  670. } else {
  671. x = ev.layerX - offsetX;
  672. y = ev.layerY - offsetY;
  673. }
  674. if (!down)
  675. return;
  676. if (no_last) {
  677. no_last = 0;
  678. last_x = x;
  679. last_y = y;
  680. return;
  681. }
  682. socket_lm.send("d " + color + " " + last_x + " " + last_y + " " + x + ' ' + y + ';');
  683. last_x = x;
  684. last_y = y;
  685. }
  686. </script>
  687. </body>
  688. </html>