Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | ONOS GUI -- Remote -- Web Socket Service |
| 19 | */ |
| 20 | (function () { |
| 21 | 'use strict'; |
| 22 | |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 23 | // injected refs |
Simon Hunt | ab34ecb | 2015-12-11 13:14:48 -0800 | [diff] [blame] | 24 | var $log, $loc, fs, ufs, wsock, vs, ls; |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 25 | |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 26 | // internal state |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 27 | var webSockOpts, // web socket options |
| 28 | ws = null, // web socket reference |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 29 | wsUp = false, // web socket is good to go |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 30 | handlers = {}, // event handler bindings |
| 31 | pendingEvents = [], // events TX'd while socket not up |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 32 | host, // web socket host |
Thomas Vachuska | b6acc7b | 2015-03-11 09:11:21 -0700 | [diff] [blame] | 33 | url, // web socket URL |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 34 | clusterNodes = [], // ONOS instances data for failover |
| 35 | clusterIndex = -1, // the instance to which we are connected |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 36 | connectRetries = 0, // limit our attempts at reconnecting |
| 37 | openListeners = {}, // registered listeners for websocket open() |
Simon Hunt | 7715e89 | 2016-04-12 19:55:32 -0700 | [diff] [blame] | 38 | nextListenerId = 1, // internal ID for open listeners |
| 39 | loggedInUser = null; // name of logged-in user |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 40 | |
| 41 | // ======================= |
| 42 | // === Bootstrap Handler |
Simon Hunt | acf410b | 2015-01-23 10:05:48 -0800 | [diff] [blame] | 43 | |
Thomas Vachuska | b6acc7b | 2015-03-11 09:11:21 -0700 | [diff] [blame] | 44 | var builtinHandlers = { |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 45 | bootstrap: function (data) { |
Simon Hunt | 7715e89 | 2016-04-12 19:55:32 -0700 | [diff] [blame] | 46 | $log.debug('bootstrap data', data); |
| 47 | loggedInUser = data.user; |
Thomas Vachuska | 20084b7 | 2015-03-11 13:46:50 -0700 | [diff] [blame] | 48 | clusterNodes = data.clusterNodes; |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 49 | clusterNodes.forEach(function (d, i) { |
| 50 | if (d.uiAttached) { |
| 51 | clusterIndex = i; |
Thomas Vachuska | 20084b7 | 2015-03-11 13:46:50 -0700 | [diff] [blame] | 52 | $log.info('Connected to cluster node ' + d.ip); |
| 53 | // TODO: add connect info to masthead somewhere |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 54 | } |
| 55 | }); |
| 56 | } |
| 57 | }; |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 58 | |
Steven Burrows | 530cf46 | 2016-04-12 16:04:37 +0100 | [diff] [blame] | 59 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 60 | // ========================== |
| 61 | // === Web socket callbacks |
| 62 | |
| 63 | function handleOpen() { |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 64 | $log.info('Web socket open - ', url); |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 65 | vs && vs.hide(); |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 66 | |
Simon Hunt | 4deb0e8 | 2015-06-10 16:18:25 -0700 | [diff] [blame] | 67 | if (fs.debugOn('txrx')) { |
| 68 | $log.debug('Sending ' + pendingEvents.length + ' pending event(s)...'); |
| 69 | } |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 70 | pendingEvents.forEach(function (ev) { |
| 71 | _send(ev); |
| 72 | }); |
| 73 | pendingEvents = []; |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 74 | |
| 75 | connectRetries = 0; |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 76 | wsUp = true; |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 77 | informListeners(host, url); |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | // Handles the specified (incoming) message using handler bindings. |
| 81 | function handleMessage(msgEvent) { |
| 82 | var ev, h; |
| 83 | |
| 84 | try { |
| 85 | ev = JSON.parse(msgEvent.data); |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 86 | } catch (e) { |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 87 | $log.error('Message.data is not valid JSON', msgEvent.data, e); |
Bri Prebilic Cole | 6ed04eb | 2015-04-27 16:26:03 -0700 | [diff] [blame] | 88 | return null; |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 89 | } |
Simon Hunt | 4deb0e8 | 2015-06-10 16:18:25 -0700 | [diff] [blame] | 90 | if (fs.debugOn('txrx')) { |
| 91 | $log.debug(' << *Rx* ', ev.event, ev.payload); |
| 92 | } |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 93 | |
| 94 | if (h = handlers[ev.event]) { |
| 95 | try { |
| 96 | h(ev.payload); |
| 97 | } catch (e) { |
| 98 | $log.error('Problem handling event:', ev, e); |
Bri Prebilic Cole | 6ed04eb | 2015-04-27 16:26:03 -0700 | [diff] [blame] | 99 | return null; |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 100 | } |
| 101 | } else { |
| 102 | $log.warn('Unhandled event:', ev); |
| 103 | } |
| 104 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | function handleClose() { |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 108 | var gsucc; |
| 109 | |
Simon Hunt | 8a0429a | 2017-01-06 16:52:47 -0800 | [diff] [blame] | 110 | $log.warn('Web socket closed'); |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 111 | ls && ls.stop(); |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 112 | wsUp = false; |
| 113 | |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 114 | if (gsucc = findGuiSuccessor()) { |
| 115 | createWebSocket(webSockOpts, gsucc); |
| 116 | } else { |
| 117 | // If no controllers left to contact, show the Veil... |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 118 | vs && vs.show([ |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 119 | 'Oops!', |
| 120 | 'Web-socket connection to server closed...', |
| 121 | 'Try refreshing the page.' |
| 122 | ]); |
| 123 | } |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | |
| 127 | // ============================== |
| 128 | // === Private Helper Functions |
| 129 | |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 130 | function findGuiSuccessor() { |
| 131 | var ncn = clusterNodes.length, |
Bri Prebilic Cole | 6ed04eb | 2015-04-27 16:26:03 -0700 | [diff] [blame] | 132 | ip, node; |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 133 | |
| 134 | while (connectRetries < ncn && !ip) { |
| 135 | connectRetries++; |
| 136 | clusterIndex = (clusterIndex + 1) % ncn; |
| 137 | node = clusterNodes[clusterIndex]; |
| 138 | ip = node && node.ip; |
| 139 | } |
| 140 | |
| 141 | return ip; |
| 142 | } |
| 143 | |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 144 | function informListeners(host, url) { |
Bri Prebilic Cole | 6ed04eb | 2015-04-27 16:26:03 -0700 | [diff] [blame] | 145 | angular.forEach(openListeners, function (lsnr) { |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 146 | lsnr.cb(host, url); |
| 147 | }); |
| 148 | } |
| 149 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 150 | function _send(ev) { |
Simon Hunt | 4deb0e8 | 2015-06-10 16:18:25 -0700 | [diff] [blame] | 151 | if (fs.debugOn('txrx')) { |
| 152 | $log.debug(' *Tx* >> ', ev.event, ev.payload); |
| 153 | } |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 154 | ws.send(JSON.stringify(ev)); |
| 155 | } |
| 156 | |
Bri Prebilic Cole | 6ed04eb | 2015-04-27 16:26:03 -0700 | [diff] [blame] | 157 | function noHandlersWarn(handlers, caller) { |
| 158 | if (!handlers || fs.isEmptyObject(handlers)) { |
| 159 | $log.warn('WSS.' + caller + '(): no event handlers'); |
| 160 | return true; |
| 161 | } |
| 162 | return false; |
| 163 | } |
| 164 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 165 | // =================== |
| 166 | // === API Functions |
| 167 | |
| 168 | // Required for unit tests to set to known state |
Bri Prebilic Cole | 6ed04eb | 2015-04-27 16:26:03 -0700 | [diff] [blame] | 169 | function resetState() { |
| 170 | webSockOpts = undefined; |
| 171 | ws = null; |
| 172 | wsUp = false; |
| 173 | host = undefined; |
| 174 | url = undefined; |
| 175 | pendingEvents = []; |
| 176 | handlers = {}; |
Bri Prebilic Cole | 6ed04eb | 2015-04-27 16:26:03 -0700 | [diff] [blame] | 177 | clusterNodes = []; |
| 178 | clusterIndex = -1; |
| 179 | connectRetries = 0; |
| 180 | openListeners = {}; |
| 181 | nextListenerId = 1; |
| 182 | } |
Simon Hunt | 970e7fd | 2015-01-22 17:46:28 -0800 | [diff] [blame] | 183 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 184 | // Currently supported opts: |
| 185 | // wsport: web socket port (other than default 8181) |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 186 | // host: if defined, is the host address to use |
| 187 | function createWebSocket(opts, _host_) { |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 188 | var wsport = (opts && opts.wsport) || null; |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 189 | |
Simon Hunt | 8b6d2d4 | 2015-03-11 13:04:52 -0700 | [diff] [blame] | 190 | webSockOpts = opts; // preserved for future calls |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 191 | |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 192 | host = _host_ || $loc.host(); |
| 193 | url = ufs.wsUrl('core', wsport, _host_); |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 194 | |
| 195 | $log.debug('Attempting to open websocket to: ' + url); |
| 196 | ws = wsock.newWebSocket(url); |
| 197 | if (ws) { |
| 198 | ws.onopen = handleOpen; |
| 199 | ws.onmessage = handleMessage; |
| 200 | ws.onclose = handleClose; |
| 201 | } |
| 202 | // Note: Wsock logs an error if the new WebSocket call fails |
Simon Hunt | 2d16fc8 | 2015-03-10 20:19:52 -0700 | [diff] [blame] | 203 | return url; |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 206 | // Binds the message handlers to their message type (event type) as |
| 207 | // specified in the given map. Note that keys are the event IDs; values |
| 208 | // are either: |
| 209 | // * the event handler function, or |
| 210 | // * an API object which has an event handler for the key |
| 211 | // |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 212 | function bindHandlers(handlerMap) { |
Bri Prebilic Cole | 6ed04eb | 2015-04-27 16:26:03 -0700 | [diff] [blame] | 213 | var m, |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 214 | dups = []; |
Simon Hunt | 970e7fd | 2015-01-22 17:46:28 -0800 | [diff] [blame] | 215 | |
Bri Prebilic Cole | 6ed04eb | 2015-04-27 16:26:03 -0700 | [diff] [blame] | 216 | if (noHandlersWarn(handlerMap, 'bindHandlers')) { |
| 217 | return null; |
| 218 | } |
| 219 | m = d3.map(handlerMap); |
| 220 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 221 | m.forEach(function (eventId, api) { |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 222 | var fn = fs.isF(api) || fs.isF(api[eventId]); |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 223 | if (!fn) { |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 224 | $log.warn(eventId + ' handler not a function'); |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 225 | return; |
Simon Hunt | 970e7fd | 2015-01-22 17:46:28 -0800 | [diff] [blame] | 226 | } |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 227 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 228 | if (handlers[eventId]) { |
| 229 | dups.push(eventId); |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 230 | } else { |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 231 | handlers[eventId] = fn; |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 232 | } |
| 233 | }); |
| 234 | if (dups.length) { |
| 235 | $log.warn('duplicate bindings ignored:', dups); |
| 236 | } |
Simon Hunt | 970e7fd | 2015-01-22 17:46:28 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 239 | // Unbinds the specified message handlers. |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 240 | // Expected that the same map will be used, but we only care about keys |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 241 | function unbindHandlers(handlerMap) { |
Bri Prebilic Cole | 6ed04eb | 2015-04-27 16:26:03 -0700 | [diff] [blame] | 242 | var m; |
| 243 | |
| 244 | if (noHandlersWarn(handlerMap, 'unbindHandlers')) { |
| 245 | return null; |
| 246 | } |
| 247 | m = d3.map(handlerMap); |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 248 | |
| 249 | m.forEach(function (eventId) { |
| 250 | delete handlers[eventId]; |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 251 | }); |
| 252 | } |
Simon Hunt | acf410b | 2015-01-23 10:05:48 -0800 | [diff] [blame] | 253 | |
Simon Hunt | d5b9673 | 2016-07-08 13:22:27 -0700 | [diff] [blame] | 254 | // TODO: simplify listener handling (see theme.js for sample code) |
| 255 | |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 256 | function addOpenListener(callback) { |
| 257 | var id = nextListenerId++, |
| 258 | cb = fs.isF(callback), |
| 259 | o = { id: id, cb: cb }; |
| 260 | |
| 261 | if (cb) { |
| 262 | openListeners[id] = o; |
| 263 | } else { |
| 264 | $log.error('WSS.addOpenListener(): callback not a function'); |
| 265 | o.error = 'No callback defined'; |
| 266 | } |
| 267 | return o; |
| 268 | } |
| 269 | |
| 270 | function removeOpenListener(lsnr) { |
Bri Prebilic Cole | 6ed04eb | 2015-04-27 16:26:03 -0700 | [diff] [blame] | 271 | var id = fs.isO(lsnr) && lsnr.id, |
| 272 | o; |
| 273 | if (!id) { |
| 274 | $log.warn('WSS.removeOpenListener(): invalid listener', lsnr); |
| 275 | return null; |
| 276 | } |
| 277 | o = openListeners[id]; |
| 278 | |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 279 | if (o) { |
| 280 | delete openListeners[id]; |
| 281 | } |
| 282 | } |
| 283 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 284 | // Formulates an event message and sends it via the web-socket. |
| 285 | // If the websocket is not up yet, we store it in a pending list. |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 286 | function sendEvent(evType, payload) { |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 287 | var ev = { |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 288 | event: evType, |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 289 | payload: payload || {} |
| 290 | }; |
| 291 | |
| 292 | if (wsUp) { |
| 293 | _send(ev); |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 294 | } else { |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 295 | pendingEvents.push(ev); |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 299 | // Binds the veil service as a delegate |
| 300 | function setVeilDelegate(vd) { |
| 301 | vs = vd; |
| 302 | } |
| 303 | |
| 304 | // Binds the loading service as a delegate |
| 305 | function setLoadingDelegate(ld) { |
| 306 | ls = ld; |
| 307 | } |
| 308 | |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 309 | |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 310 | // ============================ |
| 311 | // ===== Definition of module |
Simon Hunt | 584122a | 2015-01-21 15:32:40 -0800 | [diff] [blame] | 312 | angular.module('onosRemote') |
Simon Hunt | bb920fd | 2015-01-22 17:06:32 -0800 | [diff] [blame] | 313 | .factory('WebSocketService', |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 314 | ['$log', '$location', 'FnService', 'UrlFnService', 'WSock', |
Simon Hunt | bb920fd | 2015-01-22 17:06:32 -0800 | [diff] [blame] | 315 | |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 316 | function (_$log_, _$loc_, _fs_, _ufs_, _wsock_) { |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 317 | $log = _$log_; |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 318 | $loc = _$loc_; |
| 319 | fs = _fs_; |
| 320 | ufs = _ufs_; |
| 321 | wsock = _wsock_; |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 322 | |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 323 | bindHandlers(builtinHandlers); |
Thomas Vachuska | b6acc7b | 2015-03-11 09:11:21 -0700 | [diff] [blame] | 324 | |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 325 | return { |
Bri Prebilic Cole | 6ed04eb | 2015-04-27 16:26:03 -0700 | [diff] [blame] | 326 | resetState: resetState, |
Thomas Vachuska | 329af53 | 2015-03-10 02:08:33 -0700 | [diff] [blame] | 327 | createWebSocket: createWebSocket, |
| 328 | bindHandlers: bindHandlers, |
| 329 | unbindHandlers: unbindHandlers, |
Simon Hunt | 3b9ad04d | 2015-03-11 15:26:02 -0700 | [diff] [blame] | 330 | addOpenListener: addOpenListener, |
| 331 | removeOpenListener: removeOpenListener, |
Simon Hunt | 412adc8 | 2015-12-11 15:56:20 -0800 | [diff] [blame] | 332 | sendEvent: sendEvent, |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 333 | isConnected: function () { return wsUp; }, |
Simon Hunt | 7715e89 | 2016-04-12 19:55:32 -0700 | [diff] [blame] | 334 | loggedInUser: function () { return loggedInUser || '(no-one)'; }, |
Thomas Vachuska | 0af2691 | 2016-03-21 21:37:30 -0700 | [diff] [blame] | 335 | |
| 336 | _setVeilDelegate: setVeilDelegate, |
| 337 | _setLoadingDelegate: setLoadingDelegate |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 338 | }; |
Simon Hunt | 20207df | 2015-03-10 18:30:14 -0700 | [diff] [blame] | 339 | } |
| 340 | ]); |
Simon Hunt | 1e4a001 | 2015-01-21 11:36:08 -0800 | [diff] [blame] | 341 | |
| 342 | }()); |