Skip to content

Instantly share code, notes, and snippets.

@austenito
Created August 28, 2011 00:54
Show Gist options
  • Save austenito/1176083 to your computer and use it in GitHub Desktop.
Save austenito/1176083 to your computer and use it in GitHub Desktop.
old
var nowjs = require('now'),
Zeus = require('Zeus').Zeus,
everyone;
function start_chat(server) {
transport_types = ['xhr-polling', 'jsonp-polling'];
everyone = nowjs.initialize(server, { socketio: {'log level': 3,
'transports': transport_types }});
nowjs.on('connect', function(){
this.now.name = "Guest";
});
nowjs.on('disconnect', function(){
console.log("Left: " + this.now.room_hash);
});
everyone.now.initializeChat = function(room_hash) {
this.now.room_hash = room_hash;
nowjs.getGroup(this.now.room_hash).addUser(this.user.clientId);
};
everyone.now.distributeMessage = function(message){
if (message.startsWith('/nick ')) {
var old_name = this.now.name;
this.now.name = message.substring(message.indexOf(' '));
nowjs.getGroup(this.now.room_hash).now.nameChanged(old_name,
this.now.name);
}
else {
message.trim;
if(message.length > 0) {
nowjs.getGroup(this.now.room_hash).now.receiveMessage(this.now.name,
message);
}
}
};
everyone.now.addToQueue = function(video_src) {
var room_hash = this.now.room_hash;
var zeus = new Zeus();
zeus.init(room_hash);
zeus.add_to_queue(video_src, function() {
nowjs.getGroup(room_hash).now.pushToVideoQueue(video_src);
});
};
everyone.now.removeFromQueue = function() {
var room_hash = this.now.room_hash;
var zeus = new Zeus();
zeus.init(room_hash);
zeus.remove_from_queue(function() {
nowjs.getGroup(room_hash).now.popFromVideoQueue();
});
};
};
String.prototype.startsWith = function (str){
return this.indexOf(str) == 0;
};
module.exports.start_chat = start_chat;
@j3j3
Copy link

j3j3 commented May 16, 2012

What an amazing gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment