npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dksignalrjs

v1.3.0

Published

signalrJS

Downloads

13

Readme

signalR

===

A Node.js server implementation of Signalr. It works with the 2.0 signalr javascript client

Install

npm install dksignalrjs

Quick Start - Persistent Connection

The Server

var express = require('express');
var DKSignalRJS = require('dksignalrjs');

var signalR = DKSignalRJS();

var server = express();
server.use(signalR.createListener())
server.use(express.static(__dirname));
server.listen(3000);

signalR.on('CONNECTED',function(){
	console.log('connected');
	setInterval(function () {
		signalR.send({time:new Date()});
	},1000)
});

The Client

<!DOCTYPE html>
<html xmlns="">
<head>
    <script src="bower_components/jquery/dist/jquery.js" type="text/javascript"></script>
    <script src="bower_components/signalr/jquery.signalR.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            var connection = $.connection('/signalr');
            connection.error(function(error){
                console.log(error);
            });
            connection.received(function (data) {
                console.log('The time is ' + data.time.toString());
            });

            connection.start().done(function() {
                console.log("connection started!");
            });
        });
    </script>
</head>
<body>
</body>
</html>

Quick Start - Hub Connection

##The Server

var express = require('express');
var DKSignalRJS = require('dksignalrjs');

//Init SignalRJs
var signalR = DKSignalRJS();

//Create the hub connection
//NOTE: Server methods are defined as an object on the second argument
signalR.hub('chatHub',{
	send : function(userName,message){
		this.clients.all.invoke('broadcast').withArgs([userName,message])
		console.log('send:'+message);
	}
});

var server = express();
server.use(express.static(__dirname));
server.use(signalR.createListener())
server.listen(3000);

##The Client

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script src="bower_components/jquery/dist/jquery.js" type="text/javascript"></script>
    <script src="bower_components/signalr/jquery.signalR.js" type="text/javascript"></script>
    <script src="signalr/hubs"></script>
    <script type="text/javascript">
        $(function () {
        	//Create hub connection
            var connection = $.connection.hub;
            var chatHub = $.connection.chatHub;

            //Handle a broadcast
            chatHub.client.broadcast = function (broadcastMessage) {
            	console.log(broadcastMessage);
            };

            $.connection.hub.start().done(function () {
                $('#sendmessage').click(function () {
                	//Call the hub server send
                    chatHub.server.send('A Message');
                });
            });
        });
    </script>
</head>
<body>
	<input type="button" id="sendmessage" value="Send" />
</body>
</html>

Purpose

The purpose of this project is to allow developers to use a non .Net platform with SignalR.

The main benefit of this implementation is that it allows front end developers to quickly mockup a Signalr implementation without having to worry about the .Net server side development. The implementation is not 100% complete, and is not intended for production.

Supported Transports

The implementation currently supports the following transports:

  • Long Polling - IE > 10
  • Server Sent Events - Chrome, Firefox, etc

Examples

Check out the Docs section to see an examples for:

  • A Time server
  • A chat server
  • A private server
  • A chat server with passport authentication

Supported Connections

Hubs

Hub Servers

Hubs define a connection by a name, and a set of available methods. Signalr makes the server methods 'directly' callable within the client application like. Given a client as follows:

var connection = $.connection.hub;
var chatHub = $.connection.chatHub

chatHub.server.send('A Message');

The server would need to have the 'send' method defined in the 'chatHub' as follows:

signalR.hub('chatHub',{
	send : function(message){

	}
});

Finally, to have the send method communicate to the clients, the server needs to make a call to all clients. This can be done within a server method by calling the following:

//invoke specifies the name of the client function to call
//withArgs specifies the arguments to call the function with
this.clients.all.invoke('broadcast').withArgs([message])

The client would then have the following method defined:

chatHub.client.broadcast = function (message) {
	console.log('some message:'+message)
};

Now the server can communicate to the clients.

Handling User

These methods are provided to make it easier to set a user for a connection. If you ar using Signalr .Net you would use Integrated authentication, since dksignalrjs uses node.js it handles user authentication slightly differet.

With the client

Signalrjs provides the ability for clients to set the user name for a connection. NOTE: this is non-standard and is not part of the Signalr.

In the client this can be done as follows:

$.connection.hub.start().done(function () {
    $.connection.$user('anyUserName');
});

NOTE: setting a user can only be done after the connection has been set; See the privateChat example to see this in action.

With Passport

Passport provides the ability to use several strategies to manage user authentication. If you use passport, then dksignalrjs will automatically set the user for a particular connection. See the passportChat example to see this in action.