aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/sockets.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/sockets.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/sockets.js363
1 files changed, 182 insertions, 181 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/sockets.js b/js/helper-classes/RDGE/src/core/script/sockets.js
index 7d6192d2..d8246bb7 100755
--- a/js/helper-classes/RDGE/src/core/script/sockets.js
+++ b/js/helper-classes/RDGE/src/core/script/sockets.js
@@ -1,181 +1,182 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License. 4
5 5Redistribution and use in source and binary forms, with or without
6Redistribution and use in source and binary forms, with or without 6modification, are permitted provided that the following conditions are met:
7modification, are permitted provided that the following conditions are met: 7
8 8* Redistributions of source code must retain the above copyright notice,
9 - Redistributions of source code must retain the above copyright notice, 9 this list of conditions and the following disclaimer.
10 this list of conditions and the following disclaimer. 10
11 - Redistributions in binary form must reproduce the above copyright 11* Redistributions in binary form must reproduce the above copyright notice,
12 notice, this list of conditions and the following disclaimer in the 12 this list of conditions and the following disclaimer in the documentation
13 documentation and/or other materials provided with the distribution. 13 and/or other materials provided with the distribution.
14 - Neither the name of Motorola Mobility nor the names of its contributors 14
15 may be used to endorse or promote products derived from this software 15* Neither the name of Motorola Mobility LLC nor the names of its
16 without specific prior written permission. 16 contributors may be used to endorse or promote products derived from this
17 17 software without specific prior written permission.
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28POSSIBILITY OF SUCH DAMAGE. 28ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29</copyright> */ 29POSSIBILITY OF SUCH DAMAGE.
30 30</copyright> */
31// RDGE namespaces 31
32var RDGE = RDGE || {}; 32// RDGE namespaces
33 33var RDGE = RDGE || {};
34/* 34
35* Simple socket connection discovery and management 35/*
36*/ 36* Simple socket connection discovery and management
37 37*/
38RDGE.CreateSocket = function (url, listenList, connectedList, messageHandler, socketID, openHandler, closeHandler) { 38
39 var ws = new WebSocket(url); 39RDGE.CreateSocket = function (url, listenList, connectedList, messageHandler, socketID, openHandler, closeHandler) {
40 40 var ws = new WebSocket(url);
41 ws.listenIndex = socketID; 41
42 42 ws.listenIndex = socketID;
43 ws.onmessage = messageHandler; 43
44 44 ws.onmessage = messageHandler;
45 ws.connectedList = connectedList; 45
46 ws.listenList = listenList; 46 ws.connectedList = connectedList;
47 47 ws.listenList = listenList;
48 // make up a flag 48
49 ws.rdge_isConnected = false; 49 // make up a flag
50 ws.rdge_tryDisconnect = false; 50 ws.rdge_isConnected = false;
51 51 ws.rdge_tryDisconnect = false;
52 if (openHandler) { 52
53 ws.addEventListener("open", openHandler); 53 if (openHandler) {
54 } 54 ws.addEventListener("open", openHandler);
55 if (closeHandler) { 55 }
56 ws.addEventListener("close", closeHandler); 56 if (closeHandler) {
57 ws.addEventListener("error", closeHandler); 57 ws.addEventListener("close", closeHandler);
58 } 58 ws.addEventListener("error", closeHandler);
59 59 }
60 ws.onopen = function (evt) { 60
61 var websocket = evt.srcElement; 61 ws.onopen = function (evt) {
62 document.getElementById("socketConnection").innerHTML += "connected: " + websocket.URL + "</br>"; 62 var websocket = evt.srcElement;
63 63 document.getElementById("socketConnection").innerHTML += "connected: " + websocket.URL + "</br>";
64 websocket.rdge_isConnected = true; 64
65 65 websocket.rdge_isConnected = true;
66 websocket.connectedList.push(ws); 66
67 67 websocket.connectedList.push(ws);
68 // save the connected array index of this item 68
69 ws.connectedIndex = websocket.connectedList.length - 1; 69 // save the connected array index of this item
70 }; 70 ws.connectedIndex = websocket.connectedList.length - 1;
71 71 };
72 ws.onerror = function (event) { 72
73 window.console.log("error: " + event); 73 ws.onerror = function (event) {
74 } 74 window.console.log("error: " + event);
75 75 }
76 ws.onclose = function (evt) { 76
77 var websocket = evt.srcElement; 77 ws.onclose = function (evt) {
78 78 var websocket = evt.srcElement;
79 websocket.rdge_isConnected = false; 79
80 80 websocket.rdge_isConnected = false;
81 // send disconnect message 81
82 websocket.send("type=srv\nmsg=2\n"); 82 // send disconnect message
83 83 websocket.send("type=srv\nmsg=2\n");
84 // remove from connected sockets 84
85 websocket.connectedList[websocket.connectedIndex, 1]; 85 // remove from connected sockets
86 86 websocket.connectedList[websocket.connectedIndex, 1];
87 // re-open port for listening 87
88 //websocket.listenList[websocket.listenIndex] = new WebSocket(websocket.URL.toString()); 88 // re-open port for listening
89 89 //websocket.listenList[websocket.listenIndex] = new WebSocket(websocket.URL.toString());
90 //document.getElementById("socketConnection").innerHTML += "disconnected: " + websocket.URL +"</br>"; 90
91 }; 91 //document.getElementById("socketConnection").innerHTML += "disconnected: " + websocket.URL +"</br>";
92 92 };
93 return ws; 93
94}; 94 return ws;
95 95};
96// The DCHP range on Whitney 10.0.0.1 - 10.0.0.254 96
97 97// The DCHP range on Whitney 10.0.0.1 - 10.0.0.254
98// add the connection Pool's to this list for auto polling 98
99RDGE.ConnPoll = function() { 99// add the connection Pool's to this list for auto polling
100 var len = RDGE.globals.poolList.length; 100RDGE.ConnPoll = function() {
101 for (var i = 0; i < len; ++i) { 101 var len = RDGE.globals.poolList.length;
102 RDGE.globals.poolList[i].Poll(); 102 for (var i = 0; i < len; ++i) {
103 } 103 RDGE.globals.poolList[i].Poll();
104}; 104 }
105 105};
106/* 106
107* manages a connection 107/*
108* @param base: base url minus the last octet (ie "ws://192.168.1.") 108* manages a connection
109* @param startAddr: the last octect of the beginning address range (ie 10.0.0.x where x is the value passed in for startAddr) 109* @param base: base url minus the last octet (ie "ws://192.168.1.")
110* @param endAddr: the last octect of the end address range (ie 10.0.0.x where x is the value passed in for endAddr) 110* @param startAddr: the last octect of the beginning address range (ie 10.0.0.x where x is the value passed in for startAddr)
111* @param messageHandlerFunc: handle to onMessage function 111* @param endAddr: the last octect of the end address range (ie 10.0.0.x where x is the value passed in for endAddr)
112*/ 112* @param messageHandlerFunc: handle to onMessage function
113RDGE.ConnectionPool = funciton(base, startAddr, endAddr, messageHandlerFunc) 113*/
114{ 114RDGE.ConnectionPool = funciton(base, startAddr, endAddr, messageHandlerFunc)
115 this.start = startAddr; 115{
116 this.end = endAddr; 116 this.start = startAddr;
117 this.port = 38951; 117 this.end = endAddr;
118 this.messageHandler = messageHandlerFunc; 118 this.port = 38951;
119 119 this.messageHandler = messageHandlerFunc;
120 this.listenSockets = []; 120
121 this.connectedSockets = []; 121 this.listenSockets = [];
122 122 this.connectedSockets = [];
123 this.openHandler = null; 123
124 this.closeHandler = null; 124 this.openHandler = null;
125 125 this.closeHandler = null;
126 this.interval = null; 126
127 127 this.interval = null;
128 this.Init = function (openHandler, closeHandler) { 128
129 // empty out lists 129 this.Init = function (openHandler, closeHandler) {
130 this.listenSockets = []; 130 // empty out lists
131 this.connectedSockets = []; 131 this.listenSockets = [];
132 132 this.connectedSockets = [];
133 this.openHandler = openHandler; 133
134 this.closeHandler = closeHandler; 134 this.openHandler = openHandler;
135 135 this.closeHandler = closeHandler;
136 var len = this.end - this.start; 136
137 for (var i = 0; i < len; ++i) { 137 var len = this.end - th