Utility to keep single SignalR connection for all browser windows (tabs) of the same application
Switch branches/tags
Nothing to show
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Initial commit Feb 1, 2015
README.md Added an example for script references (see #9) Nov 29, 2018
icon.png Icon added Feb 1, 2015
iwc-signalr.js Added method `getConnectionId` (#7) May 24, 2015
signalr-patch.js Fix typo in signalr-patch Apr 21, 2015



Browsers have a limitation of the maximum number of connections to the same host address (same application). So, this limits the maximum number of opened browser windows of the same application with SignalR connections. IWC-SignalR allows to bypass this restriction using single SignalR connection for all windows of the same application. IWC-SignalR was tested with SignalR v2.2.0.

How it works

One of the windows becomes a connection owner (choosen randomly) and holds the real SignalR connection. If connection owner is closed or crashed another window becomes a connection owner - this happens automatically. Inter-window communication is done by means of IWC.


To use IWC-SignalR include signalr-patch.js and iwc-signalr.js files on your page. signalr-patch.js allows to start SignalR multiple times. This allows to reconfigure hub proxies at any time.

IWC-SignalR works with auto generated proxies. So, you should also include a reference <script src="signalr/hubs"></script> before signalr-patch.js and iwc-signalr.js. For example:

<!--Reference the SignalR library. -->
<script src=".../jquery.signalR-2.2.0.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="signalr/hubs"></script>

<script src=".../iwc-all.js"></script>
<script src=".../signalr-patch.js"></script>
<script src=".../iwc-signalr.js"></script>

Let's have a hub Echo with method Send defined on server. Method Send calls method displayMsg of all clients.

var echoHub = SJ.iwc.SignalR.getHubProxy('echo', {
    client: {
        displayMsg: function (msg) {
SJ.iwc.SignalR.start().done(function () {
    echoHub.server.send('test').done(function () {
//Result in console:


IWC-SignalR depends on IWC


Connection starting


Parameters and return value:

This function has the same signature as the original $.connection.hub.start function


SJ.iwc.SignalR.start when called it tries to find connection owner and connect to it via IWC. If connection owner not found, real SignalR connection is established and this window becomes a connection owner.

Obtaining hub proxy

{object}SJ.iwc.SignalR.getHubProxy({string}hubName, {object}proxyConfig)

  • hubName - hub name according to SignalR naming convention (starts from lower case letter)
  • proxyConfig - object which contains definition of client's methods
Return value:

Returns hub proxy object with server and client


Creates hub proxy object with server and client. Usage of server and client doesn't depend on whether the SignalR connection is real or via IWC.

var echoHub = SJ.iwc.SignalR.getHubProxy('echo', {
    client: {
        displayMsg: function (msg) {


Check if conection owner


Return value:

Returns true if this window is the owner of SignalR connection

Who is conection owner


Return value:

Returns the ID of connection owner window. Returns null if connection owner not found.


This method works properly only if SJ.iwc.WindowMonitor is initialized.

Current state


Return value:

Returns connection state (see SignalR's $.connection.connectionState for available values)


Returns the state of real SignalR connection

Connection Id


Return value:

Returns connection id (see SignalR's $.connection.hub.id)


Returns the connection id of real SignalR connection


Use SJ.iwc.SignalR.on() and SJ.iwc.SignalR.un() to subscribe/unsubscribe on events

  • statechanged(newState, prevState) - fired when connection state is changed. newState, prevState - new and previous state (see SignalR's $.connection.connectionState for available values)
  • connected - fired when state is changed to $.connection.connectionState.connected
  • starting, received, connectionslow, reconnecting, reconnected, disconnected - are the same events as for original SignalR connection
var someObject = {
    onStateChanged: function (newState, prevState) {
SJ.iwc.SignalR.on('statechanged', someObject.onStateChanged, someObject);
SJ.iwc.SignalR.un('statechanged', someObject.onStateChanged, someObject);