modules/websocket: updated example configuration and test scripts
[sip-router] / modules / websocket / example / websocket_test.html
1 <!DOCTYPE html>
2
3 <meta charset="utf-8" />
4
5 <title>WebSocket Test</title>
6
7 <script language="javascript" type="text/javascript">
8 var wsUri = "wss://192.168.111.2/";
9 var output;
10
11 function init()
12 {
13         output = document.getElementById("output");
14         testWebSocket();
15 }
16
17 function testWebSocket() 
18 {
19         websocket = new WebSocket(wsUri, "sip");
20         websocket.onopen = function(evt) { onOpen(evt) };
21         websocket.onclose = function(evt) { onClose(evt) };
22         websocket.onmessage = function(evt) { onMessage(evt) };
23         websocket.onerror = function(evt) { onError(evt) };
24 }
25
26 function onOpen(evt)
27 {
28         writeToScreen("CONNECTED");
29         doSend("OPTIONS sip:alice@example.com SIP/2.0\r\nVia: SIP/2.0/WSS abcd1234.invalid;branch=z9hG4bkabcd1234\r\nMax-Forwards: 70\r\nTo: <sip:alice@example.com>\r\nFrom: <sip:bob@example.com>;tag=abcd1234\r\nCall-ID: abcd1234\r\nCSeq: 1 OPTIONS\r\nContact: <sip:bob@abcd1234;transport=ws>\r\n\r\n");
30 }
31
32 function onClose(evt)
33 {
34         writeToScreen("DISCONNECTED");
35 }
36
37 function onMessage(evt)
38 {
39         writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>'); websocket.close();
40 }
41
42 function onError(evt)
43 {
44         writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
45 }
46
47 function doSend(message)
48 {
49         writeToScreen("SENT: " + message);
50         websocket.send(message);
51 }
52
53 function writeToScreen(message)
54 {
55         var pre = document.createElement("p");
56         pre.style.wordWrap = "break-word";
57         pre.innerHTML = message; output.appendChild(pre);
58 }
59
60 window.addEventListener("load", init, false);
61
62 </script>
63
64 <h2>WebSocket Test</h2>
65
66 <div id="output"></div>
67
68 </html>