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