1.0.0-rc.2 • Published 6 years ago

signalr-js-client v1.0.0-rc.2

Weekly downloads
2
License
ISC
Repository
-
Last release
6 years ago

SignalR JS Client

A SignalR Javascript client without dependencies. Supports the following transport methods:

  • Web sockets
  • Server-sent Events (SSE)
  • Long polling

Installation

$ cd my-app
$ npm install signalr-js-client

or

<script src='https://cdn.jsdelivr.net/gh/lylerman/signalr-js-client/dist/signalr-js-client.min.js'></script>

Usage

Initialize

For the referenced script version, make sure to use the signalR keyword when initializing the connection. Please do not use import when referencing via script tag.

import signalR from 'signalr-js-client';

const hub = signalR.connection('hubName');
hub.url = 'http://website.com/signalr';
    
hub.start();

Client-methods

hub.on('notify', msg => {
    console.log(msg);
});

Server-methods

When applicable, separate params using commas.

hub.invoke('BroadcastNotification', msg)

Options

You can set these options on or before calling hub.start(). Transport fallback is in this order: web sockets, server-sent events, long polling.

OptionValuesDescriptionDefault
timeoutany positive integersets timeout (in milliseconds) for negotiationg with server3000
transportwebSockets, serverSentEvents, longPollingspecifies transport type (falls back automatically)webSockets
url (required)signalr server urlsets url where signalR will connect toN/A

Example

hub.start({
    url: 'http://website.com/signalR',
    transport: 'serverSentEvents',
    timeout: 5000
});

or

hub.url = 'http://website.com/signalR';
hub.start();

The timeout option is used only for the negotiate request.

Todo

  • Forever frame for IE