Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Last active December 20, 2015 10:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save 3rd-Eden/6113494 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/6113494 to your computer and use it in GitHub Desktop.
{
"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
Copy link
Author

<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
Copy link

mons54 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