JSteunou / webstomp-client

Stomp client over websocket for browsers
Apache License 2.0
299 stars 59 forks source link

Failed to execute 'send' on 'WebSocket': Still in CONNECTING state. #44

Closed tschuege closed 6 years ago

tschuege commented 7 years ago

Hello there!

I'm getting lots of error reports with: Chrome: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state. Safari complains with: InvalidStateError: The object is in an invalid state. and in Firefox it's: An attempt was made to use an object that is not, or is no longer, usable

Im not 100% sure if I'm doing everything right, so here is how i do it in TypeScript

connect(): void {
    this.stompClient = client(this.hostname, {
        debug: false,
        protocols: ['v10.stomp', 'v11.stomp', 'v12.stomp'],
        binary: false,
        heartbeat: {incoming: 25000, outgoing: 25000}
    });
    this.stompClient.connect(this.username, this.password, this.onConnect, this.onError, this.vhost);
}

private onConnect = () => {
    this.stompClient.subscribe('/exchange/sync/' + this.userUuid, this.onMessage);
}

private onError = (err) => {
    this.logger.warn(`Live sync change to: not available: error: ${JSON.stringify(err)}`);
}

I expect the WebSocket to be ready when the connect callback gets called (onConnect). Or am I misunderstanding something?

JSteunou commented 7 years ago

@mitkpl might help you on this one, I'm not a TS expert

Mamoru1234 commented 7 years ago

have you tried debug true option? Maybe there is some interesting message