Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [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 | import { Injectable } from '@angular/core'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 17 | import { LogService } from '../log.service'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 18 | |
| 19 | /** |
| 20 | * ONOS GUI -- Remote -- Web Socket Wrapper Service |
| 21 | * |
| 22 | * This service provided specifically so that it can be mocked in unit tests. |
| 23 | */ |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 24 | @Injectable({ |
| 25 | providedIn: 'root', |
| 26 | }) |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 27 | export class WSock { |
| 28 | |
| 29 | constructor( |
| 30 | private log: LogService, |
| 31 | ) { |
| 32 | this.log.debug('WSockService constructed'); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | newWebSocket(url) { |
| 37 | let ws = null; |
| 38 | try { |
| 39 | ws = new WebSocket(url); |
| 40 | } catch (e) { |
| 41 | this.log.error('Unable to create web socket:', e); |
| 42 | } |
| 43 | return ws; |
| 44 | } |
| 45 | |
| 46 | } |