I am trying to implement a Stomp Websocket client using stomp.js.
I use angular2 with typescript and webpack and am really new to all of these technologies. My angular2 project was built on this seed:
https://github.com/angular/angular2-seed
As a guide for implementing the stomp.js client, I used https://github.com/sjmf/ng2-stompjs-demo
The error I am currently getting is the following:
?d41d:73 EXCEPTION: TypeError: Cannot read property 'client' of undefined in [null]
The error in this method:
public configure() : void {
if (this.state.getValue() != STOMPState.CLOSED) {
throw Error("Already running!");
}
let scheme : string = 'ws';
if( AppSettings.IS_SSL ) {
scheme = 'wss';
}
this.client = Stomp.client(
scheme + '://'
+ AppSettings.HOST + ':'
+ AppSettings.WEBSOCK_PORT
+ AppSettings.WEBSOCK_ENDPOINT
);
this.client.heartbeat.incoming = AppSettings.HEARTBEAT;
}
So Stompit seems undefined.
I import:
import {Stomp} from "stompjs";
I installed stomp.js with npm, like this
npm install
And my stompjs module looks like this:
declare module "stompjs" {
export interface Client {
heartbeat: any;
debug(...args: string[]);
connect(...args: any[]);
disconnect(disconnectCallback: () => any, headers?: any);
send(destination: string, headers?:any, body?: string);
subscribe(destination: string, callback?: (message: Message) => any, body?: string);
unsubscribe();
begin(transaction: string);
commit(transaction: string);
abort(transaction: string);
ack(messageID: string, subscription: string, headers?: any);
nack(messageID: string, subscription: string, headers?: any);
}
export interface Message {
command: string;
headers: any;
body: string;
ack(headers?: any);
nack(headers?: any);
}
export interface Frame {
constructor(command: string, headers?: any, body?: string);
toString(): string;
sizeOfUTF8(s: string);
unmarshall(datas: any);
marshall(command: string, headers?, body?);
}
export interface Stomp {
client: Client;
Frame: Frame;
over(ws: WebSocket);
}
}
, , , , github.
!