Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-present Open Networking Foundation |
| 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 | */ |
Sean Condon | a00bf38 | 2018-06-23 07:54:01 +0100 | [diff] [blame] | 16 | import { Injectable, Inject } from '@angular/core'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 17 | import { FnService } from '../util/fn.service'; |
| 18 | import { GlyphService } from '../svg/glyph.service'; |
| 19 | import { LogService } from '../../log.service'; |
| 20 | import { UrlFnService } from './urlfn.service'; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 21 | import { VeilComponent } from '../layer/veil/veil.component'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 22 | import { WSock } from './wsock.service'; |
| 23 | |
| 24 | /** |
| 25 | * Event Type structure for the WebSocketService |
| 26 | */ |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 27 | export interface EventType { |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 28 | event: string; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 29 | payload: Object; |
| 30 | } |
| 31 | |
| 32 | export interface Callback { |
| 33 | id: number; |
| 34 | error: string; |
| 35 | cb(host: string, url: string): void; |
| 36 | } |
| 37 | |
| 38 | interface ClusterNode { |
| 39 | id: string; |
| 40 | ip: string; |
| 41 | m_uiAttached: boolean; |
| 42 | } |
| 43 | |
| 44 | interface Bootstrap { |
| 45 | user: string; |
| 46 | clusterNodes: ClusterNode[]; |
| 47 | glyphs: any[]; // TODO: narrow this down to a known type |
| 48 | } |
| 49 | |
| 50 | interface ErrorData { |
| 51 | message: string; |
| 52 | } |
| 53 | |
| 54 | export interface WsOptions { |
| 55 | wsport: number; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /** |
| 59 | * ONOS GUI -- Remote -- Web Socket Service |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 60 | * |
| 61 | * To see debug messages add ?debug=txrx to the URL |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 62 | */ |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 63 | @Injectable({ |
| 64 | providedIn: 'root', |
| 65 | }) |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 66 | export class WebSocketService { |
| 67 | // internal state |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 68 | private webSockOpts: WsOptions; // web socket options |
| 69 | private ws: WebSocket = null; // web socket reference |
| 70 | private wsUp: boolean = false; // web socket is good to go |
| 71 | |
| 72 | // A map of event handler bindings - names and functions (that accept data and return void) |
| 73 | private handlers = new Map<string, (data: any) => void>([]); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 74 | private pendingEvents: EventType[] = []; // events TX'd while socket not up |
| 75 | private host: string; // web socket host |
| 76 | private url; // web socket URL |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 77 | private clusterNodes: ClusterNode[] = []; // ONOS instances data for failover |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 78 | private clusterIndex = -1; // the instance to which we are connected |
| 79 | private glyphs = []; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 80 | private connectRetries: number = 0; // limit our attempts at reconnecting |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 81 | |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 82 | // A map of registered Callbacks for websocket open() |
| 83 | private openListeners = new Map<number, Callback>([]); |
| 84 | private nextListenerId: number = 1; // internal ID for open listeners |
| 85 | private loggedInUser = null; // name of logged-in user |
| 86 | private lcd: any; // The loading component delegate |
| 87 | private vcd: any; // The veil component delegate |
| 88 | |
| 89 | /** |
| 90 | * built-in handler for the 'boostrap' event |
| 91 | */ |
| 92 | private bootstrap(data: Bootstrap) { |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 93 | this.loggedInUser = data.user; |
| 94 | |
| 95 | this.clusterNodes = data.clusterNodes; |
| 96 | this.clusterNodes.forEach((d, i) => { |
| 97 | if (d.m_uiAttached) { |
| 98 | this.clusterIndex = i; |
| 99 | this.log.info('Connected to cluster node ' + d.ip); |
| 100 | // TODO: add connect info to masthead somewhere |
| 101 | } |
| 102 | }); |
| 103 | this.glyphs = data.glyphs; |
| 104 | const glyphsMap = new Map<string, string>([]); |
| 105 | this.glyphs.forEach((d, i) => { |
| 106 | glyphsMap.set('_' + d.id, d.viewbox); |
| 107 | glyphsMap.set(d.id, d.path); |
| 108 | this.gs.registerGlyphs(glyphsMap); |
| 109 | }); |
| 110 | } |
| 111 | |
| 112 | private error(data: ErrorData) { |
| 113 | const m: string = data.message || 'error from server'; |
| 114 | this.log.error(m, data); |
| 115 | |
| 116 | // Unrecoverable error - throw up the veil... |
| 117 | if (this.vcd) { |
| 118 | this.vcd.show([ |
| 119 | 'Oops!', |
| 120 | 'Server reports error...', |
| 121 | m, |
| 122 | ]); |
| 123 | } |
| 124 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 125 | |
| 126 | constructor( |
| 127 | private fs: FnService, |
| 128 | private gs: GlyphService, |
| 129 | private log: LogService, |
| 130 | private ufs: UrlFnService, |
| 131 | private wsock: WSock, |
Sean Condon | a00bf38 | 2018-06-23 07:54:01 +0100 | [diff] [blame] | 132 | @Inject('Window') private window: Window |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 133 | ) { |
| 134 | this.log.debug(window.location.hostname); |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 135 | |
| 136 | // Bind the boot strap event by default |
| 137 | this.bindHandlers(new Map<string, (data) => void>([ |
| 138 | ['bootstrap', (data) => this.bootstrap(data)], |
| 139 | ['error', (data) => this.error(data)] |
| 140 | ])); |
| 141 | |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 142 | this.log.debug('WebSocketService constructed'); |
| 143 | } |
| 144 | |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 145 | |
| 146 | // ========================== |
| 147 | // === Web socket callbacks |
| 148 | |
| 149 | /** |
| 150 | * Called when WebSocket has just opened |
| 151 | * |
| 152 | * Lift the Veil if it is displayed |
| 153 | * If there are any events pending, send them |
| 154 | * Mark the WSS as up and inform any listeners for this open event |
| 155 | */ |
| 156 | handleOpen(): void { |
| 157 | this.log.info('Web socket open - ', this.url); |
| 158 | // Hide the veil |
| 159 | if (this.vcd) { |
| 160 | this.vcd.hide(); |
| 161 | } |
| 162 | |
| 163 | if (this.fs.debugOn('txrx')) { |
| 164 | this.log.debug('Sending ' + this.pendingEvents.length + ' pending event(s)...'); |
| 165 | } |
| 166 | this.pendingEvents.forEach((ev) => { |
| 167 | this.send(ev); |
| 168 | }); |
| 169 | this.pendingEvents = []; |
| 170 | |
| 171 | this.connectRetries = 0; |
| 172 | this.wsUp = true; |
| 173 | this.informListeners(this.host, this.url); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Function called when WebSocket send a message |
| 178 | */ |
| 179 | handleMessage(msgEvent: MessageEvent): void { |
| 180 | let ev: EventType; |
| 181 | let h; |
| 182 | try { |
| 183 | ev = JSON.parse(msgEvent.data); |
| 184 | } catch (e) { |
| 185 | this.log.error('Message.data is not valid JSON', msgEvent.data, e); |
| 186 | return null; |
| 187 | } |
| 188 | if (this.fs.debugOn('txrx')) { |
| 189 | this.log.debug(' << *Rx* ', ev.event, ev.payload); |
| 190 | } |
| 191 | h = this.handlers.get(ev.event); |
| 192 | if (h) { |
| 193 | try { |
| 194 | h(ev.payload); |
| 195 | } catch (e) { |
| 196 | this.log.error('Problem handling event:', ev, e); |
| 197 | return null; |
| 198 | } |
| 199 | } else { |
| 200 | this.log.warn('Unhandled event:', ev); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Called by the WebSocket if it is closed from the server end |
| 206 | * |
| 207 | * If the loading component is shown, call stop() on it |
| 208 | * Try to find another node in the cluster to connect to |
| 209 | * If this is not possible then show the Veil Component |
| 210 | */ |
| 211 | handleClose(): void { |
| 212 | this.log.warn('Web socket closed'); |
| 213 | if (this.lcd) { |
| 214 | this.lcd.stop(); |
| 215 | } |
| 216 | this.wsUp = false; |
| 217 | let gsucc; |
| 218 | |
| 219 | if (gsucc = this.findGuiSuccessor()) { |
| 220 | this.url = this.createWebSocket(this.webSockOpts, gsucc); |
| 221 | } else { |
| 222 | // If no controllers left to contact, show the Veil... |
| 223 | if (this.vcd) { |
| 224 | this.vcd.show([ |
| 225 | 'Oops!', // TODO: Localize this |
| 226 | 'Web-socket connection to server closed...', |
| 227 | 'Try refreshing the page.', |
| 228 | ]); |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // ============================== |
| 234 | // === Private Helper Functions |
| 235 | |
| 236 | /** |
| 237 | * Find the next node in the ONOS cluster. |
| 238 | * |
| 239 | * This is used if the WebSocket connection closes because a |
| 240 | * node in the cluster ges down - fail over should be automatic |
| 241 | */ |
| 242 | findGuiSuccessor(): string { |
| 243 | const ncn = this.clusterNodes.length; |
| 244 | let ip: string; |
| 245 | let node; |
| 246 | |
| 247 | while (this.connectRetries < ncn && !ip) { |
| 248 | this.connectRetries++; |
| 249 | this.clusterIndex = (this.clusterIndex + 1) % ncn; |
| 250 | node = this.clusterNodes[this.clusterIndex]; |
| 251 | ip = node && node.ip; |
| 252 | } |
| 253 | |
| 254 | return ip; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * When the WebSocket is opened, inform any listeners that registered |
| 259 | * for that event |
| 260 | */ |
| 261 | informListeners(host: string, url: string): void { |
| 262 | for (const [key, cb] of this.openListeners.entries()) { |
| 263 | cb.cb(host, url); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | send(ev: EventType): void { |
| 268 | if (this.fs.debugOn('txrx')) { |
| 269 | this.log.debug(' *Tx* >> ', ev.event, ev.payload); |
| 270 | } |
| 271 | this.ws.send(JSON.stringify(ev)); |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Check if there are no WSS event handlers left |
| 276 | */ |
| 277 | noHandlersWarn(handlers: Map<string, Object>, caller: string): boolean { |
| 278 | if (!handlers || handlers.size === 0) { |
| 279 | this.log.warn('WSS.' + caller + '(): no event handlers'); |
| 280 | return true; |
| 281 | } |
| 282 | return false; |
| 283 | } |
| 284 | |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 285 | /* =================== |
| 286 | * === API Functions |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 287 | */ |
| 288 | |
| 289 | /** |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 290 | * Required for unit tests to set to known state |
| 291 | */ |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 292 | resetState(): void { |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 293 | this.webSockOpts = undefined; |
| 294 | this.ws = null; |
| 295 | this.wsUp = false; |
| 296 | this.host = undefined; |
| 297 | this.url = undefined; |
| 298 | this.pendingEvents = []; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 299 | this.handlers.clear(); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 300 | this.clusterNodes = []; |
| 301 | this.clusterIndex = -1; |
| 302 | this.glyphs = []; |
| 303 | this.connectRetries = 0; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 304 | this.openListeners.clear(); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 305 | this.nextListenerId = 1; |
| 306 | |
| 307 | } |
| 308 | |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 309 | /* |
| 310 | * Currently supported opts: |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 311 | * wsport: web socket port (other than default 8181) |
| 312 | * host: if defined, is the host address to use |
| 313 | */ |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 314 | createWebSocket(opts?: WsOptions, host?: string) { |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 315 | this.webSockOpts = opts; // preserved for future calls |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 316 | this.host = host === undefined ? this.window.location.host : host; |
| 317 | this.url = this.ufs.wsUrl('core', opts === undefined ? '' : opts['wsport'].toString(), host); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 318 | |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 319 | this.log.debug('Attempting to open websocket to: ' + this.url); |
| 320 | this.ws = this.wsock.newWebSocket(this.url); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 321 | if (this.ws) { |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 322 | // fat arrow => syntax means that the 'this' context passed will |
| 323 | // be of WebSocketService, not the WebSocket |
| 324 | this.ws.onopen = (() => this.handleOpen()); |
| 325 | this.ws.onmessage = ((msgEvent) => this.handleMessage(msgEvent)); |
| 326 | this.ws.onclose = (() => this.handleClose()); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 327 | |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 328 | this.sendEvent('authentication token', { token: 'testAuth' }); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 329 | } |
| 330 | // Note: Wsock logs an error if the new WebSocket call fails |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 331 | return this.url; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 332 | } |
| 333 | |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 334 | /** |
| 335 | * Tell the WebSocket to close - this should call the handleClose() method |
| 336 | */ |
| 337 | closeWebSocket() { |
| 338 | this.ws.close(); |
| 339 | } |
| 340 | |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 341 | |
| 342 | /** |
| 343 | * Binds the message handlers to their message type (event type) as |
| 344 | * specified in the given map. Note that keys are the event IDs; values |
| 345 | * are either: |
| 346 | * * the event handler function, or |
| 347 | * * an API object which has an event handler for the key |
| 348 | */ |
| 349 | bindHandlers(handlerMap: Map<string, (data) => void>): void { |
| 350 | const dups: string[] = []; |
| 351 | |
| 352 | if (this.noHandlersWarn(handlerMap, 'bindHandlers')) { |
| 353 | return null; |
| 354 | } |
| 355 | for (const [eventId, api] of handlerMap) { |
| 356 | this.log.debug('Adding handler for ', eventId); |
| 357 | const fn = this.fs.isF(api) || this.fs.isF(api[eventId]); |
| 358 | if (!fn) { |
| 359 | this.log.warn(eventId + ' handler not a function'); |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | if (this.handlers.get(eventId)) { |
| 364 | dups.push(eventId); |
| 365 | } else { |
| 366 | this.handlers.set(eventId, fn); |
| 367 | } |
| 368 | } |
| 369 | if (dups.length) { |
| 370 | this.log.warn('duplicate bindings ignored:', dups); |
| 371 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 372 | } |
| 373 | |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 374 | /** |
| 375 | * Unbinds the specified message handlers. |
| 376 | * Expected that the same map will be used, but we only care about keys |
| 377 | */ |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 378 | unbindHandlers(handlerIds: string[]): void { |
| 379 | if ( handlerIds.length === 0 ) { |
| 380 | this.log.warn('WSS.unbindHandlers(): no event handlers'); |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 381 | return null; |
| 382 | } |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 383 | for (const eventId of handlerIds) { |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 384 | this.handlers.delete(eventId); |
| 385 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 388 | isHandling(handlerId: string): boolean { |
| 389 | return this.handlers.get(handlerId) !== undefined; |
| 390 | } |
| 391 | |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 392 | /** |
| 393 | * Add a listener function for listening for WebSocket opening. |
| 394 | * The function must give a host and url and return void |
| 395 | */ |
| 396 | addOpenListener(callback: (host: string, url: string) => void ): Callback { |
| 397 | const id: number = this.nextListenerId++; |
| 398 | const cb = this.fs.isF(callback); |
| 399 | const o: Callback = <Callback>{ id: id, cb: cb }; |
| 400 | |
| 401 | if (cb) { |
| 402 | this.openListeners.set(id, o); |
| 403 | } else { |
| 404 | this.log.error('WSS.addOpenListener(): callback not a function'); |
| 405 | o.error = 'No callback defined'; |
| 406 | } |
| 407 | return o; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 408 | } |
| 409 | |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 410 | /** |
| 411 | * Remove a listener of WebSocket opening |
| 412 | */ |
| 413 | removeOpenListener(lsnr: Callback): void { |
| 414 | const id = this.fs.isO(lsnr) && lsnr.id; |
| 415 | let o; |
| 416 | |
| 417 | if (!id) { |
| 418 | this.log.warn('WSS.removeOpenListener(): invalid listener', lsnr); |
| 419 | return null; |
| 420 | } |
| 421 | o = this.openListeners[id]; |
| 422 | |
| 423 | if (o) { |
| 424 | this.openListeners.delete(id); |
| 425 | } |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * Formulates an event message and sends it via the web-socket. |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 430 | * If the websocket is not up yet, we store it in a pending list. |
| 431 | */ |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 432 | sendEvent(evType: string, payload: Object ): void { |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 433 | const ev = <EventType> { |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 434 | event: evType, |
| 435 | payload: payload |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 436 | }; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 437 | |
| 438 | if (this.wsUp) { |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 439 | this.send(ev); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 440 | } else { |
| 441 | this.pendingEvents.push(ev); |
| 442 | } |
| 443 | } |
| 444 | |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 445 | /** |
| 446 | * Binds the veil service as a delegate. |
| 447 | */ |
| 448 | setVeilDelegate(vd: VeilComponent): void { |
| 449 | this.vcd = vd; |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * Binds the loading service as a delegate |
| 454 | */ |
| 455 | setLoadingDelegate(ld: any): void { |
| 456 | // TODO - Investigate changing Loading Service to LoadingComponent |
| 457 | this.log.debug('Loading delegate set', ld); |
| 458 | this.lcd = ld; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 459 | } |
| 460 | |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 461 | isConnected(): boolean { |
| 462 | return this.wsUp; |
| 463 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 464 | } |