signalr-no-jquery icon indicating copy to clipboard operation
signalr-no-jquery copied to clipboard

Adding proxy event listeners after connection has been opened

Open BartVanBeurden opened this issue 7 years ago • 1 comments

Description

Event listeners are not triggered when added after a connection was opened.
I'm not sure if this is intended behaviour but I don't think it's documented anywhere, and it's also confusing why it doesn't work.

Reproduction

import { hubConnection } from 'signalr-no-jquery';

const connection = hubConnection("signalr.url");
const proxy = connection.createHubProxy("testHub");

proxy.on("test1", data => console.log("test1:", data));

connection.start().done(() => {
    proxy.on("test2", data => console.log("test2:", data));
    proxy.invoke("remoteCall", "message").done(data => console.log("returned:", data));
});

Output:

test1: message
returned: message

remoteCall is invoked, and sends two events (test1, test2) before returning the data. The client never handles test2 (which was added after the connection started).

In case this may be relevant, The SignalR transport mode is "serverSentEvents". I have not tested "websockets" or any other transport mode.

BartVanBeurden avatar Aug 28 '17 08:08 BartVanBeurden

same thing here

rolivares avatar Apr 30 '18 13:04 rolivares