• Stars
    star
    156
  • Rank 239,589 (Top 5 %)
  • Language
    JavaScript
  • Created over 14 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript push server and client, developing real-time web applications should be easy.. now you can do it in js

No longer maintained.

Push-It is no longer maintained. If you'd like to become the maintainer, please email me - [email protected]

For alternatives, please see SockJS or Socket.io

Introduction

Push-It gives you an API for realtime pub/sub in the browser. On the server, it gives you hooks for security and message routing. It is fast and cross-browser compatible.

Dependencies

Self-contained on the client. On the server, Push-It is tested with Node 0.4.7

Overall Design

The design takes the best of bayeux, layers it on top of sockjs and provides you a simple and clear way to define security for your application.

With callbacks, you can easily customize the system to provide security and message-routing functionality.

The system is designed with scaling in mind, so you will be able to run multiple Push-It servers without worrying about sticky sessions once sockjs supports pluggable persistence. Please email [email protected] if this is something you require.

Security

You should override this: The default behavior of the system is to be completely open and echo all messages published to all subscribers on a per-channel basis.

You define security at the point of connection, subscription and publication of messages. The semantics are all asynchronous so you can call out from Node to other services to perform your security checking if you'd like. For instance, you could check credentials with facebook connect, LDAP or a custom REST api. Each of these handlers has a timeout. If your handler takes longer than its timeout, then the system will perform the least-permissive action (disconnecting a client, denying a subscription request or denying a publication.)

Server and Client

Push-It has the server that you run with node.js (or include in your existing node.js project,) and the client that you include in your web page.

Client

  var channels = ["stories/5", "calendar"];
  var credentials = document.cookie; 
  pushIt = new PushIt({channels: channels, credentials: credentials});

  var msgId = pushIt.publish(message, onError, onSuccess);

  //set up message handler
  pushIt.onMessageReceived = function(channel, message){
     /* 
        update UI
        message has the properties: uuid, channel, and payload
     */
  };

  //unsubscribe
  pushIt.unsubscribe("messages");

  //subscribe to additional channels at runtime
  pushIt.subscribe("calendar/2", onError, onSuccess);

Server

  //create your default server, raw http, connect or express
  var server = connect.createServer( 
    connect.staticProvider(__dirname + '/static')
  );

  //open your port
  server.listen(8001);

  //read the optional options file. sync is usually avoided, but fine for server statup
  var options = JSON.parse(fs.readFileSync(__dirname+"/options.json"))  

  //create the PushIt instance      
  var pi = new PushIt(server, options);

  //customize security gates. default is to permit all actions.
  pi.onConnectionRequest = function(agent){
    if(agent.credentials == "it's meeee!") //reasonable default ;)
      agent.connected();
  }

Workflow

###1. An agent connects

  PushIt.onConnectionRequest = function(agent){}
  1. check the agent.credentials however you see fit.
  2. if they are valid, call agent.connected()
  3. if they are invalid or you have an error, call agent.connectionDenied(reason)
  4. if you do not call disconnect or connected, they will be denied after pushIt.TIMEOUTS.onConnectionRequest milliseconds

###2. An agent subscribes to channels

The system will use the channel-specific function if the channel and function exist and will fall back to the default otherwise.

    PushIt.onSubscriptionRequest = function(channel, agent){}
    channel.onSubscriptionRequest = function(channel, agent){}
  1. check agent.credentials however you see fit
  2. if the agent is allowed to receive on this channel, call agent.subscribe(channel)
  3. if the agent is not allowed to receive on this channel, call agent.subscriptionDenied(channel, reason)
  4. if you do not call subscribe or subscriptionDenied, they will be automatically disconnected after pushIt.TIMEOUTS.onSubscriptionRequest milliseconds

###3. An agent publishes to channels

The system will use the channel-specific function if the channel and function exist and will fall back to the default otherwise.

    PushIt.onPublicationRequest = function(channel, agent, message){}
    channel.onPublicationRequest = function(channel, agent, message){}
  1. check agent.credentials however you see fit
  2. if the agent is allowed to publish on this channel, call channel.publish(message). You may publish the message to as many channels as you'd like.
  3. call agent.publicationSuccess(message) if you have published the message (or dealt with it in some other way, like posting it to a rest service or logging it or whatever else you'd like,)
  4. if the agent is not allowed to publish on this channel, call agent.publicationDenied(message, reason)
  5. if you do not call agent.publicationDenied or agent.publicationSuccess, then a publicationDenied will be automatically sent after pushIt.TIMEOUTS.onPublicationRequest milliseconds

###4. An message is sent to a channel where an agent has a subscription.

    Agent.onMessageReceived = function(channel, agent, message){}
  1. check agent.credentials however you see fit
  2. if the agent is allowed to receive this message, call agent.deliver(channel, message)

NOTE: this callback is unlike the others. there is no timeout or failure condition. you can silently drop messages and nobody will be informed. This is useful if you want to perform some JIT transformation of messages before delivery to agents.

###5. An agent unsubscribes to channels

This is the same as subscription, except with the names changed to Unsubscribe and Unsubscription.

###6. An agent disconnects

PushIt.onDisconnect(agent)

This is provided for your convenience and completeness.

Push-It Objects:

Define in your code

  • PushIt

    • options
    • channels
  • Channel (a namespace for message distribution)

    • name
    • guards:
      • beforeJoin
      • onMessage

created / destroyed at runtime

  • Agent (things that wish to be notified, and may stand in for other things of the same ilk)
    • uuid
    • isConnected
    • connection
    • credentials (application-defined)
  • Message (stuff to be routed)
    • uuid
    • channel (uuid)
    • data (application-defined)
  • Subscription (the connection between an agent and a channel)
    • uuid
    • channel (uuid)
    • agent (uuid)

More Repositories

1

routes.js

a minimalist url-style routing library, extracted from connect
JavaScript
319
star
2

clutch

Make a USB pedal send one key tap when you press it in and another when you release it
Objective-C
44
star
3

macros

Aan easy way to define a pre-processor chain for your JavaScript source.
JavaScript
28
star
4

EasyStereoWaveFileHeader

A simple C library for writing out 16-bit Int Stereo 44.1khz .wav files
C
20
star
5

restartr

Restart process when files change - reload node.js automatically
JavaScript
18
star
6

evalsha

a hosted redis script site =)
Ruby
12
star
7

Propagate-JS

Reactive programming for JavaScript; less callbacks, better interfaces
JavaScript
10
star
8

shared-views

I want to share server-side templates with the browser
JavaScript
10
star
9

Random-ID

Pure-JS random base64-uri id generation.
JavaScript
9
star
10

JavaScript-datastructures

A collection of datastructures for JavaScript. Intended to be a nice starting point for building just what you need.
JavaScript
7
star
11

inspector_gadget

Inspector Gadget gives insight into the construction, composition and monkeypatching of ruby classes, modules and methods
Ruby
6
star
12

advent-of-code-2022

Rust
6
star
13

bitset

Go
6
star
14

Pearl

Perl's Autovivification for Ruby : complex object creation without initialization.
Ruby
5
star
15

fsproxy

A FUSE-based filesystem proxy with hooks!
Go
5
star
16

easyhash

convenience wrapper for node.js hash module
JavaScript
4
star
17

Twilio-Node

Twilio API bindings for Node.JS
3
star
18

formulate

thin wrapper for formidable, making it a touch more convenient.
JavaScript
3
star
19

DeskSet

Yet Another Asynchronous JS Library
JavaScript
3
star
20

MinimalStyleSheet

2
star
21

ejsrb

embeddedjs with ruby
JavaScript
2
star
22

iOS-Accelerate-Framework-Benchmark

simple app to test the speed increase of the Accelerate framework on iOS
C
2
star
23

Journaling-Hash

Overriding defaults is awesome, but it can be tricky to debug. Journaling-Hash makes it easy to have a configuration object where you can easily track where configuration changes were made.
2
star
24

soundcloud-cli-ruby

Soundcloud Command-Line Interface in Ruby
Ruby
1
star
25

FastTime

Fast ruby binding to `gettimeofday`. Cheaper than Time.now.to_i.
Ruby
1
star
26

advent-of-code-2021

Ruby
1
star
27

yertlejr

Yertle Jr is a Parsing Expression Grammar (PEG) and parser generator
JavaScript
1
star
28

simple-tracing

Simple Tracing for Ruby.
Ruby
1
star
29

gostar

Generics in Go through simple AST manipulation.
1
star
30

Transitive-Bootstrap

bootstrap a new transitive app.
1
star
31

dx-dt

dx-dt
JavaScript
1
star
32

dxdt-web

The front-end web site for dxdt
JavaScript
1
star
33

Realtime-Experiments

JavaScript
1
star
34

Xitive.com

Our Home page
1
star
35

stochastik.xitive.com

Stochastik web site
1
star
36

blog-old

1
star