electrum-signalr
This wrapper hides the depencies to SignalR and jQuery, so that it gets possible
to use ES6 import
to get a properly configured SignalR instance, and then use
the HubLoader
class to establish a bidirectional connection with the SignalR
server.
import SignalR from 'electrum-signalr';
const hubUrl = '...';
const ownUrl = '...';
let loader = new SignalR.HubLoader ('fooHub');
loader.Load (hubUrl, ownUrl, () => console.log ('Ready'));
The HubLoader class
Methods
The HubLoader
class defines following public methods:
constructor (hubName)
→ specify the name of the SignalR hub.load (hubUrl, ownUrl, ready)
→ load the proxy for the given hub;
the URL of the hub and of the client endpoint need to be provided; ready
will be called with the instance of the HubLoader
when the proxy is
ready for use. Typically, ready(loader)
should call loader.start()
.start ()
→ start the communication between the proxy and the
distant hub; this will establish the SignalR communication channel.setupProxy (factory)
→ configure the proxy by injecting it the
handler's methods; the handler is returned by the factory. Methods
which start with an underscore (_
) will not be injected.
Note: setupProxy (factory)
takes a proxy => handler
callback as argument.
Getters
The HubLoader
class defines following public getters:
hub
→ the client-side hub instance.hubName
→ the name of the hub, as provided to the constructor.hubProxy
→ the proxy to the server hub.connection
→ the SignalR connection.
Static getters
The HubLoader
class exposes jQuery as a static getter:
const jQuery = SignalR.HubLoader.jQuery ();
Internal notifications
The HubLoader
calls life cycle methods when things happen:
onConnected ()
→ the client and the server hubs are now connected.onConnectFailed ()
→ the connection failed.onError (error)
→ there was an error while exchanging messages between
the hubs.
You can overload these methods if you need to handle the notifications.
Otherwise, they will just display messages on the console.