blob: 40e0b2a190efaca085a7e5c7090bc59e8135184d [file] [log] [blame]
Sean Condon83fc39f2018-04-19 18:56:13 +01001/*
Sean Condon5ca00262018-09-06 17:55:25 +01002 * Copyright 2018-present Open Networking Foundation
Sean Condon83fc39f2018-04-19 18:56:13 +01003 *
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 */
16import { Injectable } from '@angular/core';
Sean Condon5ca00262018-09-06 17:55:25 +010017import { LogService } from '../log.service';
Sean Condon83fc39f2018-04-19 18:56:13 +010018
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 Condonfd6d11b2018-06-02 20:29:49 +010024@Injectable({
25 providedIn: 'root',
26})
Sean Condon83fc39f2018-04-19 18:56:13 +010027export 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}