Azure SignalR support for Node.js


Introduction

Azure SignalR Serviceexternal link enables real-time messaging over WebSocket connections for both ASP.NET Core and ASP.NET Framework applications.

Whenever a call to a supported hub method API is detected, this extension evaluates the hub name and the method name and creates a NodeJS Azure SignalR Call to Hub Method object named after the method, with a property storing the hub name. If the evaluation fails (due to missing information in the source code or limitations in the evaluation), a NodeJS Azure SignalR Call to Unknown Hub Method object is created instead.

Objects

Icon Description
NodeJS SignalR Call to Hub Method
NodeJS SignalR Call to Unknown Hub Method

Supported Packages

Package Runtime Supported APIs
@microsoft/signalr ASP.NET Core HubConnection.invoke
HubConnection.send
HubConnection.stream
@aspnet/signalr ASP.NET Core (deprecated) HubConnection.invoke
HubConnection.send
HubConnection.stream
signalr ASP.NET Framework - jQuery $.hubConnection
createHubProxy
proxy.invoke
$.connection.<hub>.server.<method>
ms-signalr-client ASP.NET Framework - jQuery $.hubConnection
createHubProxy
proxy.invoke
$.connection.<hub>.server.<method>
signalr-no-jquery ASP.NET Framework - no jQuery hubConnection
createHubProxy
proxy.invoke
signalrjs-angular ASP.NET Framework - no jQuery hubConnection
createHubProxy
proxy.invoke
angular-signalr-hub ASP.NET Framework - AngularJS 1.x new Hub(name, options)
hub.<method>()
hub.invoke(method)
ng2-signalr ASP.NET Framework - Angular 2+ SignalRConfiguration.hubName
connection.invoke(method)

The com.castsoftware.wbslinker extension will create a callLink from a NodeJS Azure SignalR Call to Hub Method to a matching DotNet Azure SignalR Method object when both the method name and hub name match.

Examples

When analyzing one of the following pieces of code, the following result will be produced:

@microsoft/signalr and @aspnet/signalr

import * as signalr from '@microsoft/signalr'

function my_invoke(){
  const connection = new signalR.HubConnectionBuilder()
  .withUrl("/myhub")
  .configureLogging(signalR.LogLevel.Information)
  .build();

  await connection.start()
  await connection.invoke("MyMethod", user, message);
}

signalr - without generated proxy

function my_invoke(){
  var connection = $.hubConnection();
  var hubProxy= connection.createHubProxy('myhub');
  hubProxy.invoke('MyMethod', { UserName: userName, Message: message})
}

signalr - with generated proxy

function my_invoke(){
  var hubProxy = $.connection.myhub;
  hubProxy.server.MyMethod({user:user, message:message})
}

ms-signalr-client

require('jquery');
require('ms-signalr-client');

(function ($, window) {
  "use strict";
  var connection = $.hubConnection('http://server/');
  var proxy = connection.createHubProxy('chatHub');

  function my_invoke() {
    proxy.invoke('MyMethod', user, message);
  }
}(window.jQuery, window));

signalr-no-jquery and signalrjs-angular

import { hubConnection } from 'signalr-no-jquery'

const connection = hubConnection('http://server:8080/signalr', { useDefaultPath: false });
const proxy = connection.createHubProxy('chatHub');

function my_invoke() {
  proxy.invoke('MyMethod', user, message);
}

The signalrjs-angular package exposes the same API and is detected identically, juste replace the import source with 'signalrjs-angular'.

angular-signalr-hub

const signalrHub = require('angular-signalr-hub');

function register(Hub) {
  var hub = new Hub('chatHub', {
    methods: ['MyMethod', 'join']
  });

  function my_invoke() {
    hub.invoke('MyMethod', user, message);
  }
}

Methods declared in the methods array can also be called directly on the hub variable (e.g. hub.MyMethod(user, message)) - both forms are detected.

ng2-signalr

import { SignalR, SignalRConfiguration } from 'ng2-signalr';

const config = new SignalRConfiguration();
config.hubName = 'chatHub';

async function my_invoke() {
  const connection = await signalR.connect();
  connection.invoke('MyMethod', user, message);
}