blob: d510867e4787628108f7c2529b62e441f0141e3a [file] [log] [blame]
Sean Condona36f65c2019-05-20 08:21:41 +01001/*
2 * Copyright ${year}-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 */
16import { Component, OnInit } from '@angular/core';
17import {LogService, WebSocketService} from 'gui2-fw-lib';
18
19const SAMPLE_CUSTOM_DATA_REQ = 'sampleCustomDataRequest';
20const SAMPLE_CUSTOM_DATA_RESP = 'sampleCustomDataResponse';
21
22@Component({
23 selector: '${artifactId}-app-sample',
24 templateUrl: './${artifactId}.component.html',
25 styleUrls: ['./${artifactId}.component.css']
26})
27export class ${appNameCap}${appNameEnd}Component implements OnInit {
28 private handlers: string[] = [];
29 private openListener: any;
30
31 constructor(
32 protected log: LogService,
33 protected wss: WebSocketService
34 ) {
35 this.log.debug('${appNameCap}${appNameEnd}Component constructed');
36 }
37
38 ngOnInit() {
39 this.wss.bindHandlers(new Map<string, (data) => void>([
40 [SAMPLE_CUSTOM_DATA_RESP, (data) => {
Sean Condon27f06da2019-05-25 17:02:14 +010041 this.log.debug(SAMPLE_CUSTOM_DATA_RESP, data);
Sean Condona36f65c2019-05-20 08:21:41 +010042 }
43 ]
44 ]));
45
46 this.handlers.push(SAMPLE_CUSTOM_DATA_RESP);
47
48 // in case we fail over to a new server,
49 // listen for wsock-open events
50 this.openListener = this.wss.addOpenListener(() => this.wsOpen);
51 }
52
53 wsOpen(host: string, url: string) {
54 this.log.debug(SAMPLE_CUSTOM_DATA_RESP, ': WSopen - cluster node:', host, 'URL:', url);
55 // tell the server we are ready to receive topo events
56 this.wss.sendEvent(SAMPLE_CUSTOM_DATA_REQ, {});
57 }
58}