signalr-node

1.1.0 • Public • Published

signalr-node

A fork of signalr which works in Node, instead of the browser.

It's based on signalr-no-jquery which shims jQuery as the first step.

This repo takes it all the way and removes all reference to browser-specific standards.

Specifically, anything to do with window, user-agent detection, or cross-origin consideration has been replaced or stripped out.

It also removes the foreverFrame transport, as it's useless outside the browser.

The serverSendEvents and webSockets transports have been implemnted by two dependencies: EventSource for serverSendEvents and ws for webSockets.

All transports allow the use of a bearer access token by setting this via connection.accessToken. The token is then automatically set as an Authorization header.

For maximum flexibility, longPolling and any other AJAX will use a method provided by the user, here's a recommended implementation using request:

var request = require('request');

var ajax = function(options) {
  request({
    url: options.url,
    method: options.type,
    headers: {
      'content-type': options.contentType || 'application/text'
    },
    body: options.data && Object.keys(options.data).map((key) => key + '=' + encodeURIComponent(options.data[key])).join('&'),
    json: options.dataType == 'json',
    timeout: options.timeout || 30000
  }, function (error, response, body) {
    if (error !== null || response.statusCode >= 400) {
      if (options.error) {
        options.error({});
      }
    } else {
      if (options.success) {
        options.success(body);
      }
    }
  });
}

var signalr = require('signalr-node')(ajax);

Readme

Keywords

Package Sidebar

Install

npm i signalr-node

Weekly Downloads

81

Version

1.1.0

License

Apache-2.0

Unpacked Size

108 kB

Total Files

4

Last publish

Collaborators

  • tristanpenman
  • dubistkomisch
  • deanylev