After dabbling in Angular2 and Typescript, I decided to challenge myself by creating an application using plain javascript with the CometD library. The goal of this app was to retrieve data from a CometD channel and present it to the user in some way.
So, I went ahead and crafted a simple component with a link to the CometD js library.
import { Component } from '@angular/core';
import * as cometd from '../cometd/cometd';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
cometD: any;
constructor() {
console.log("Starting cometD service ...");
this.cometD = new cometd.CometD();
this.cometD.configure({ url: '/services/cometd', logLevel: 'debug', requestHeaders: { "userID": 555 } });
this.title = "CometD demo";
this.cometD.handshake();
this.subscribe()
}
subscribe() {
this.cometD.subscribe('/mychannel', (message)=> this.mychannelHandler(message));
}
mychannelHandler(message) {
console.log("MESSAGE FROM SERVER RECIEVED: " + message + ", data: " + message.data);
this.title = message.data;
}
}
Although I see debug messages in the console from CometD confirming the connection, subscription to the channel, and incoming data, something's not working as expected.
The mychannelHandler is not being triggered. The message isn't logged in the console, and the title remains unchanged. What could I be overlooking?
Any insightful answers would be greatly appreciated.