Skip to content

viviedu/signalr-node

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%