Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

upgrade to socket.io 0.7.x

  • Loading branch information...
commit 9e857f655fb2f0b12ab4f6391149b3a58786fe1b 1 parent 1861cae
@gaarf authored
View
2  lib/manager.js
@@ -20,7 +20,7 @@ _.extend(module.exports, {
removeUser: function(client) {
_.each(rooms, function(r) {
- r.removeUser({id:client.sessionId});
+ r.removeUser({id:client.id});
});
}
View
2  lib/user.js
@@ -11,7 +11,7 @@ function User(client) {
return _(this).defaults({
name: null,
ua: null,
- id: client.sessionId
+ id: client.id
});
};
View
2  package.json
@@ -17,7 +17,7 @@
"express": ">=2.3.2",
"underscore": ">=1.1.6",
"ejs": ">=0.4.1",
- "socket.io": ">=0.6.17",
+ "socket.io": "~0.7.7",
"oauth": ">=0.9.0"
}
}
View
11 public/javascripts/client.js
@@ -7,8 +7,7 @@ jQuery(document).ready(function($) {
$input = $compose.find('input'),
$twitstream = $page.find('.twitstream ol.tweets');
- var socket = new io.Socket();
- socket.connect();
+ var socket = io.connect();
soundManager.url = '/javascripts/libs/soundmanager2/';
soundManager.onload = function() {
@@ -98,13 +97,11 @@ jQuery(document).ready(function($) {
});
- socket.on('message', function(str){
- var mySessionId = this.transport.sessionid,
+ socket.on('message', function(msg){
+ var mySessionId = this.socket.sessionid,
doAlert = false;
- // console.debug('>>>',str);
-
- $.each(JSON.parse(str), function(k,obj) {
+ $.each(msg, function(k,obj) {
switch(k) {
View
19 server.js
@@ -11,15 +11,14 @@ if (!module.parent) {
console.log("Express server listening on port %d", app.address().port);
var _ = require('underscore')
- , io = require('socket.io') // socket.io, I choose you
- , socket = io.listen(app)
+ , io = require('socket.io').listen(app) // socket.io, I choose you
, roomManager = require('./lib/manager.js')
, room = roomManager.createRoom();
/* ================================================================ managing clients */
- socket.on('connection', function(client){
+ io.sockets.on('connection', function(client){
var user = roomManager.getUser(client);
@@ -36,12 +35,12 @@ if (!module.parent) {
user.on('name-update', function(me) {
user.joinRoom(room);
- client.send(JSON.stringify({ 'buffer': room.buffer, 'topic': {what:room.topic}, 'join':me }));
+ client.json.send({ 'buffer': room.buffer, 'topic': {what:room.topic}, 'join':me });
sendHelp();
});
user.on('slash-response', function(msg, cls) {
- client.send(JSON.stringify({ 'system': {msg:msg, addCls:cls} }));
+ client.json.send({ 'system': {msg:msg, addCls:cls} });
});
});
@@ -51,21 +50,21 @@ if (!module.parent) {
/* ================================================================ chatroom activity */
room.on('topic-update', function(who) {
- socket.broadcast(JSON.stringify({ 'topic': {what:this.topic, who:who} }));
+ io.sockets.json.send({ 'topic': {what:this.topic, who:who} });
});
room.on('stream-stop', function(who) {
- socket.broadcast(JSON.stringify({ 'stop': {who:who}, 'topic': {what:this.topic+' (stopped)'} }));
+ io.sockets.json.send({ 'stop': {who:who}, 'topic': {what:this.topic+' (stopped)'} });
});
room.on('roster-update', function(what, who) {
var out = { 'roster': this.roster };
out[what] = who; // fun!
- socket.broadcast(JSON.stringify(out));
+ io.sockets.json.send(out);
});
room.on('conversation-update', function(msg) {
- socket.broadcast(JSON.stringify({ 'speech': msg }));
+ io.sockets.json.send({ 'speech': msg });
});
@@ -75,7 +74,7 @@ if (!module.parent) {
setInterval(function() {
var tweets = room.getTweets();
if(tweets.length) {
- socket.broadcast(JSON.stringify({ 'tweets': tweets }));
+ io.sockets.json.send({ 'tweets': tweets });
}
}, 1000);
Please sign in to comment.
Something went wrong with that request. Please try again.