DVLP / signalr-no-jquery

120 stars 78 forks source link

Adding proxy event listeners after connection has been opened #28

Closed BartVanBeurden closed 7 months ago

BartVanBeurden commented 7 years ago

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.

rolivares commented 6 years ago

same thing here