ReconnectingWebSocket
我得到以下信息:
reconnecting_websocket_1.default is not a constructor
typescript代码为:
import ReconnectingWebSocket, { Options } from 'reconnecting-websocket';
export class RealtimeClient {
private reconnectingWebSocket: ReconnectingWebSocket
constructor(private url: string, private dispatch: IDispatcher) {}
public connect() {
const wsOptions: Options = {
minReconnectionDelay: 1000,
reconnectionDelayGrowFactor: 1.0,
connectionTimeout: 2000,
}
this.reconnectingWebSocket = new ReconnectingWebSocket(this.url, [], wsOptions)
this.reconnectingWebSocket.onmessage = this.onMessage
}
/* ... */
}
在运行时,chrome dev tools中生成的javascript显示
reconnecting_websocket_1
default
是未定义的,我认为这是失败的根本原因。
this.reconnectingWebSocket = new reconnecting_websocket_1.default(this.url, [], wsOptions);
this.reconnectingWebSocket.onmessage = this.onMessage;
注意:
-
我正在编译到ES5JavaScript(通过tsconfig.json
目标
-
我对重新连接websocket没有开发依赖性
"reconnecting-websocket": "^4.0.0-rc5"