diff options
author | John Mayhew | 2012-07-09 17:28:24 -0700 |
---|---|---|
committer | John Mayhew | 2012-07-09 17:28:24 -0700 |
commit | 770bcb52422742ff741a88a75ecefbeb90bc9247 (patch) | |
tree | 64cb3e09a8daeb340261dd7f3869c73f7b90b643 /js/helper-classes/RDGE/src/core/script/sockets.js | |
parent | 8c5ecaf90062f9e030386f338bdc19fd62b826c8 (diff) | |
parent | 2b2b5fbb4b6a786daa4e9d4ee9eba9ac78924842 (diff) | |
download | ninja-770bcb52422742ff741a88a75ecefbeb90bc9247.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal
Conflicts:
manifest.json
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/sockets.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/sockets.js | 363 |
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> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | 4 | |
5 | 5 | Redistribution and use in source and binary forms, with or without | |
6 | Redistribution and use in source and binary forms, with or without | 6 | modification, are permitted provided that the following conditions are met: |
7 | modification, 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. | |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 | |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | </copyright> */ | 29 | POSSIBILITY OF SUCH DAMAGE. |
30 | 30 | </copyright> */ | |
31 | // RDGE namespaces | 31 | |
32 | var RDGE = RDGE || {}; | 32 | // RDGE namespaces |
33 | 33 | var RDGE = RDGE || {}; | |
34 | /* | 34 | |
35 | * Simple socket connection discovery and management | 35 | /* |
36 | */ | 36 | * Simple socket connection discovery and management |
37 | 37 | */ | |
38 | RDGE.CreateSocket = function (url, listenList, connectedList, messageHandler, socketID, openHandler, closeHandler) { | 38 | |
39 | var ws = new WebSocket(url); | 39 | RDGE.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 | |
99 | RDGE.ConnPoll = function() { | 99 | // add the connection Pool's to this list for auto polling |
100 | var len = RDGE.globals.poolList.length; | 100 | RDGE.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 |
113 | RDGE.ConnectionPool = funciton(base, startAddr, endAddr, messageHandlerFunc) | 113 | */ |
114 | { | 114 | RDGE.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 | |