https://github.com/williscool/simple-node-socket.io-wrapper
Makes using the node.js socket.io server a bit less painful
https://github.com/williscool/simple-node-socket.io-wrapper
Last synced: 11 months ago
JSON representation
Makes using the node.js socket.io server a bit less painful
- Host: GitHub
- URL: https://github.com/williscool/simple-node-socket.io-wrapper
- Owner: williscool
- Created: 2011-03-31T08:08:11.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2011-04-04T05:49:51.000Z (almost 15 years ago)
- Last Synced: 2023-03-11T21:07:20.194Z (almost 3 years ago)
- Language: JavaScript
- Homepage:
- Size: 89.8 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Node Socket.io Wrapper
var express = require('express');
var app = express.createServer();
app.use(express.bodyParser());
var sockH = require('../lib/node-socket-wrapper').config(app);
app.listen(5000);
app.get("/", function (req, res){
sockH.on('gotClient', function(seh){
seh.greeting('hi there client. this is a bit easier to write');
setTimeout( seh.calling('im caliing you!'), 5000);
seh._trigger('anEventIMadeUp', 'A message I would like to send' );
seh._trigger('passingData', req.body.somethingOrOther );
});
});
## How it works
1) It binds to any connect server (in the example an express one)
2) Returns a socket bound to the port of your server
3) on the `gotClient` event it returns the client that has connected with helpful functions wrapped around it that you can extend
## This allows you to
a) leave socket.io connection code out of your app code.
b) easily access actual clients
c) trivially use socket.io on more than one page in an app.
## Usage
there is server example in this repository to help you get started
## Credits
parts of the server code inspired by this article
[http://spiritconsulting.com.ar/fedex/2010/11/events-with-jquery-nodejs-and-socket-io/](http://spiritconsulting.com.ar/fedex/2010/11/events-with-jquery-nodejs-and-socket-io/)
server depend on [`express`](http://expressjs.com).