Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
{
"name": "socket.io.1.0",
"version": "1.0.0",
"description": "Socket.IO 1.0 using Primus",
"main": "socket.io.1.0.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gist.github.com/6113494.git"
},
"keywords": [
"socket.io",
"primus"
],
"author": "Arnout Kazemier",
"license": "MIT",
"bugs": {
"url": "https://gist.github.com/6113494"
},
"dependencies": {
"primus-multiplex": "~0.1.2",
"primus-emitter": "~0.1.0",
"primus-rooms": "~0.1.6",
"primus": "~1.1.2",
"engine.io": "~0.6.3"
}
}
'use strict';
var Primus = require('primus')
, http = require('http');
//
// Setup a server that Primus can listen on, pass it in the primus
// constructor, select `engine.io` as transformer, add plugins,
// ???, profit
//
var server = http.createServer();
var app = new Primus(server, { transformer: 'engine.io' });
app.use('multiplex', 'primus-multiplex')
.use('emitter', 'primus-emitter')
.use('rooms', 'primus-rooms');
server.listen(8080);
//
// Save the client in the root of directory or just use it directly
// <script src="http://localhost:8080/primus/primus.js"></script>
//
app.on('connection', function (socket) {
socket.emit('hello', 'world');
socket.join('room');
});
app.channel('foo').on('connection', function (socket) {
socket.emit('hello', 'foo');
});
@3rd-Eden

This comment has been minimized.

Copy link
Owner Author

commented Sep 18, 2013

<script src="/primus/primus.js"></script>
<script>
var socket = Primus.connect('http://localhost:8080')

socket.on('hello', function (data) {
  console.log(arguments);
  socket.emit('foo', data);
});
</script>
@mons54

This comment has been minimized.

Copy link

commented Nov 13, 2013

socket.emit() doesn't work with Primus Emitter 2.x.

Must be used: socket.send()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.