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