Coder Social home page Coder Social logo

pushproxy.js's Introduction

#pushProxy.js - v0.2

##Goal The goal is to create a language neutral push system. By exposing a very simple RESTful API, we will create a powerful and flexible interface that will provide real time communication.

###Technical Stuff This is a node.js application that takes advantage of the awesome socket.io package. It is extremely powerful and very flexible. I also use Journey to provide simple routing to create the API. There is no html served ever.

node.js - http://nodejs.org/

socket.io - https://github.com/LearnBoost/socket.io

journey - https://github.com/cloudhead/journey --This is a custom version. Please use the one in the repo.

###Current Version v0.2: COMPLETE - Allow a user to register, and provide an API to send messages with a custom payload. Chat room functionality. This will allow users to subscribe to a room and also receive room specific broadcasts

###Roadmap

  • v0.1: COMPLETE - Allow a user to register, and provide an API to send messages with a custom payload.
  • v0.2: COMPLETE - Chat room functionality. This will allow users to subscribe to a room and also receive room specific broadcasts
  • v0.25: Add better response for each rest call. Return some useful information.
  • v0.3: Security. Add heavy security to facility server2server communication and facility some way to verify users authenticity.
  • v0.4: Different Message Types. This will simply the message handling on the javascript side

##Usage

###Simple Sample Here is a simple example of what pushProxy.js can do. Backend sample written in ColdFusion

Start pushProxy

sudo node pushProxy.js

Client side code

<script src="http://localhost:8080/socket.io/socket.io.js"></script>
<script>
    //Connect to socket.io
    var socket = io.connect('http://localhost:8080');
	socket.on('connect', function (data) {
    	socket.emit('register', { userId: #userId# });
	});
	socket.on('message', function(data){
		//This is your handler.  All messages come in via a message right now.
		//I use a generic window call
		window[data.method].apply(this, data.arguments)
	})
</script>

Back end code

<cfscript>
payload = {
	 'userId' = 1,
	 'data' = {
	 	'method' = 'foobar',
		'arguments' = {
				'roomId' = 1
			}
	 	}
	};
</cfscript>
<cfhttp name="call" result="test" url="http://localhost/command" method="POST" port="8080" resolveurl="yes">
	<cfhttpparam type="FORMFIELD" name="command" value="send">
	<cfhttpparam type="FORMFIELD" name="data" value="#SerializeJSON(payload)#">
</cfhttp>
<cfdump var="#DeserializeJSON(test.filecontent)#" />

Please note that for format of the payload and the command in the post.

  • The command in the post notifies pushProxy that it it wants to push. This is the only command right now.
  • The payload for the send command must have the userId key in the json struct. The userId could be a string or number. It just has to match the userId sent in the register function.
  • I use the data to invoke the proper action with the arguments. This is completely up you to you though.

##License I have released this under the MIT License. Feel free to use and contribute.

pushproxy.js's People

Contributors

mbseid avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.