试图在angular2中使用stomp.js

我正在试图使用stomp.js实现一个Stomp Websocket客户端。

我正在使用typescript和webpack的angular2,并且对于所有这些技术都是新的。 我的angular2项目是build立在这个种子: https : //github.com/angular/angular2-seed

作为实现stomp.js客户端的指南,我使用了https://github.com/sjmf/ng2-stompjs-demo

我目前收到的错误如下:

?d41d:73 EXCEPTION: TypeError: Cannot read property 'client' of undefined in [null] 

错误发生在这个方法中:

  public configure() : void { // Check for errors 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; } 

所以Stomp似乎是不确定的。

我正在导入:

 import {Stomp} from "stompjs"; 

我已经用npm安装了stomp.js

 npm install --save stompjs 

我的stompjs模块看起来像这样:

 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演示了。

提前感谢任何帮助!

       

网上收集的解决方案 "试图在angular2中使用stomp.js"