added all the code for realtime mapping using websockets. fixed some minor bugs like the label glitches, dragBox to deselect as well as select, shift click for synapses working again, panning won't deselect all your selected nodes and edges, nor hide the showcard, but a single click will hide the open card
This commit is contained in:
parent
aae89c3c1a
commit
f657a61327
498 changed files with 183196 additions and 143 deletions
5
Gemfile
5
Gemfile
|
@ -5,6 +5,7 @@ gem 'rails', '3.2.11'
|
|||
# Bundle edge Rails instead:
|
||||
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
||||
|
||||
gem 'redis'
|
||||
gem 'pg'
|
||||
gem 'authlogic'
|
||||
gem 'cancan'
|
||||
|
@ -13,8 +14,8 @@ gem 'formtastic'
|
|||
gem 'json'
|
||||
gem 'rails3-jquery-autocomplete'
|
||||
gem 'best_in_place'
|
||||
gem 'therubyracer' #optional
|
||||
gem 'rb-readline'
|
||||
#gem 'therubyracer' #optional
|
||||
#gem 'rb-readline'
|
||||
|
||||
# Gems used only for assets and not required
|
||||
# in production environments by default.
|
||||
|
|
10
Gemfile.lock
10
Gemfile.lock
|
@ -96,9 +96,10 @@ GEM
|
|||
rake (10.0.3)
|
||||
rdoc (3.12)
|
||||
json (~> 1.4)
|
||||
sass (3.2.1)
|
||||
sass-rails (3.2.5)
|
||||
railties (~> 3.2.0)
|
||||
redis (2.2.2)
|
||||
sass (3.2.7)
|
||||
sass-rails (3.2.3)
|
||||
railties (~> 3.2.0.beta)
|
||||
sass (>= 3.1.10)
|
||||
tilt (~> 1.3)
|
||||
sprockets (2.2.2)
|
||||
|
@ -133,5 +134,6 @@ DEPENDENCIES
|
|||
pg
|
||||
rails (= 3.2.11)
|
||||
rails3-jquery-autocomplete
|
||||
sass-rails (~> 3.2.3)
|
||||
redis
|
||||
sass-rails (= 3.2.3)
|
||||
uglifier (>= 1.0.3)
|
||||
|
|
6
Gemfile~
6
Gemfile~
|
@ -13,13 +13,13 @@ gem 'formtastic'
|
|||
gem 'json'
|
||||
gem 'rails3-jquery-autocomplete'
|
||||
gem 'best_in_place'
|
||||
#gem 'therubyracer' #optional
|
||||
#gem 'rb-readline'
|
||||
gem 'therubyracer' #optional
|
||||
gem 'rb-readline'
|
||||
|
||||
# Gems used only for assets and not required
|
||||
# in production environments by default.
|
||||
group :assets do
|
||||
gem 'sass-rails', '~> 3.2.3'
|
||||
gem 'sass-rails', '3.2.3'
|
||||
gem 'coffee-rails', '~> 3.2.1'
|
||||
|
||||
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
||||
|
|
|
@ -149,9 +149,8 @@ function onCanvasSearch(searchQuery, mapID, mapperID) {
|
|||
function clearCanvas() {
|
||||
Mconsole.graph.eachNode(function(n) {
|
||||
Mconsole.graph.removeNode(n.id);
|
||||
//TODO shouldn't we use disposeLabel? Yes, but it breaks things so it's
|
||||
//hide for now
|
||||
Mconsole.labels.hideLabel(n.id);
|
||||
Mconsole.labels.disposeLabel(n.id);
|
||||
delete Mconsole.labels.labels["" + n.id]
|
||||
});
|
||||
Mconsole.plot();
|
||||
}
|
||||
|
|
|
@ -8,17 +8,20 @@ function selectEdgeOnClickHandler(adj, e) {
|
|||
return;
|
||||
}
|
||||
|
||||
var showDesc = adj.getData("showDesc");
|
||||
if (showDesc && e.shiftKey) {
|
||||
var edgeIsSelected = MetamapsModel.selectedEdges.indexOf(adj);
|
||||
if (edgeIsSelected == -1) edgeIsSelected = false;
|
||||
else if (edgeIsSelected != -1) edgeIsSelected = true;
|
||||
|
||||
if (edgeIsSelected && e.shiftKey) {
|
||||
//deselecting an edge with shift
|
||||
deselectEdge(adj);
|
||||
} else if (!showDesc && e.shiftKey) {
|
||||
} else if (!edgeIsSelected && e.shiftKey) {
|
||||
//selecting an edge with shift
|
||||
selectEdge(adj);
|
||||
} else if (showDesc && !e.shiftKey) {
|
||||
} else if (edgeIsSelected && !e.shiftKey) {
|
||||
//deselecting an edge without shift - unselect all
|
||||
deselectAllEdges();
|
||||
} else if (!showDesc && !e.shiftKey) {
|
||||
} else if (!edgeIsSelected && !e.shiftKey) {
|
||||
//selecting an edge without shift - unselect all but new one
|
||||
deselectAllEdges();
|
||||
selectEdge(adj);
|
||||
|
|
|
@ -13,10 +13,17 @@ MetamapsModel.embed = false;
|
|||
MetamapsModel.selectedEdges = new Array();
|
||||
MetamapsModel.selectedNodes = new Array();
|
||||
|
||||
//this stores a value that indicates whether the user panned or simply clicked without panning
|
||||
// used for purposes of knowing whether to close the open card or not (don't if panned)
|
||||
MetamapsModel.didPan = false;
|
||||
|
||||
//is any showcard open right now? which one?
|
||||
MetamapsModel.showcardInUse = null;
|
||||
MetamapsModel.widthOfLabel = null;
|
||||
|
||||
//is an edge card open right now? which one (the id)?
|
||||
MetamapsModel.edgecardInUse = null;
|
||||
|
||||
//is the mouse hovering over an edge? which one?
|
||||
MetamapsModel.edgeHoveringOver = false;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ function graphSettings(type, embed) {
|
|||
//Enable panning events only if we're dragging the empty
|
||||
//canvas (and not a node).
|
||||
panning: 'avoid nodes',
|
||||
zooming: 15 //zoom speed. higher is more sensible
|
||||
zooming: 28 //zoom speed. higher is more sensible
|
||||
},
|
||||
// Change node and edge styles such as
|
||||
// color and width.
|
||||
|
@ -111,13 +111,6 @@ function graphSettings(type, embed) {
|
|||
|
||||
if (e.target.id != "infovis-canvas") return false;
|
||||
|
||||
//topic and synapse editing cards
|
||||
if (!Mconsole.events.moved && !node) {
|
||||
hideCards();
|
||||
deselectAllNodes();
|
||||
deselectAllEdges();
|
||||
}
|
||||
|
||||
//clicking on a edge, node, or clicking on blank part of canvas?
|
||||
if (node.nodeFrom) {
|
||||
selectEdgeOnClickHandler(node, e);
|
||||
|
@ -125,7 +118,9 @@ function graphSettings(type, embed) {
|
|||
selectNodeOnClickHandler(node, e);
|
||||
} else {
|
||||
//topic and synapse editing cards
|
||||
if (!Mconsole.events.moved) hideCards();
|
||||
if (!MetamapsModel.didPan) {
|
||||
hideCards();
|
||||
}
|
||||
canvasDoubleClickHandler(eventInfo.getPos(), e);
|
||||
}//if
|
||||
}
|
||||
|
@ -199,6 +194,7 @@ function graphSettings(type, embed) {
|
|||
|
||||
function hideCards() {
|
||||
$('#edit_synapse').hide();
|
||||
MetamapsModel.edgecardInUse = null;
|
||||
hideCurrentCard();
|
||||
}
|
||||
|
||||
|
@ -471,7 +467,10 @@ function selectNodesWithBox() {
|
|||
var x = n.pos.x, y = n.pos.y;
|
||||
|
||||
if ((sX < x && x < eX && sY < y && y < eY) || (sX > x && x > eX && sY > y && y > eY) || (sX > x && x > eX && sY < y && y < eY) || (sX < x && x < eX && sY > y && y > eY)) {
|
||||
selectNode(n);
|
||||
var nodeIsSelected = MetamapsModel.selectedNodes.indexOf(n);
|
||||
if (nodeIsSelected == -1) selectNode(n); // the node is not selected, so select it
|
||||
else if (nodeIsSelected != -1) deselectNode(n); // the node is selected, so deselect it
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -513,12 +512,13 @@ function onMouseMoveHandler(node, eventInfo, e) {
|
|||
|
||||
function onMouseEnter(edge) {
|
||||
$('canvas').css('cursor', 'pointer');
|
||||
var showDesc = edge.getData("showDesc");
|
||||
if (!showDesc) {
|
||||
var edgeIsSelected = MetamapsModel.selectedEdges.indexOf(edge);
|
||||
//following if statement only executes if the edge being hovered over is not selected
|
||||
if (edgeIsSelected == -1) {
|
||||
edge.setData('showDesc', true, 'current');
|
||||
edge.setDataset('end', {
|
||||
lineWidth: 4,
|
||||
color: '#222222',
|
||||
alpha: 1
|
||||
lineWidth: 4,
|
||||
alpha: 1
|
||||
});
|
||||
Mconsole.fx.animate({
|
||||
modes: ['edge-property:lineWidth:color:alpha'],
|
||||
|
@ -530,11 +530,12 @@ function onMouseEnter(edge) {
|
|||
|
||||
function onMouseLeave(edge) {
|
||||
$('canvas').css('cursor', 'default');
|
||||
var showDesc = edge.getData("showDesc");
|
||||
if (!showDesc) {
|
||||
var edgeIsSelected = MetamapsModel.selectedEdges.indexOf(edge);
|
||||
//following if statement only executes if the edge being hovered over is not selected
|
||||
if (edgeIsSelected == -1) {
|
||||
edge.setData('showDesc', false, 'current');
|
||||
edge.setDataset('end', {
|
||||
lineWidth: 2,
|
||||
color: '#222222',
|
||||
alpha: 0.4
|
||||
});
|
||||
Mconsole.fx.animate({
|
||||
|
@ -563,8 +564,10 @@ function onDragEndTopicHandler(node, eventInfo, e, allowRealtime) {
|
|||
tempNode2 = null;
|
||||
tempInit = false;
|
||||
} else if (dragged != 0 && goRealtime) {
|
||||
//TODO: dragged is invalid if multiple nodes were dragged
|
||||
saveLayout(dragged);
|
||||
saveLayout(dragged);
|
||||
for (var i = 0; i < MetamapsModel.selectedNodes.length; i++) {
|
||||
saveLayout(MetamapsModel.selectedNodes[i].id);
|
||||
}
|
||||
}
|
||||
}//onDragEndTopicHandler
|
||||
|
||||
|
|
|
@ -2614,12 +2614,17 @@ Extras.Classes.Navigation = new Class({
|
|||
|
||||
onMouseDown: function(e, win, eventInfo) {
|
||||
if(!this.config.panning) return;
|
||||
if(this.config.panning == 'avoid nodes' && eventInfo.getNode()) return;
|
||||
|
||||
//START METAMAPS CODE
|
||||
if((this.config.panning == 'avoid nodes' && eventInfo.getNode()) || eventInfo.getEdge()) return;
|
||||
// END METAMAPS CODE
|
||||
// ORIGINAl CODE if(this.config.panning == 'avoid nodes' && eventInfo.getNode()) return;
|
||||
this.pressed = true;
|
||||
//START METAMAPS CODE
|
||||
if (!MetamapsModel.boxStartCoordinates && e.shiftKey) {
|
||||
MetamapsModel.boxStartCoordinates = eventInfo.getPos();
|
||||
}
|
||||
MetamapsModel.didPan = false;
|
||||
// END METAMAPS CODE
|
||||
this.pos = eventInfo.getPos();
|
||||
var canvas = this.canvas,
|
||||
|
@ -2652,6 +2657,7 @@ Extras.Classes.Navigation = new Class({
|
|||
this.pressed = false;
|
||||
return;
|
||||
}
|
||||
MetamapsModel.didPan = true;
|
||||
// END METAMAPS CODE
|
||||
var thispos = this.pos,
|
||||
currentPos = eventInfo.getPos(),
|
||||
|
|
|
@ -272,12 +272,41 @@ function bindNameContainerCallbacks(nameContainer, node) {
|
|||
nameContainer.onmouseout = function(){
|
||||
$('.name.topic_' + node.id + ' .nodeOptions').css('display','none');
|
||||
}
|
||||
|
||||
var showCard = document.getElementById('showcard');
|
||||
|
||||
// add some events to the label
|
||||
$(nameContainer).find('.label').click(function(e){
|
||||
hideCurrentCard();
|
||||
|
||||
// set the diameter to full again for whatever node had its topic card showing
|
||||
if ( MetamapsModel.showcardInUse != null ) {
|
||||
currentOpenNode = Mconsole.graph.getNode(MetamapsModel.showcardInUse)
|
||||
currentOpenNode.setData('dim', 25, 'current');
|
||||
Mconsole.labels.hideLabel(currentOpenNode, true)
|
||||
Mconsole.plot();
|
||||
}
|
||||
|
||||
//populate the card that's about to show with the right topics data
|
||||
populateShowCard(node);
|
||||
|
||||
// positions the card in the right place
|
||||
var top = $('#' + node.id).css('top');
|
||||
var left = parseInt($('#' + node.id).css('left'));
|
||||
var w = $('#topic_' + node.id + '_label').width();
|
||||
w = w/2;
|
||||
left = (left + w) + 'px';
|
||||
$('#showcard').css('top', top);
|
||||
$('#showcard').css('left', left);
|
||||
|
||||
$('.showcard.topic_' + node.id).fadeIn('fast');
|
||||
node.setData('dim', 1, 'current');
|
||||
MetamapsModel.showcardInUse = node.id;
|
||||
Mconsole.plot();
|
||||
Mconsole.labels.hideLabel(Mconsole.graph.getNode(node.id));
|
||||
});
|
||||
}
|
||||
|
||||
function populateShowCard(node) {
|
||||
var showCard = document.getElementById('showcard');
|
||||
|
||||
showCard.innerHTML = '';
|
||||
|
||||
var html = generateShowcardHTML();
|
||||
|
@ -306,17 +335,20 @@ function bindNameContainerCallbacks(nameContainer, node) {
|
|||
|
||||
$(showCard).find('.best_in_place_name').bind("ajax:success", function() {
|
||||
var name = $(this).html();
|
||||
$(nameContainer).find('.label').html(name);
|
||||
$('#topic_' + node.id + '_label').find('.label').html(name);
|
||||
node.name = name;
|
||||
});
|
||||
|
||||
$(showCard).find('.best_in_place_desc').bind("ajax:success", function() {
|
||||
$(showCard).find('.scroll').mCustomScrollbar("update");
|
||||
var desc = $(this).html();
|
||||
node.setData("desc", desc);
|
||||
});
|
||||
|
||||
$(showCard).find('.best_in_place_link').bind("ajax:success", function() {
|
||||
var link = $(this).html();
|
||||
$(showCard).find('.go-link').attr('href', link);
|
||||
node.setData("link", link);
|
||||
});
|
||||
|
||||
$(showCard).find(".permActivator").bind('mouseover',
|
||||
|
@ -362,25 +394,13 @@ function bindNameContainerCallbacks(nameContainer, node) {
|
|||
if (permission == "commons") el.html("co");
|
||||
else if (permission == "public") el.html("pu");
|
||||
else if (permission == "private") el.html("pr");
|
||||
node.setData("permission", permission);
|
||||
});
|
||||
|
||||
var top = $('#' + node.id).css('top');
|
||||
var left = parseInt($('#' + node.id).css('left'));
|
||||
var w = $('#topic_' + node.id + '_label').width();
|
||||
w = w/2;
|
||||
left = (left + w) + 'px';
|
||||
$('#showcard').css('top', top);
|
||||
$('#showcard').css('left', left);
|
||||
|
||||
$('.showcard.topic_' + node.id).fadeIn('fast');
|
||||
$('.showcard.topic_' + node.id).find('.scroll').mCustomScrollbar();
|
||||
node.setData('dim', 1, 'current');
|
||||
MetamapsModel.showcardInUse = node.id;
|
||||
Mconsole.plot();
|
||||
Mconsole.labels.hideLabel(Mconsole.graph.getNode(node.id))
|
||||
// add some events to the label
|
||||
$(showCard).find('img.icon').click(function(){
|
||||
hideCard(node);
|
||||
});
|
||||
$('.showcard.topic_' + node.id).find('.scroll').mCustomScrollbar();
|
||||
|
||||
// add some events to the label
|
||||
$('.showcard').find('img.icon').click(function(){
|
||||
hideCard(node);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
function editEdge(edge, e) {
|
||||
if (authorizeToEdit(edge)) {
|
||||
//reset so we don't interfere with other edges
|
||||
//reset so we don't interfere with other edges, but first, save its x and y
|
||||
var myX = $('#edit_synapse').css('left');
|
||||
var myY = $('#edit_synapse').css('top');
|
||||
$('#edit_synapse').remove();
|
||||
|
||||
//so label is missing while editing
|
||||
|
@ -17,11 +19,19 @@ function editEdge(edge, e) {
|
|||
|
||||
//drop it in the right spot, activate it
|
||||
$('#edit_synapse').css('position', 'absolute');
|
||||
$('#edit_synapse').css('left', e.clientX);
|
||||
$('#edit_synapse').css('top', e.clientY);
|
||||
if (e) {
|
||||
$('#edit_synapse').css('left', e.clientX);
|
||||
$('#edit_synapse').css('top', e.clientY);
|
||||
}
|
||||
else {
|
||||
$('#edit_synapse').css('left', myX);
|
||||
$('#edit_synapse').css('top', myY);
|
||||
}
|
||||
//$('#edit_synapse_name').click(); //required in case name is empty
|
||||
//$('#edit_synapse_name input').focus();
|
||||
$('#edit_synapse').show();
|
||||
|
||||
MetamapsModel.edgecardInUse = edge.data.$id;
|
||||
}
|
||||
else if ((! authorizeToEdit(edge)) && userid) {
|
||||
alert("You don't have the permissions to edit this synapse.");
|
||||
|
@ -335,54 +345,49 @@ function deselectNode(node) {
|
|||
|
||||
function selectEdge(edge) {
|
||||
if (MetamapsModel.selectedEdges.indexOf(edge) != -1) return;
|
||||
var showDesc = edge.getData("showDesc");
|
||||
if (! showDesc) {
|
||||
edge.setData('showDesc', true, 'current');
|
||||
if ( ! MetamapsModel.embed) {
|
||||
edge.setDataset('end', {
|
||||
lineWidth: 4,
|
||||
color: '#FFFFFF',
|
||||
alpha: 1
|
||||
});
|
||||
} else if (MetamapsModel.embed) {
|
||||
edge.setDataset('end', {
|
||||
lineWidth: 4,
|
||||
color: '#999',
|
||||
alpha: 1
|
||||
});
|
||||
}
|
||||
Mconsole.fx.animate({
|
||||
modes: ['edge-property:lineWidth:color:alpha'],
|
||||
duration: 100
|
||||
edge.setData('showDesc', true, 'current');
|
||||
if ( ! MetamapsModel.embed) {
|
||||
edge.setDataset('end', {
|
||||
lineWidth: 4,
|
||||
color: '#FFFFFF',
|
||||
alpha: 1
|
||||
});
|
||||
} else if (MetamapsModel.embed) {
|
||||
edge.setDataset('end', {
|
||||
lineWidth: 4,
|
||||
color: '#999',
|
||||
alpha: 1
|
||||
});
|
||||
}
|
||||
Mconsole.fx.animate({
|
||||
modes: ['edge-property:lineWidth:color:alpha'],
|
||||
duration: 100
|
||||
});
|
||||
MetamapsModel.selectedEdges.push(edge);
|
||||
}
|
||||
|
||||
function deselectEdge(edge) {
|
||||
var showDesc = edge.getData("showDesc");
|
||||
if (showDesc) {
|
||||
edge.setData('showDesc', false, 'current');
|
||||
edge.setData('showDesc', false, 'current');
|
||||
edge.setDataset('end', {
|
||||
lineWidth: 2,
|
||||
color: '#222222',
|
||||
alpha: 0.4
|
||||
});
|
||||
|
||||
if (MetamapsModel.edgeHoveringOver == edge) {
|
||||
edge.setData('showDesc', true, 'current');
|
||||
edge.setDataset('end', {
|
||||
lineWidth: 2,
|
||||
lineWidth: 4,
|
||||
color: '#222222',
|
||||
alpha: 0.4
|
||||
});
|
||||
|
||||
if (MetamapsModel.edgeHoveringOver == edge) {
|
||||
edge.setDataset('end', {
|
||||
lineWidth: 4,
|
||||
color: '#222222',
|
||||
alpha: 1
|
||||
});
|
||||
}
|
||||
|
||||
Mconsole.fx.animate({
|
||||
modes: ['edge-property:lineWidth:color:alpha'],
|
||||
duration: 100
|
||||
alpha: 1
|
||||
});
|
||||
}
|
||||
|
||||
Mconsole.fx.animate({
|
||||
modes: ['edge-property:lineWidth:color:alpha'],
|
||||
duration: 100
|
||||
});
|
||||
|
||||
//remove the edge
|
||||
MetamapsModel.selectedEdges.splice(
|
||||
MetamapsModel.selectedEdges.indexOf(edge), 1);
|
||||
|
@ -409,6 +414,7 @@ function hideNode(nodeid) {
|
|||
});
|
||||
Mconsole.graph.removeNode(nodeid);
|
||||
Mconsole.labels.disposeLabel(nodeid);
|
||||
delete Mconsole.labels.labels["" + nodeid]
|
||||
}
|
||||
|
||||
function hideSelectedNodes() {
|
||||
|
|
BIN
app/assets/javascripts/WebSocketMain.swf
Normal file
BIN
app/assets/javascripts/WebSocketMain.swf
Normal file
Binary file not shown.
BIN
app/assets/javascripts/WebSocketMainInsecure.swf
Normal file
BIN
app/assets/javascripts/WebSocketMainInsecure.swf
Normal file
Binary file not shown.
5
app/assets/javascripts/app.js.coffee
Normal file
5
app/assets/javascripts/app.js.coffee
Normal file
|
@ -0,0 +1,5 @@
|
|||
$ () ->
|
||||
start = () ->
|
||||
window.app.realtime.connect();
|
||||
|
||||
start();
|
2
app/assets/javascripts/config.js.coffee
Normal file
2
app/assets/javascripts/config.js.coffee
Normal file
|
@ -0,0 +1,2 @@
|
|||
window.app =
|
||||
{}
|
|
@ -1,3 +1,70 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
window.app.addTopicToMap = (topic) ->
|
||||
Mconsole.graph.addNode(topic)
|
||||
tempForT = Mconsole.graph.getNode(topic.id)
|
||||
tempForT.setData('dim', 1, 'start')
|
||||
tempForT.setData('dim', 25, 'end')
|
||||
newPos = new $jit.Complex()
|
||||
newPos.x = tempForT.data.$xloc
|
||||
newPos.y = tempForT.data.$yloc
|
||||
tempForT.setPos(newPos, 'start')
|
||||
tempForT.setPos(newPos, 'current')
|
||||
tempForT.setPos(newPos, 'end')
|
||||
Mconsole.fx.plotNode(tempForT, Mconsole.canvas)
|
||||
Mconsole.labels.plotLabel(Mconsole.canvas, tempForT, Mconsole.config)
|
||||
|
||||
window.app.updateTopicOnMap = (topic) ->
|
||||
tempForT = Mconsole.graph.getNode(topic.id)
|
||||
|
||||
tempForT.data = topic.data
|
||||
tempForT.name = topic.name
|
||||
$('#topic_' + topic.id + '_label').find('.label').html(topic.name);
|
||||
|
||||
if MetamapsModel.showcardInUse == topic.id
|
||||
populateShowCard(tempForT)
|
||||
|
||||
newPos = new $jit.Complex()
|
||||
newPos.x = tempForT.data.$xloc
|
||||
newPos.y = tempForT.data.$yloc
|
||||
tempForT.setPos(newPos, 'start')
|
||||
tempForT.setPos(newPos, 'current')
|
||||
tempForT.setPos(newPos, 'end')
|
||||
|
||||
Mconsole.fx.animate({
|
||||
modes: ['linear','node-property:dim','edge-property:lineWidth'],
|
||||
transition: $jit.Trans.Quad.easeInOut,
|
||||
duration: 500
|
||||
})
|
||||
|
||||
window.app.addSynapseToMap = (synapse) ->
|
||||
Node1 = Mconsole.graph.getNode(synapse.data.$direction[0])
|
||||
Node2 = Mconsole.graph.getNode(synapse.data.$direction[1])
|
||||
Mconsole.graph.addAdjacence(Node1, Node2, {})
|
||||
tempForS = Mconsole.graph.getAdjacence(Node1.id, Node2.id)
|
||||
tempForS.setDataset('start', {
|
||||
lineWidth: 0.4
|
||||
})
|
||||
tempForS.setDataset('end', {
|
||||
lineWidth: 2
|
||||
})
|
||||
tempForS.data = synapse.data
|
||||
Mconsole.fx.plotLine(tempForS, Mconsole.canvas)
|
||||
Mconsole.fx.animate({
|
||||
modes: ['linear','node-property:dim','edge-property:lineWidth'],
|
||||
transition: $jit.Trans.Quad.easeInOut,
|
||||
duration: 500
|
||||
})
|
||||
|
||||
window.app.updateSynapseOnMap = (synapse) ->
|
||||
tempForS = Mconsole.graph.getAdjacence(synapse.data.$direction[0], synapse.data.$direction[1])
|
||||
|
||||
wasShowDesc = tempForS.data.$showDesc
|
||||
|
||||
for k,v of synapse.data
|
||||
tempForS.data[k] = v
|
||||
|
||||
tempForS.data.$showDesc = wasShowDesc
|
||||
|
||||
if MetamapsModel.edgecardInUse == synapse.data.$id
|
||||
editEdge(tempForS, false)
|
||||
|
||||
Mconsole.plot()
|
||||
|
|
6
app/assets/javascripts/realtime.js.coffee
Normal file
6
app/assets/javascripts/realtime.js.coffee
Normal file
|
@ -0,0 +1,6 @@
|
|||
window.app.realtime =
|
||||
connect : () ->
|
||||
window.app.socket = io.connect('http://localhost:5001');
|
||||
window.app.socket.on 'connect', () ->
|
||||
subscribeToRooms()
|
||||
console.log('socket connected')
|
3871
app/assets/javascripts/socket.io.js
Normal file
3871
app/assets/javascripts/socket.io.js
Normal file
File diff suppressed because one or more lines are too long
|
@ -42,6 +42,9 @@ class MappingsController < ApplicationController
|
|||
end
|
||||
end
|
||||
@mapping.save()
|
||||
|
||||
#push add to map to realtime viewers of the map
|
||||
@mapping.message 'create',@user.id
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -166,6 +166,7 @@ class MapsController < ApplicationController
|
|||
|
||||
# PUT maps/:id/savelayout
|
||||
def savelayout
|
||||
@user = current_user
|
||||
@map = Map.find(params[:id])
|
||||
|
||||
if params[:map][:coordinates]
|
||||
|
@ -178,6 +179,9 @@ class MapsController < ApplicationController
|
|||
@mapping.xloc = topic[1]
|
||||
@mapping.yloc = topic[2]
|
||||
@mapping.save
|
||||
|
||||
#push realtime update for location on map
|
||||
@mapping.message 'update',@user.id
|
||||
end
|
||||
end
|
||||
@map.arranged = true
|
||||
|
@ -185,27 +189,6 @@ class MapsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# GET maps/:id/realtime
|
||||
def realtime
|
||||
@current = current_user
|
||||
@map = Map.find(params[:id])
|
||||
|
||||
@time = params[:map][:time]
|
||||
@time = @time.to_i - 10
|
||||
|
||||
@topics = Array.new()
|
||||
@synapses = Array.new()
|
||||
@mappings = Array.new()
|
||||
# add code for finding deleted topics and sending the ids of those back to the client here
|
||||
@topics = @map.topics.select{|t| t.updated_at.to_i > @time}
|
||||
@synapses = @map.synapses.select{|t| t.updated_at.to_i > @time}
|
||||
@mappings = @map.mappings.select{|t| t.updated_at.to_i > @time && t.category == "Topic"}
|
||||
|
||||
respond_to do |format|
|
||||
format.js { respond_with(@map,@topics,@synapses,@mappings) }
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE maps/:id
|
||||
def destroy
|
||||
@map = Map.find(params[:id])
|
||||
|
|
|
@ -100,11 +100,14 @@ class SynapsesController < ApplicationController
|
|||
@mapping.synapse = @synapse
|
||||
@mapping.save
|
||||
|
||||
#push add to map to realtime viewers of the map
|
||||
@mapping.message 'create',@user.id
|
||||
|
||||
# set the permission of the synapse to whatever the permission of the
|
||||
#map is
|
||||
@synapse.permission = @map.permission
|
||||
@synapse.save
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { respond_with(@user, location: synapse_url(@synapse)) }
|
||||
|
@ -133,6 +136,8 @@ class SynapsesController < ApplicationController
|
|||
@synapse = Synapse.find(params[:id]).authorize_to_edit(@current)
|
||||
|
||||
if @synapse
|
||||
@permissionBefore = @synapse.permission
|
||||
|
||||
if params[:synapse]
|
||||
@synapse.desc = params[:synapse][:desc] if params[:synapse][:desc]
|
||||
@synapse.category = params[:synapse][:category] if params[:synapse][:category]
|
||||
|
@ -145,6 +150,18 @@ class SynapsesController < ApplicationController
|
|||
@synapse.topic2 = Topic.find(params[:node2_id][:node2])
|
||||
end
|
||||
@synapse.save
|
||||
|
||||
@permissionAfter = @synapse.permission
|
||||
|
||||
#push notify to anyone viewing this synapse on a map in realtime (see mapping.rb to understand the 'message' action)
|
||||
# if the topic was private and is being switched to PU or CO it is the same as being created for other viewers
|
||||
if @permissionBefore == "private" and @permissionAfter != "private"
|
||||
@synapse.message 'create',@current.id
|
||||
elsif @permissionBefore != "private" and @permissionAfter == "private"
|
||||
@synapse.message 'destroy',@current.id
|
||||
else
|
||||
@synapse.message 'update',@current.id
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
|
@ -155,7 +172,13 @@ class SynapsesController < ApplicationController
|
|||
|
||||
# POST mappings/:map_id/:synapse_id/removefrommap
|
||||
def removefrommap
|
||||
@user = current_user
|
||||
|
||||
@mapping = Mapping.find_by_synapse_id_and_map_id(params[:synapse_id],params[:map_id])
|
||||
|
||||
#push notify to anyone viewing same map in realtime (see mapping.rb to understand the 'message' action)
|
||||
@mapping.message 'destroy',@user.id
|
||||
|
||||
@mapping.delete
|
||||
|
||||
respond_to do |format|
|
||||
|
@ -169,6 +192,9 @@ class SynapsesController < ApplicationController
|
|||
@synapse = Synapse.find(params[:id]).authorize_to_edit(@current)
|
||||
|
||||
@synapse.mappings.each do |m|
|
||||
#push notify to anyone viewing same map in realtime (see mapping.rb to understand the 'message' action)
|
||||
m.message 'destroy',@current.id
|
||||
|
||||
m.delete
|
||||
end
|
||||
|
||||
|
|
|
@ -111,6 +111,9 @@ class TopicsController < ApplicationController
|
|||
@mapping.xloc = params[:topic][:x]
|
||||
@mapping.yloc = params[:topic][:y]
|
||||
@mapping.save
|
||||
|
||||
#push add to map to realtime viewers of the map
|
||||
@mapping.message 'create',@user.id
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
|
@ -138,13 +141,27 @@ class TopicsController < ApplicationController
|
|||
|
||||
if @topic
|
||||
if params[:topic]
|
||||
@permissionBefore = @topic.permission
|
||||
|
||||
@topic.name = params[:topic][:name] if params[:topic][:name]
|
||||
@topic.desc = params[:topic][:desc] if params[:topic][:desc]
|
||||
@topic.link = params[:topic][:link] if params[:topic][:link]
|
||||
@topic.permission = params[:topic][:permission] if params[:topic][:permission]
|
||||
@topic.metacode = Metacode.find_by_name(params[:topic][:metacode]) if params[:topic][:metacode]
|
||||
|
||||
@permissionAfter = @topic.permission
|
||||
end
|
||||
@topic.save
|
||||
|
||||
#push notify to anyone viewing this topic on a map in realtime (see mapping.rb to understand the 'message' action)
|
||||
# if the topic was private and is being switched to PU or CO it is the same as being created for other viewers
|
||||
if @permissionBefore == "private" and @permissionAfter != "private"
|
||||
@topic.message 'create',@current.id
|
||||
elsif @permissionBefore != "private" and @permissionAfter == "private"
|
||||
@topic.message 'destroy',@current.id
|
||||
else
|
||||
@topic.message 'update',@current.id
|
||||
end
|
||||
end
|
||||
|
||||
respond_with @topic
|
||||
|
@ -165,9 +182,17 @@ class TopicsController < ApplicationController
|
|||
end
|
||||
}
|
||||
@mappings.each do |m|
|
||||
|
||||
#push notify to anyone viewing same map in realtime (see mapping.rb to understand the 'message' action)
|
||||
m.message 'destroy',@current.id
|
||||
|
||||
m.delete
|
||||
end
|
||||
|
||||
|
||||
#push notify to anyone viewing same map in realtime (see mapping.rb to understand the 'message' action)
|
||||
@mapping.message 'destroy',@current.id
|
||||
|
||||
@mapping.delete
|
||||
|
||||
respond_to do |format|
|
||||
|
@ -185,10 +210,20 @@ class TopicsController < ApplicationController
|
|||
@mappings = @topic.mappings
|
||||
|
||||
@synapses.each do |synapse|
|
||||
synapse.mappings.each do |m|
|
||||
#push notify to anyone viewing same map in realtime (see mapping.rb to understand the 'message' action)
|
||||
m.message 'destroy',@current.id
|
||||
|
||||
m.delete
|
||||
end
|
||||
|
||||
synapse.delete
|
||||
end
|
||||
|
||||
@mappings.each do |mapping|
|
||||
#push notify to anyone viewing a map with this topic in realtime (see mapping.rb to understand the 'message' action)
|
||||
mapping.message 'destroy',@current.id
|
||||
|
||||
mapping.delete
|
||||
end
|
||||
|
||||
|
|
|
@ -5,4 +5,31 @@ belongs_to :synapse, :class_name => "Synapse", :foreign_key => "synapse_id"
|
|||
belongs_to :map, :class_name => "Map", :foreign_key => "map_id"
|
||||
|
||||
belongs_to :user
|
||||
|
||||
# sends push updates through redis to websockets for realtime updates
|
||||
def message action, origin_user_id
|
||||
if self.category == "Topic"
|
||||
|
||||
return if self.topic.permission == "private" and action == "create"
|
||||
|
||||
msg = { origin: origin_user_id,
|
||||
mapid: self.map.id,
|
||||
resource: self.category,
|
||||
action: action,
|
||||
id: self.topic.id,
|
||||
obj: self.topic.selfonmap_as_json(self.map.id).html_safe }
|
||||
elsif self.category == "Synapse"
|
||||
|
||||
return if self.synapse.permission == "private" and action == "create"
|
||||
|
||||
msg = { origin: origin_user_id,
|
||||
mapid: self.map.id,
|
||||
resource: self.category,
|
||||
action: action,
|
||||
id: self.synapse.id,
|
||||
obj: self.synapse.self_as_json.html_safe }
|
||||
end
|
||||
$redis.publish 'maps', msg.to_json
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -8,6 +8,25 @@ belongs_to :topic2, :class_name => "Topic", :foreign_key => "node2_id"
|
|||
has_many :mappings
|
||||
has_many :maps, :through => :mappings
|
||||
|
||||
# sends push updates through redis to websockets for realtime updates
|
||||
def message action, origin_user_id
|
||||
|
||||
return if self.permission == "private" and action == "create"
|
||||
|
||||
#get array of all maps topic appears in
|
||||
@maps = self.maps
|
||||
#sends update to all maps that topic appears in who have realtime on
|
||||
@maps.each do |map|
|
||||
msg = { origin: origin_user_id,
|
||||
mapid: map.id,
|
||||
resource: 'Synapse',
|
||||
action: action,
|
||||
id: self.id,
|
||||
obj: self.self_as_json.html_safe }
|
||||
$redis.publish 'maps', msg.to_json
|
||||
end
|
||||
end
|
||||
|
||||
##### JSON ######
|
||||
|
||||
def self_as_json
|
||||
|
|
|
@ -22,6 +22,25 @@ has_many :maps, :through => :mappings
|
|||
|
||||
belongs_to :metacode
|
||||
|
||||
# sends push updates through redis to websockets for realtime updates
|
||||
def message action, origin_user_id
|
||||
|
||||
return if self.permission == "private" and action == "create"
|
||||
|
||||
#get array of all maps topic appears in
|
||||
@maps = self.maps
|
||||
#sends update to all maps that topic appears in who have realtime on
|
||||
@maps.each do |map|
|
||||
msg = { origin: origin_user_id,
|
||||
mapid: map.id,
|
||||
resource: 'Topic',
|
||||
action: action,
|
||||
id: self.id,
|
||||
obj: self.selfonmap_as_json(map.id).html_safe }
|
||||
$redis.publish 'maps', msg.to_json
|
||||
end
|
||||
end
|
||||
|
||||
def topic_autocomplete_method
|
||||
"Get: #{self.name}"
|
||||
end
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
#%>
|
||||
|
||||
<div class="headertop">
|
||||
<% if false %>
|
||||
<button onclick="if (!goRealtime) { this.innerHTML = 'Stop Realtime'; } else if (goRealtime) { this.innerHTML = 'Start Realtime'; } goRealtime = !goRealtime;">Start Realtime</button>
|
||||
<% end %>
|
||||
<button onclick="hideSelectedEdges();hideSelectedNodes();">Hide Selected</button>
|
||||
<button onclick="enterKeyHandler();">Keep Selected</button>
|
||||
<% if authenticated? %>
|
||||
|
@ -52,13 +50,6 @@
|
|||
<%= render :partial => 'newsynapse' %>
|
||||
<%= render :partial => 'maps/new' %>
|
||||
<% end %>
|
||||
|
||||
<% if false %>
|
||||
<%= form_for @map, :url => realtime_path(@map), :method => "GET", :html => { :id => "MapRealtime"}, remote: true do |form| %>
|
||||
<%= form.hidden_field :time, :value => Time.now.to_i %>
|
||||
<%= form.hidden_field :ids, :value => 0 %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<script>
|
||||
var dragged = 0;
|
||||
|
@ -66,14 +57,7 @@
|
|||
<% if (@map.permission == "commons" && authenticated?) || @map.user == user %>
|
||||
mapperm = true;
|
||||
<% end %>
|
||||
/*var int = setInterval(function(){
|
||||
if (goRealtime) {
|
||||
$('#MapRealtime').submit();
|
||||
}
|
||||
},4000);*/
|
||||
</script>
|
||||
|
||||
<script>
|
||||
|
||||
viewMode = "graph";
|
||||
json = <%= @mapjson %>;
|
||||
if (json.length > 0) {
|
||||
|
@ -90,6 +74,47 @@
|
|||
initialize("chaotic", true);
|
||||
});
|
||||
}
|
||||
|
||||
function subscribeToRooms() {
|
||||
window.app.socket.on('maps-' + mapid, function(data) {
|
||||
//as long as you weren't the origin of the changes, update your map
|
||||
if (data.origin != userid && goRealtime) {
|
||||
if (data.resource == 'Topic') {
|
||||
topic = $.parseJSON(data.obj);
|
||||
|
||||
if (data.action == 'create') {
|
||||
window.app.addTopicToMap(topic);
|
||||
}
|
||||
else if (data.action == 'update' && Mconsole.graph.getNode(topic.id) != 'undefined') {
|
||||
window.app.updateTopicOnMap(topic);
|
||||
}
|
||||
else if (data.action == 'destroy' && Mconsole.graph.getNode(topic.id) != 'undefined') {
|
||||
hideNode(topic.id)
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (data.resource == 'Synapse') {
|
||||
synapse = $.parseJSON(data.obj);
|
||||
|
||||
if (data.action == 'create') {
|
||||
window.app.addSynapseToMap(synapse);
|
||||
}
|
||||
else if (data.action == 'update' &&
|
||||
Mconsole.graph.getAdjacence(synapse.data.$direction['0'], synapse.data.$direction['1']) != 'undefined') {
|
||||
window.app.updateSynapseOnMap(synapse);
|
||||
}
|
||||
else if (data.action == 'destroy' &&
|
||||
Mconsole.graph.getAdjacence(synapse.data.$direction['0'], synapse.data.$direction['1']) != 'undefined') {
|
||||
var edge = Mconsole.graph.getAdjacence(synapse.data.$direction['0'], synapse.data.$direction['1']);
|
||||
hideEdge(edge);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<%= render :partial => 'main/find' %>
|
||||
|
|
|
@ -25,6 +25,8 @@ if (Mconsole != null) {
|
|||
});
|
||||
Mconsole.graph.removeNode(<%= @topic.id %>);
|
||||
Mconsole.labels.disposeLabel(<%= @topic.id %>);
|
||||
delete Mconsole.labels.labels['<%= @topic.id %>']
|
||||
|
||||
}
|
||||
else {
|
||||
$('#<%= dom_id(@topic) %>').fadeOut('slow');
|
||||
|
|
|
@ -25,4 +25,5 @@ if (Mconsole != null) {
|
|||
});
|
||||
Mconsole.graph.removeNode(<%= @mapping.topic_id %>);
|
||||
Mconsole.labels.disposeLabel(<%= @mapping.topic_id %>);
|
||||
delete Mconsole.labels.labels['<%= @mapping.topic_id %>']
|
||||
}
|
||||
|
|
1
config/initializers/redis.rb
Normal file
1
config/initializers/redis.rb
Normal file
|
@ -0,0 +1 @@
|
|||
$redis = Redis.new(:host => 'localhost', :port=> 6379)
|
|
@ -11,7 +11,6 @@ ISSAD::Application.routes.draw do
|
|||
match 'search', to: 'main#search', via: :get, as: :search
|
||||
|
||||
match 'maps/:id/savelayout', to: 'maps#savelayout', via: :put, as: :savelayout
|
||||
match 'maps/:id/realtime', to: 'maps#realtime', via: :get, as: :realtime
|
||||
match 'topics/:map_id/:topic_id/removefrommap', to: 'topics#removefrommap', via: :post, as: :removefrommap
|
||||
match 'synapses/:map_id/:synapse_id/removefrommap', to: 'synapses#removefrommap', via: :post, as: :removefrommap
|
||||
|
||||
|
|
1
realtime/README.md
Normal file
1
realtime/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
'Real-Time'
|
1
realtime/node_modules/redis/.npmignore
generated
vendored
Normal file
1
realtime/node_modules/redis/.npmignore
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
node_modules
|
691
realtime/node_modules/redis/README.md
generated
vendored
Normal file
691
realtime/node_modules/redis/README.md
generated
vendored
Normal file
|
@ -0,0 +1,691 @@
|
|||
redis - a node.js redis client
|
||||
===========================
|
||||
|
||||
This is a complete Redis client for node.js. It supports all Redis commands, including many recently added commands like EVAL from
|
||||
experimental Redis server branches.
|
||||
|
||||
|
||||
Install with:
|
||||
|
||||
npm install redis
|
||||
|
||||
Pieter Noordhuis has provided a binding to the official `hiredis` C library, which is non-blocking and fast. To use `hiredis`, do:
|
||||
|
||||
npm install hiredis redis
|
||||
|
||||
If `hiredis` is installed, `node_redis` will use it by default. Otherwise, a pure JavaScript parser will be used.
|
||||
|
||||
If you use `hiredis`, be sure to rebuild it whenever you upgrade your version of node. There are mysterious failures that can
|
||||
happen between node and native code modules after a node upgrade.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
Simple example, included as `examples/simple.js`:
|
||||
|
||||
```js
|
||||
var redis = require("redis"),
|
||||
client = redis.createClient();
|
||||
|
||||
// if you'd like to select database 3, instead of 0 (default), call
|
||||
// client.select(3, function() { /* ... */ });
|
||||
|
||||
client.on("error", function (err) {
|
||||
console.log("Error " + err);
|
||||
});
|
||||
|
||||
client.set("string key", "string val", redis.print);
|
||||
client.hset("hash key", "hashtest 1", "some value", redis.print);
|
||||
client.hset(["hash key", "hashtest 2", "some other value"], redis.print);
|
||||
client.hkeys("hash key", function (err, replies) {
|
||||
console.log(replies.length + " replies:");
|
||||
replies.forEach(function (reply, i) {
|
||||
console.log(" " + i + ": " + reply);
|
||||
});
|
||||
client.quit();
|
||||
});
|
||||
```
|
||||
|
||||
This will display:
|
||||
|
||||
mjr:~/work/node_redis (master)$ node example.js
|
||||
Reply: OK
|
||||
Reply: 0
|
||||
Reply: 0
|
||||
2 replies:
|
||||
0: hashtest 1
|
||||
1: hashtest 2
|
||||
mjr:~/work/node_redis (master)$
|
||||
|
||||
|
||||
## Performance
|
||||
|
||||
Here are typical results of `multi_bench.js` which is similar to `redis-benchmark` from the Redis distribution.
|
||||
It uses 50 concurrent connections with no pipelining.
|
||||
|
||||
JavaScript parser:
|
||||
|
||||
PING: 20000 ops 42283.30 ops/sec 0/5/1.182
|
||||
SET: 20000 ops 32948.93 ops/sec 1/7/1.515
|
||||
GET: 20000 ops 28694.40 ops/sec 0/9/1.740
|
||||
INCR: 20000 ops 39370.08 ops/sec 0/8/1.269
|
||||
LPUSH: 20000 ops 36429.87 ops/sec 0/8/1.370
|
||||
LRANGE (10 elements): 20000 ops 9891.20 ops/sec 1/9/5.048
|
||||
LRANGE (100 elements): 20000 ops 1384.56 ops/sec 10/91/36.072
|
||||
|
||||
hiredis parser:
|
||||
|
||||
PING: 20000 ops 46189.38 ops/sec 1/4/1.082
|
||||
SET: 20000 ops 41237.11 ops/sec 0/6/1.210
|
||||
GET: 20000 ops 39682.54 ops/sec 1/7/1.257
|
||||
INCR: 20000 ops 40080.16 ops/sec 0/8/1.242
|
||||
LPUSH: 20000 ops 41152.26 ops/sec 0/3/1.212
|
||||
LRANGE (10 elements): 20000 ops 36563.07 ops/sec 1/8/1.363
|
||||
LRANGE (100 elements): 20000 ops 21834.06 ops/sec 0/9/2.287
|
||||
|
||||
The performance of `node_redis` improves dramatically with pipelining, which happens automatically in most normal programs.
|
||||
|
||||
|
||||
### Sending Commands
|
||||
|
||||
Each Redis command is exposed as a function on the `client` object.
|
||||
All functions take either an `args` Array plus optional `callback` Function or
|
||||
a variable number of individual arguments followed by an optional callback.
|
||||
Here is an example of passing an array of arguments and a callback:
|
||||
|
||||
client.mset(["test keys 1", "test val 1", "test keys 2", "test val 2"], function (err, res) {});
|
||||
|
||||
Here is that same call in the second style:
|
||||
|
||||
client.mset("test keys 1", "test val 1", "test keys 2", "test val 2", function (err, res) {});
|
||||
|
||||
Note that in either form the `callback` is optional:
|
||||
|
||||
client.set("some key", "some val");
|
||||
client.set(["some other key", "some val"]);
|
||||
|
||||
If the key is missing, reply will be null (probably):
|
||||
|
||||
client.get("missingkey", function(err, reply) {
|
||||
// reply is null when the key is missing
|
||||
console.log(reply);
|
||||
});
|
||||
|
||||
For a list of Redis commands, see [Redis Command Reference](http://redis.io/commands)
|
||||
|
||||
The commands can be specified in uppercase or lowercase for convenience. `client.get()` is the same as `client.GET()`.
|
||||
|
||||
Minimal parsing is done on the replies. Commands that return a single line reply return JavaScript Strings,
|
||||
integer replies return JavaScript Numbers, "bulk" replies return node Buffers, and "multi bulk" replies return a
|
||||
JavaScript Array of node Buffers. `HGETALL` returns an Object with Buffers keyed by the hash keys.
|
||||
|
||||
# API
|
||||
|
||||
## Connection Events
|
||||
|
||||
`client` will emit some events about the state of the connection to the Redis server.
|
||||
|
||||
### "ready"
|
||||
|
||||
`client` will emit `ready` a connection is established to the Redis server and the server reports
|
||||
that it is ready to receive commands. Commands issued before the `ready` event are queued,
|
||||
then replayed just before this event is emitted.
|
||||
|
||||
### "connect"
|
||||
|
||||
`client` will emit `connect` at the same time as it emits `ready` unless `client.options.no_ready_check`
|
||||
is set. If this options is set, `connect` will be emitted when the stream is connected, and then
|
||||
you are free to try to send commands.
|
||||
|
||||
### "error"
|
||||
|
||||
`client` will emit `error` when encountering an error connecting to the Redis server.
|
||||
|
||||
Note that "error" is a special event type in node. If there are no listeners for an
|
||||
"error" event, node will exit. This is usually what you want, but it can lead to some
|
||||
cryptic error messages like this:
|
||||
|
||||
mjr:~/work/node_redis (master)$ node example.js
|
||||
|
||||
node.js:50
|
||||
throw e;
|
||||
^
|
||||
Error: ECONNREFUSED, Connection refused
|
||||
at IOWatcher.callback (net:870:22)
|
||||
at node.js:607:9
|
||||
|
||||
Not very useful in diagnosing the problem, but if your program isn't ready to handle this,
|
||||
it is probably the right thing to just exit.
|
||||
|
||||
`client` will also emit `error` if an exception is thrown inside of `node_redis` for whatever reason.
|
||||
It would be nice to distinguish these two cases.
|
||||
|
||||
### "end"
|
||||
|
||||
`client` will emit `end` when an established Redis server connection has closed.
|
||||
|
||||
### "drain"
|
||||
|
||||
`client` will emit `drain` when the TCP connection to the Redis server has been buffering, but is now
|
||||
writable. This event can be used to stream commands in to Redis and adapt to backpressure. Right now,
|
||||
you need to check `client.command_queue.length` to decide when to reduce your send rate. Then you can
|
||||
resume sending when you get `drain`.
|
||||
|
||||
### "idle"
|
||||
|
||||
`client` will emit `idle` when there are no outstanding commands that are awaiting a response.
|
||||
|
||||
## redis.createClient(port, host, options)
|
||||
|
||||
Create a new client connection. `port` defaults to `6379` and `host` defaults
|
||||
to `127.0.0.1`. If you have `redis-server` running on the same computer as node, then the defaults for
|
||||
port and host are probably fine. `options` in an object with the following possible properties:
|
||||
|
||||
* `parser`: which Redis protocol reply parser to use. Defaults to `hiredis` if that module is installed.
|
||||
This may also be set to `javascript`.
|
||||
* `return_buffers`: defaults to `false`. If set to `true`, then all replies will be sent to callbacks as node Buffer
|
||||
objects instead of JavaScript Strings.
|
||||
* `detect_buffers`: default to `false`. If set to `true`, then replies will be sent to callbacks as node Buffer objects
|
||||
if any of the input arguments to the original command were Buffer objects.
|
||||
This option lets you switch between Buffers and Strings on a per-command basis, whereas `return_buffers` applies to
|
||||
every command on a client.
|
||||
* `socket_nodelay`: defaults to `true`. Whether to call setNoDelay() on the TCP stream, which disables the
|
||||
Nagle algorithm on the underlying socket. Setting this option to `false` can result in additional throughput at the
|
||||
cost of more latency. Most applications will want this set to `true`.
|
||||
* `no_ready_check`: defaults to `false`. When a connection is established to the Redis server, the server might still
|
||||
be loading the database from disk. While loading, the server not respond to any commands. To work around this,
|
||||
`node_redis` has a "ready check" which sends the `INFO` command to the server. The response from the `INFO` command
|
||||
indicates whether the server is ready for more commands. When ready, `node_redis` emits a `ready` event.
|
||||
Setting `no_ready_check` to `true` will inhibit this check.
|
||||
* `enable_offline_queue`: defaults to `true`. By default, if there is no active
|
||||
connection to the redis server, commands are added to a queue and are executed
|
||||
once the connection has been established. Setting `enable_offline_queue` to
|
||||
`false` will disable this feature and the callback will be execute immediately
|
||||
with an error, or an error will be thrown if no callback is specified.
|
||||
|
||||
```js
|
||||
var redis = require("redis"),
|
||||
client = redis.createClient(null, null, {detect_buffers: true});
|
||||
|
||||
client.set("foo_rand000000000000", "OK");
|
||||
|
||||
// This will return a JavaScript String
|
||||
client.get("foo_rand000000000000", function (err, reply) {
|
||||
console.log(reply.toString()); // Will print `OK`
|
||||
});
|
||||
|
||||
// This will return a Buffer since original key is specified as a Buffer
|
||||
client.get(new Buffer("foo_rand000000000000"), function (err, reply) {
|
||||
console.log(reply.toString()); // Will print `<Buffer 4f 4b>`
|
||||
});
|
||||
client.end();
|
||||
```
|
||||
|
||||
`createClient()` returns a `RedisClient` object that is named `client` in all of the examples here.
|
||||
|
||||
## client.auth(password, callback)
|
||||
|
||||
When connecting to Redis servers that require authentication, the `AUTH` command must be sent as the
|
||||
first command after connecting. This can be tricky to coordinate with reconnections, the ready check,
|
||||
etc. To make this easier, `client.auth()` stashes `password` and will send it after each connection,
|
||||
including reconnections. `callback` is invoked only once, after the response to the very first
|
||||
`AUTH` command sent.
|
||||
NOTE: Your call to `client.auth()` should not be inside the ready handler. If
|
||||
you are doing this wrong, `client` will emit an error that looks
|
||||
something like this `Error: Ready check failed: ERR operation not permitted`.
|
||||
|
||||
## client.end()
|
||||
|
||||
Forcibly close the connection to the Redis server. Note that this does not wait until all replies have been parsed.
|
||||
If you want to exit cleanly, call `client.quit()` to send the `QUIT` command after you have handled all replies.
|
||||
|
||||
This example closes the connection to the Redis server before the replies have been read. You probably don't
|
||||
want to do this:
|
||||
|
||||
```js
|
||||
var redis = require("redis"),
|
||||
client = redis.createClient();
|
||||
|
||||
client.set("foo_rand000000000000", "some fantastic value");
|
||||
client.get("foo_rand000000000000", function (err, reply) {
|
||||
console.log(reply.toString());
|
||||
});
|
||||
client.end();
|
||||
```
|
||||
|
||||
`client.end()` is useful for timeout cases where something is stuck or taking too long and you want
|
||||
to start over.
|
||||
|
||||
## Friendlier hash commands
|
||||
|
||||
Most Redis commands take a single String or an Array of Strings as arguments, and replies are sent back as a single String or an Array of Strings.
|
||||
When dealing with hash values, there are a couple of useful exceptions to this.
|
||||
|
||||
### client.hgetall(hash)
|
||||
|
||||
The reply from an HGETALL command will be converted into a JavaScript Object by `node_redis`. That way you can interact
|
||||
with the responses using JavaScript syntax.
|
||||
|
||||
Example:
|
||||
|
||||
client.hmset("hosts", "mjr", "1", "another", "23", "home", "1234");
|
||||
client.hgetall("hosts", function (err, obj) {
|
||||
console.dir(obj);
|
||||
});
|
||||
|
||||
Output:
|
||||
|
||||
{ mjr: '1', another: '23', home: '1234' }
|
||||
|
||||
### client.hmset(hash, obj, [callback])
|
||||
|
||||
Multiple values in a hash can be set by supplying an object:
|
||||
|
||||
client.HMSET(key2, {
|
||||
"0123456789": "abcdefghij", // NOTE: the key and value must both be strings
|
||||
"some manner of key": "a type of value"
|
||||
});
|
||||
|
||||
The properties and values of this Object will be set as keys and values in the Redis hash.
|
||||
|
||||
### client.hmset(hash, key1, val1, ... keyn, valn, [callback])
|
||||
|
||||
Multiple values may also be set by supplying a list:
|
||||
|
||||
client.HMSET(key1, "0123456789", "abcdefghij", "some manner of key", "a type of value");
|
||||
|
||||
|
||||
## Publish / Subscribe
|
||||
|
||||
Here is a simple example of the API for publish / subscribe. This program opens two
|
||||
client connections, subscribes to a channel on one of them, and publishes to that
|
||||
channel on the other:
|
||||
|
||||
```js
|
||||
var redis = require("redis"),
|
||||
client1 = redis.createClient(), client2 = redis.createClient(),
|
||||
msg_count = 0;
|
||||
|
||||
client1.on("subscribe", function (channel, count) {
|
||||
client2.publish("a nice channel", "I am sending a message.");
|
||||
client2.publish("a nice channel", "I am sending a second message.");
|
||||
client2.publish("a nice channel", "I am sending my last message.");
|
||||
});
|
||||
|
||||
client1.on("message", function (channel, message) {
|
||||
console.log("client1 channel " + channel + ": " + message);
|
||||
msg_count += 1;
|
||||
if (msg_count === 3) {
|
||||
client1.unsubscribe();
|
||||
client1.end();
|
||||
client2.end();
|
||||
}
|
||||
});
|
||||
|
||||
client1.incr("did a thing");
|
||||
client1.subscribe("a nice channel");
|
||||
```
|
||||
|
||||
When a client issues a `SUBSCRIBE` or `PSUBSCRIBE`, that connection is put into "pub/sub" mode.
|
||||
At that point, only commands that modify the subscription set are valid. When the subscription
|
||||
set is empty, the connection is put back into regular mode.
|
||||
|
||||
If you need to send regular commands to Redis while in pub/sub mode, just open another connection.
|
||||
|
||||
## Pub / Sub Events
|
||||
|
||||
If a client has subscriptions active, it may emit these events:
|
||||
|
||||
### "message" (channel, message)
|
||||
|
||||
Client will emit `message` for every message received that matches an active subscription.
|
||||
Listeners are passed the channel name as `channel` and the message Buffer as `message`.
|
||||
|
||||
### "pmessage" (pattern, channel, message)
|
||||
|
||||
Client will emit `pmessage` for every message received that matches an active subscription pattern.
|
||||
Listeners are passed the original pattern used with `PSUBSCRIBE` as `pattern`, the sending channel
|
||||
name as `channel`, and the message Buffer as `message`.
|
||||
|
||||
### "subscribe" (channel, count)
|
||||
|
||||
Client will emit `subscribe` in response to a `SUBSCRIBE` command. Listeners are passed the
|
||||
channel name as `channel` and the new count of subscriptions for this client as `count`.
|
||||
|
||||
### "psubscribe" (pattern, count)
|
||||
|
||||
Client will emit `psubscribe` in response to a `PSUBSCRIBE` command. Listeners are passed the
|
||||
original pattern as `pattern`, and the new count of subscriptions for this client as `count`.
|
||||
|
||||
### "unsubscribe" (channel, count)
|
||||
|
||||
Client will emit `unsubscribe` in response to a `UNSUBSCRIBE` command. Listeners are passed the
|
||||
channel name as `channel` and the new count of subscriptions for this client as `count`. When
|
||||
`count` is 0, this client has left pub/sub mode and no more pub/sub events will be emitted.
|
||||
|
||||
### "punsubscribe" (pattern, count)
|
||||
|
||||
Client will emit `punsubscribe` in response to a `PUNSUBSCRIBE` command. Listeners are passed the
|
||||
channel name as `channel` and the new count of subscriptions for this client as `count`. When
|
||||
`count` is 0, this client has left pub/sub mode and no more pub/sub events will be emitted.
|
||||
|
||||
## client.multi([commands])
|
||||
|
||||
`MULTI` commands are queued up until an `EXEC` is issued, and then all commands are run atomically by
|
||||
Redis. The interface in `node_redis` is to return an individual `Multi` object by calling `client.multi()`.
|
||||
|
||||
```js
|
||||
var redis = require("./index"),
|
||||
client = redis.createClient(), set_size = 20;
|
||||
|
||||
client.sadd("bigset", "a member");
|
||||
client.sadd("bigset", "another member");
|
||||
|
||||
while (set_size > 0) {
|
||||
client.sadd("bigset", "member " + set_size);
|
||||
set_size -= 1;
|
||||
}
|
||||
|
||||
// multi chain with an individual callback
|
||||
client.multi()
|
||||
.scard("bigset")
|
||||
.smembers("bigset")
|
||||
.keys("*", function (err, replies) {
|
||||
// NOTE: code in this callback is NOT atomic
|
||||
// this only happens after the the .exec call finishes.
|
||||
client.mget(replies, redis.print);
|
||||
})
|
||||
.dbsize()
|
||||
.exec(function (err, replies) {
|
||||
console.log("MULTI got " + replies.length + " replies");
|
||||
replies.forEach(function (reply, index) {
|
||||
console.log("Reply " + index + ": " + reply.toString());
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
`client.multi()` is a constructor that returns a `Multi` object. `Multi` objects share all of the
|
||||
same command methods as `client` objects do. Commands are queued up inside the `Multi` object
|
||||
until `Multi.exec()` is invoked.
|
||||
|
||||
You can either chain together `MULTI` commands as in the above example, or you can queue individual
|
||||
commands while still sending regular client command as in this example:
|
||||
|
||||
```js
|
||||
var redis = require("redis"),
|
||||
client = redis.createClient(), multi;
|
||||
|
||||
// start a separate multi command queue
|
||||
multi = client.multi();
|
||||
multi.incr("incr thing", redis.print);
|
||||
multi.incr("incr other thing", redis.print);
|
||||
|
||||
// runs immediately
|
||||
client.mset("incr thing", 100, "incr other thing", 1, redis.print);
|
||||
|
||||
// drains multi queue and runs atomically
|
||||
multi.exec(function (err, replies) {
|
||||
console.log(replies); // 101, 2
|
||||
});
|
||||
|
||||
// you can re-run the same transaction if you like
|
||||
multi.exec(function (err, replies) {
|
||||
console.log(replies); // 102, 3
|
||||
client.quit();
|
||||
});
|
||||
```
|
||||
|
||||
In addition to adding commands to the `MULTI` queue individually, you can also pass an array
|
||||
of commands and arguments to the constructor:
|
||||
|
||||
```js
|
||||
var redis = require("redis"),
|
||||
client = redis.createClient(), multi;
|
||||
|
||||
client.multi([
|
||||
["mget", "multifoo", "multibar", redis.print],
|
||||
["incr", "multifoo"],
|
||||
["incr", "multibar"]
|
||||
]).exec(function (err, replies) {
|
||||
console.log(replies);
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
## Monitor mode
|
||||
|
||||
Redis supports the `MONITOR` command, which lets you see all commands received by the Redis server
|
||||
across all client connections, including from other client libraries and other computers.
|
||||
|
||||
After you send the `MONITOR` command, no other commands are valid on that connection. `node_redis`
|
||||
will emit a `monitor` event for every new monitor message that comes across. The callback for the
|
||||
`monitor` event takes a timestamp from the Redis server and an array of command arguments.
|
||||
|
||||
Here is a simple example:
|
||||
|
||||
```js
|
||||
var client = require("redis").createClient(),
|
||||
util = require("util");
|
||||
|
||||
client.monitor(function (err, res) {
|
||||
console.log("Entering monitoring mode.");
|
||||
});
|
||||
|
||||
client.on("monitor", function (time, args) {
|
||||
console.log(time + ": " + util.inspect(args));
|
||||
});
|
||||
```
|
||||
|
||||
# Extras
|
||||
|
||||
Some other things you might like to know about.
|
||||
|
||||
## client.server_info
|
||||
|
||||
After the ready probe completes, the results from the INFO command are saved in the `client.server_info`
|
||||
object.
|
||||
|
||||
The `versions` key contains an array of the elements of the version string for easy comparison.
|
||||
|
||||
> client.server_info.redis_version
|
||||
'2.3.0'
|
||||
> client.server_info.versions
|
||||
[ 2, 3, 0 ]
|
||||
|
||||
## redis.print()
|
||||
|
||||
A handy callback function for displaying return values when testing. Example:
|
||||
|
||||
```js
|
||||
var redis = require("redis"),
|
||||
client = redis.createClient();
|
||||
|
||||
client.on("connect", function () {
|
||||
client.set("foo_rand000000000000", "some fantastic value", redis.print);
|
||||
client.get("foo_rand000000000000", redis.print);
|
||||
});
|
||||
```
|
||||
|
||||
This will print:
|
||||
|
||||
Reply: OK
|
||||
Reply: some fantastic value
|
||||
|
||||
Note that this program will not exit cleanly because the client is still connected.
|
||||
|
||||
## redis.debug_mode
|
||||
|
||||
Boolean to enable debug mode and protocol tracing.
|
||||
|
||||
```js
|
||||
var redis = require("redis"),
|
||||
client = redis.createClient();
|
||||
|
||||
redis.debug_mode = true;
|
||||
|
||||
client.on("connect", function () {
|
||||
client.set("foo_rand000000000000", "some fantastic value");
|
||||
});
|
||||
```
|
||||
|
||||
This will display:
|
||||
|
||||
mjr:~/work/node_redis (master)$ node ~/example.js
|
||||
send command: *3
|
||||
$3
|
||||
SET
|
||||
$20
|
||||
foo_rand000000000000
|
||||
$20
|
||||
some fantastic value
|
||||
|
||||
on_data: +OK
|
||||
|
||||
`send command` is data sent into Redis and `on_data` is data received from Redis.
|
||||
|
||||
## client.send_command(command_name, args, callback)
|
||||
|
||||
Used internally to send commands to Redis. For convenience, nearly all commands that are published on the Redis
|
||||
Wiki have been added to the `client` object. However, if I missed any, or if new commands are introduced before
|
||||
this library is updated, you can use `send_command()` to send arbitrary commands to Redis.
|
||||
|
||||
All commands are sent as multi-bulk commands. `args` can either be an Array of arguments, or omitted.
|
||||
|
||||
## client.connected
|
||||
|
||||
Boolean tracking the state of the connection to the Redis server.
|
||||
|
||||
## client.command_queue.length
|
||||
|
||||
The number of commands that have been sent to the Redis server but not yet replied to. You can use this to
|
||||
enforce some kind of maximum queue depth for commands while connected.
|
||||
|
||||
Don't mess with `client.command_queue` though unless you really know what you are doing.
|
||||
|
||||
## client.offline_queue.length
|
||||
|
||||
The number of commands that have been queued up for a future connection. You can use this to enforce
|
||||
some kind of maximum queue depth for pre-connection commands.
|
||||
|
||||
## client.retry_delay
|
||||
|
||||
Current delay in milliseconds before a connection retry will be attempted. This starts at `250`.
|
||||
|
||||
## client.retry_backoff
|
||||
|
||||
Multiplier for future retry timeouts. This should be larger than 1 to add more time between retries.
|
||||
Defaults to 1.7. The default initial connection retry is 250, so the second retry will be 425, followed by 723.5, etc.
|
||||
|
||||
### Commands with Optional and Keyword arguments
|
||||
|
||||
This applies to anything that uses an optional `[WITHSCORES]` or `[LIMIT offset count]` in the [redis.io/commands](http://redis.io/commands) documentation.
|
||||
|
||||
Example:
|
||||
```js
|
||||
var args = [ 'myzset', 1, 'one', 2, 'two', 3, 'three', 99, 'ninety-nine' ];
|
||||
client.zadd(args, function (err, response) {
|
||||
if (err) throw err;
|
||||
console.log('added '+response+' items.');
|
||||
|
||||
// -Infinity and +Infinity also work
|
||||
var args1 = [ 'myzset', '+inf', '-inf' ];
|
||||
client.zrevrangebyscore(args1, function (err, response) {
|
||||
if (err) throw err;
|
||||
console.log('example1', response);
|
||||
// write your code here
|
||||
});
|
||||
|
||||
var max = 3, min = 1, offset = 1, count = 2;
|
||||
var args2 = [ 'myzset', max, min, 'WITHSCORES', 'LIMIT', offset, count ];
|
||||
client.zrevrangebyscore(args2, function (err, response) {
|
||||
if (err) throw err;
|
||||
console.log('example2', response);
|
||||
// write your code here
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
||||
Better tests for auth, disconnect/reconnect, and all combinations thereof.
|
||||
|
||||
Stream large set/get values into and out of Redis. Otherwise the entire value must be in node's memory.
|
||||
|
||||
Performance can be better for very large values.
|
||||
|
||||
I think there are more performance improvements left in there for smaller values, especially for large lists of small values.
|
||||
|
||||
## How to Contribute
|
||||
- open a pull request and then wait for feedback (if
|
||||
[DTrejo](http://github.com/dtrejo) does not get back to you within 2 days,
|
||||
comment again with indignation!)
|
||||
|
||||
## Contributors
|
||||
Some people have have added features and fixed bugs in `node_redis` other than me.
|
||||
|
||||
Ordered by date of first contribution.
|
||||
[Auto-generated](http://github.com/dtrejo/node-authors) on Wed Jul 25 2012 19:14:59 GMT-0700 (PDT).
|
||||
|
||||
- [Matt Ranney aka `mranney`](https://github.com/mranney)
|
||||
- [Tim-Smart aka `tim-smart`](https://github.com/tim-smart)
|
||||
- [Tj Holowaychuk aka `visionmedia`](https://github.com/visionmedia)
|
||||
- [rick aka `technoweenie`](https://github.com/technoweenie)
|
||||
- [Orion Henry aka `orionz`](https://github.com/orionz)
|
||||
- [Aivo Paas aka `aivopaas`](https://github.com/aivopaas)
|
||||
- [Hank Sims aka `hanksims`](https://github.com/hanksims)
|
||||
- [Paul Carey aka `paulcarey`](https://github.com/paulcarey)
|
||||
- [Pieter Noordhuis aka `pietern`](https://github.com/pietern)
|
||||
- [nithesh aka `nithesh`](https://github.com/nithesh)
|
||||
- [Andy Ray aka `andy2ray`](https://github.com/andy2ray)
|
||||
- [unknown aka `unknowdna`](https://github.com/unknowdna)
|
||||
- [Dave Hoover aka `redsquirrel`](https://github.com/redsquirrel)
|
||||
- [Vladimir Dronnikov aka `dvv`](https://github.com/dvv)
|
||||
- [Umair Siddique aka `umairsiddique`](https://github.com/umairsiddique)
|
||||
- [Louis-Philippe Perron aka `lp`](https://github.com/lp)
|
||||
- [Mark Dawson aka `markdaws`](https://github.com/markdaws)
|
||||
- [Ian Babrou aka `bobrik`](https://github.com/bobrik)
|
||||
- [Felix Geisendörfer aka `felixge`](https://github.com/felixge)
|
||||
- [Jean-Hugues Pinson aka `undefined`](https://github.com/undefined)
|
||||
- [Maksim Lin aka `maks`](https://github.com/maks)
|
||||
- [Owen Smith aka `orls`](https://github.com/orls)
|
||||
- [Zachary Scott aka `zzak`](https://github.com/zzak)
|
||||
- [TEHEK Firefox aka `TEHEK`](https://github.com/TEHEK)
|
||||
- [Isaac Z. Schlueter aka `isaacs`](https://github.com/isaacs)
|
||||
- [David Trejo aka `DTrejo`](https://github.com/DTrejo)
|
||||
- [Brian Noguchi aka `bnoguchi`](https://github.com/bnoguchi)
|
||||
- [Philip Tellis aka `bluesmoon`](https://github.com/bluesmoon)
|
||||
- [Marcus Westin aka `marcuswestin2`](https://github.com/marcuswestin2)
|
||||
- [Jed Schmidt aka `jed`](https://github.com/jed)
|
||||
- [Dave Peticolas aka `jdavisp3`](https://github.com/jdavisp3)
|
||||
- [Trae Robrock aka `trobrock`](https://github.com/trobrock)
|
||||
- [Shankar Karuppiah aka `shankar0306`](https://github.com/shankar0306)
|
||||
- [Ignacio Burgueño aka `ignacio`](https://github.com/ignacio)
|
||||
|
||||
Thanks.
|
||||
|
||||
## LICENSE - "MIT License"
|
||||
|
||||
Copyright (c) 2010 Matthew Ranney, http://ranney.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
![spacer](http://ranney.com/1px.gif)
|
89
realtime/node_modules/redis/benches/buffer_bench.js
generated
vendored
Normal file
89
realtime/node_modules/redis/benches/buffer_bench.js
generated
vendored
Normal file
|
@ -0,0 +1,89 @@
|
|||
var source = new Buffer(100),
|
||||
dest = new Buffer(100), i, j, k, tmp, count = 1000000, bytes = 100;
|
||||
|
||||
for (i = 99 ; i >= 0 ; i--) {
|
||||
source[i] = 120;
|
||||
}
|
||||
|
||||
var str = "This is a nice String.",
|
||||
buf = new Buffer("This is a lovely Buffer.");
|
||||
|
||||
var start = new Date();
|
||||
for (i = count * 100; i > 0 ; i--) {
|
||||
if (Buffer.isBuffer(str)) {}
|
||||
}
|
||||
var end = new Date();
|
||||
console.log("Buffer.isBuffer(str) " + (end - start) + " ms");
|
||||
|
||||
var start = new Date();
|
||||
for (i = count * 100; i > 0 ; i--) {
|
||||
if (Buffer.isBuffer(buf)) {}
|
||||
}
|
||||
var end = new Date();
|
||||
console.log("Buffer.isBuffer(buf) " + (end - start) + " ms");
|
||||
|
||||
var start = new Date();
|
||||
for (i = count * 100; i > 0 ; i--) {
|
||||
if (str instanceof Buffer) {}
|
||||
}
|
||||
var end = new Date();
|
||||
console.log("str instanceof Buffer " + (end - start) + " ms");
|
||||
|
||||
var start = new Date();
|
||||
for (i = count * 100; i > 0 ; i--) {
|
||||
if (buf instanceof Buffer) {}
|
||||
}
|
||||
var end = new Date();
|
||||
console.log("buf instanceof Buffer " + (end - start) + " ms");
|
||||
|
||||
for (i = bytes ; i > 0 ; i --) {
|
||||
var start = new Date();
|
||||
for (j = count ; j > 0; j--) {
|
||||
tmp = source.toString("ascii", 0, bytes);
|
||||
}
|
||||
var end = new Date();
|
||||
console.log("toString() " + i + " bytes " + (end - start) + " ms");
|
||||
}
|
||||
|
||||
for (i = bytes ; i > 0 ; i --) {
|
||||
var start = new Date();
|
||||
for (j = count ; j > 0; j--) {
|
||||
tmp = "";
|
||||
for (k = 0; k <= i ; k++) {
|
||||
tmp += String.fromCharCode(source[k]);
|
||||
}
|
||||
}
|
||||
var end = new Date();
|
||||
console.log("manual string " + i + " bytes " + (end - start) + " ms");
|
||||
}
|
||||
|
||||
for (i = bytes ; i > 0 ; i--) {
|
||||
var start = new Date();
|
||||
for (j = count ; j > 0 ; j--) {
|
||||
for (k = i ; k > 0 ; k--) {
|
||||
dest[k] = source[k];
|
||||
}
|
||||
}
|
||||
var end = new Date();
|
||||
console.log("Manual copy " + i + " bytes " + (end - start) + " ms");
|
||||
}
|
||||
|
||||
for (i = bytes ; i > 0 ; i--) {
|
||||
var start = new Date();
|
||||
for (j = count ; j > 0 ; j--) {
|
||||
for (k = i ; k > 0 ; k--) {
|
||||
dest[k] = 120;
|
||||
}
|
||||
}
|
||||
var end = new Date();
|
||||
console.log("Direct assignment " + i + " bytes " + (end - start) + " ms");
|
||||
}
|
||||
|
||||
for (i = bytes ; i > 0 ; i--) {
|
||||
var start = new Date();
|
||||
for (j = count ; j > 0 ; j--) {
|
||||
source.copy(dest, 0, 0, i);
|
||||
}
|
||||
var end = new Date();
|
||||
console.log("Buffer.copy() " + i + " bytes " + (end - start) + " ms");
|
||||
}
|
38
realtime/node_modules/redis/benches/hiredis_parser.js
generated
vendored
Normal file
38
realtime/node_modules/redis/benches/hiredis_parser.js
generated
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
var Parser = require('../lib/parser/hiredis').Parser;
|
||||
var assert = require('assert');
|
||||
|
||||
/*
|
||||
This test makes sure that exceptions thrown inside of "reply" event handlers
|
||||
are not trapped and mistakenly emitted as parse errors.
|
||||
*/
|
||||
(function testExecuteDoesNotCatchReplyCallbackExceptions() {
|
||||
var parser = new Parser();
|
||||
var replies = [{}];
|
||||
|
||||
parser.reader = {
|
||||
feed: function() {},
|
||||
get: function() {
|
||||
return replies.shift();
|
||||
}
|
||||
};
|
||||
|
||||
var emittedError = false;
|
||||
var caughtException = false;
|
||||
|
||||
parser
|
||||
.on('error', function() {
|
||||
emittedError = true;
|
||||
})
|
||||
.on('reply', function() {
|
||||
throw new Error('bad');
|
||||
});
|
||||
|
||||
try {
|
||||
parser.execute();
|
||||
} catch (err) {
|
||||
caughtException = true;
|
||||
}
|
||||
|
||||
assert.equal(caughtException, true);
|
||||
assert.equal(emittedError, false);
|
||||
})();
|
14
realtime/node_modules/redis/benches/re_sub_test.js
generated
vendored
Normal file
14
realtime/node_modules/redis/benches/re_sub_test.js
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
var client = require('../index').createClient()
|
||||
, client2 = require('../index').createClient()
|
||||
, assert = require('assert');
|
||||
|
||||
client.once('subscribe', function (channel, count) {
|
||||
client.unsubscribe('x');
|
||||
client.subscribe('x', function () {
|
||||
client.quit();
|
||||
client2.quit();
|
||||
});
|
||||
client2.publish('x', 'hi');
|
||||
});
|
||||
|
||||
client.subscribe('x');
|
29
realtime/node_modules/redis/benches/reconnect_test.js
generated
vendored
Normal file
29
realtime/node_modules/redis/benches/reconnect_test.js
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
var redis = require("../index").createClient(null, null, {
|
||||
// max_attempts: 4
|
||||
});
|
||||
|
||||
redis.on("error", function (err) {
|
||||
console.log("Redis says: " + err);
|
||||
});
|
||||
|
||||
redis.on("ready", function () {
|
||||
console.log("Redis ready.");
|
||||
});
|
||||
|
||||
redis.on("reconnecting", function (arg) {
|
||||
console.log("Redis reconnecting: " + JSON.stringify(arg));
|
||||
});
|
||||
redis.on("connect", function () {
|
||||
console.log("Redis connected.");
|
||||
});
|
||||
|
||||
setInterval(function () {
|
||||
var now = Date.now();
|
||||
redis.set("now", now, function (err, res) {
|
||||
if (err) {
|
||||
console.log(now + " Redis reply error: " + err);
|
||||
} else {
|
||||
console.log(now + " Redis reply: " + res);
|
||||
}
|
||||
});
|
||||
}, 100);
|
16
realtime/node_modules/redis/benches/stress/codec.js
generated
vendored
Normal file
16
realtime/node_modules/redis/benches/stress/codec.js
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
var json = {
|
||||
encode: JSON.stringify,
|
||||
decode: JSON.parse
|
||||
};
|
||||
|
||||
var MsgPack = require('node-msgpack');
|
||||
msgpack = {
|
||||
encode: MsgPack.pack,
|
||||
decode: function(str) { return MsgPack.unpack(new Buffer(str)); }
|
||||
};
|
||||
|
||||
bison = require('bison');
|
||||
|
||||
module.exports = json;
|
||||
//module.exports = msgpack;
|
||||
//module.exports = bison;
|
38
realtime/node_modules/redis/benches/stress/pubsub/pub.js
generated
vendored
Normal file
38
realtime/node_modules/redis/benches/stress/pubsub/pub.js
generated
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
'use strict';
|
||||
|
||||
var freemem = require('os').freemem;
|
||||
var profiler = require('v8-profiler');
|
||||
var codec = require('../codec');
|
||||
|
||||
var sent = 0;
|
||||
|
||||
var pub = require('redis').createClient(null, null, {
|
||||
//command_queue_high_water: 5,
|
||||
//command_queue_low_water: 1
|
||||
})
|
||||
.on('ready', function() {
|
||||
this.emit('drain');
|
||||
})
|
||||
.on('drain', function() {
|
||||
process.nextTick(exec);
|
||||
});
|
||||
|
||||
var payload = '1'; for (var i = 0; i < 12; ++i) payload += payload;
|
||||
console.log('Message payload length', payload.length);
|
||||
|
||||
function exec() {
|
||||
pub.publish('timeline', codec.encode({ foo: payload }));
|
||||
++sent;
|
||||
if (!pub.should_buffer) {
|
||||
process.nextTick(exec);
|
||||
}
|
||||
}
|
||||
|
||||
profiler.takeSnapshot('s_0');
|
||||
|
||||
exec();
|
||||
|
||||
setInterval(function() {
|
||||
profiler.takeSnapshot('s_' + sent);
|
||||
console.error('sent', sent, 'free', freemem(), 'cmdqlen', pub.command_queue.length, 'offqlen', pub.offline_queue.length);
|
||||
}, 2000);
|
10
realtime/node_modules/redis/benches/stress/pubsub/run
generated
vendored
Normal file
10
realtime/node_modules/redis/benches/stress/pubsub/run
generated
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/sh
|
||||
node server.js &
|
||||
node server.js &
|
||||
node server.js &
|
||||
node server.js &
|
||||
node server.js &
|
||||
node server.js &
|
||||
node server.js &
|
||||
node server.js &
|
||||
node --debug pub.js
|
23
realtime/node_modules/redis/benches/stress/pubsub/server.js
generated
vendored
Normal file
23
realtime/node_modules/redis/benches/stress/pubsub/server.js
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
var freemem = require('os').freemem;
|
||||
var codec = require('../codec');
|
||||
|
||||
var id = Math.random();
|
||||
var recv = 0;
|
||||
|
||||
var sub = require('redis').createClient()
|
||||
.on('ready', function() {
|
||||
this.subscribe('timeline');
|
||||
})
|
||||
.on('message', function(channel, message) {
|
||||
var self = this;
|
||||
if (message) {
|
||||
message = codec.decode(message);
|
||||
++recv;
|
||||
}
|
||||
});
|
||||
|
||||
setInterval(function() {
|
||||
console.error('id', id, 'received', recv, 'free', freemem());
|
||||
}, 2000);
|
49
realtime/node_modules/redis/benches/stress/rpushblpop/pub.js
generated
vendored
Normal file
49
realtime/node_modules/redis/benches/stress/rpushblpop/pub.js
generated
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
'use strict';
|
||||
|
||||
var freemem = require('os').freemem;
|
||||
//var profiler = require('v8-profiler');
|
||||
var codec = require('../codec');
|
||||
|
||||
var sent = 0;
|
||||
|
||||
var pub = require('redis').createClient(null, null, {
|
||||
//command_queue_high_water: 5,
|
||||
//command_queue_low_water: 1
|
||||
})
|
||||
.on('ready', function() {
|
||||
this.del('timeline');
|
||||
this.emit('drain');
|
||||
})
|
||||
.on('drain', function() {
|
||||
process.nextTick(exec);
|
||||
});
|
||||
|
||||
var payload = '1'; for (var i = 0; i < 12; ++i) payload += payload;
|
||||
console.log('Message payload length', payload.length);
|
||||
|
||||
function exec() {
|
||||
pub.rpush('timeline', codec.encode({ foo: payload }));
|
||||
++sent;
|
||||
if (!pub.should_buffer) {
|
||||
process.nextTick(exec);
|
||||
}
|
||||
}
|
||||
|
||||
//profiler.takeSnapshot('s_0');
|
||||
|
||||
exec();
|
||||
|
||||
setInterval(function() {
|
||||
//var ss = profiler.takeSnapshot('s_' + sent);
|
||||
//console.error(ss.stringify());
|
||||
pub.llen('timeline', function(err, result) {
|
||||
console.error('sent', sent, 'free', freemem(),
|
||||
'cmdqlen', pub.command_queue.length, 'offqlen', pub.offline_queue.length,
|
||||
'llen', result
|
||||
);
|
||||
});
|
||||
}, 2000);
|
||||
|
||||
/*setTimeout(function() {
|
||||
process.exit();
|
||||
}, 30000);*/
|
6
realtime/node_modules/redis/benches/stress/rpushblpop/run
generated
vendored
Normal file
6
realtime/node_modules/redis/benches/stress/rpushblpop/run
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
node server.js &
|
||||
#node server.js &
|
||||
#node server.js &
|
||||
#node server.js &
|
||||
node --debug pub.js
|
30
realtime/node_modules/redis/benches/stress/rpushblpop/server.js
generated
vendored
Normal file
30
realtime/node_modules/redis/benches/stress/rpushblpop/server.js
generated
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
'use strict';
|
||||
|
||||
var freemem = require('os').freemem;
|
||||
var codec = require('../codec');
|
||||
|
||||
var id = Math.random();
|
||||
var recv = 0;
|
||||
|
||||
var cmd = require('redis').createClient();
|
||||
var sub = require('redis').createClient()
|
||||
.on('ready', function() {
|
||||
this.emit('timeline');
|
||||
})
|
||||
.on('timeline', function() {
|
||||
var self = this;
|
||||
this.blpop('timeline', 0, function(err, result) {
|
||||
var message = result[1];
|
||||
if (message) {
|
||||
message = codec.decode(message);
|
||||
++recv;
|
||||
}
|
||||
self.emit('timeline');
|
||||
});
|
||||
});
|
||||
|
||||
setInterval(function() {
|
||||
cmd.llen('timeline', function(err, result) {
|
||||
console.error('id', id, 'received', recv, 'free', freemem(), 'llen', result);
|
||||
});
|
||||
}, 2000);
|
13
realtime/node_modules/redis/benches/stress/speed/00
generated
vendored
Normal file
13
realtime/node_modules/redis/benches/stress/speed/00
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
# size JSON msgpack bison
|
||||
26602 2151.0170848180414
|
||||
25542 ? 2842.589272665782
|
||||
24835 ? ? 7280.4538397469805
|
||||
6104 6985.234528557929
|
||||
5045 ? 7217.461392841478
|
||||
4341 ? ? 14261.406335354604
|
||||
4180 15864.633685636572
|
||||
4143 ? 12954.806235781925
|
||||
4141 ? ? 44650.70733912719
|
||||
75 114227.07313350472
|
||||
40 ? 30162.440062810834
|
||||
39 ? ? 119815.66013519121
|
13
realtime/node_modules/redis/benches/stress/speed/plot
generated
vendored
Normal file
13
realtime/node_modules/redis/benches/stress/speed/plot
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
#!/bin/sh
|
||||
|
||||
gnuplot >size-rate.jpg << _EOF_
|
||||
|
||||
set terminal png nocrop enhanced font verdana 12 size 640,480
|
||||
set logscale x
|
||||
set logscale y
|
||||
set grid
|
||||
set xlabel 'Serialized object size, octets'
|
||||
set ylabel 'decode(encode(obj)) rate, 1/sec'
|
||||
plot '00' using 1:2 title 'json' smooth bezier, '00' using 1:3 title 'msgpack' smooth bezier, '00' using 1:4 title 'bison' smooth bezier
|
||||
|
||||
_EOF_
|
BIN
realtime/node_modules/redis/benches/stress/speed/size-rate.png
generated
vendored
Normal file
BIN
realtime/node_modules/redis/benches/stress/speed/size-rate.png
generated
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
84
realtime/node_modules/redis/benches/stress/speed/speed.js
generated
vendored
Normal file
84
realtime/node_modules/redis/benches/stress/speed/speed.js
generated
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
var msgpack = require('node-msgpack');
|
||||
var bison = require('bison');
|
||||
var codec = {
|
||||
JSON: {
|
||||
encode: JSON.stringify,
|
||||
decode: JSON.parse
|
||||
},
|
||||
msgpack: {
|
||||
encode: msgpack.pack,
|
||||
decode: msgpack.unpack
|
||||
},
|
||||
bison: bison
|
||||
};
|
||||
|
||||
var obj, l;
|
||||
|
||||
var s = '0';
|
||||
for (var i = 0; i < 12; ++i) s += s;
|
||||
|
||||
obj = {
|
||||
foo: s,
|
||||
arrrrrr: [{a:1,b:false,c:null,d:1.0}, 1111, 2222, 33333333],
|
||||
rand: [],
|
||||
a: s,
|
||||
ccc: s,
|
||||
b: s + s + s
|
||||
};
|
||||
for (i = 0; i < 100; ++i) obj.rand.push(Math.random());
|
||||
forObj(obj);
|
||||
|
||||
obj = {
|
||||
foo: s,
|
||||
arrrrrr: [{a:1,b:false,c:null,d:1.0}, 1111, 2222, 33333333],
|
||||
rand: []
|
||||
};
|
||||
for (i = 0; i < 100; ++i) obj.rand.push(Math.random());
|
||||
forObj(obj);
|
||||
|
||||
obj = {
|
||||
foo: s,
|
||||
arrrrrr: [{a:1,b:false,c:null,d:1.0}, 1111, 2222, 33333333],
|
||||
rand: []
|
||||
};
|
||||
forObj(obj);
|
||||
|
||||
obj = {
|
||||
arrrrrr: [{a:1,b:false,c:null,d:1.0}, 1111, 2222, 33333333],
|
||||
rand: []
|
||||
};
|
||||
forObj(obj);
|
||||
|
||||
function run(obj, codec) {
|
||||
var t1 = Date.now();
|
||||
var n = 10000;
|
||||
for (var i = 0; i < n; ++i) {
|
||||
codec.decode(l = codec.encode(obj));
|
||||
}
|
||||
var t2 = Date.now();
|
||||
//console.log('DONE', n*1000/(t2-t1), 'codecs/sec, length=', l.length);
|
||||
return [n*1000/(t2-t1), l.length];
|
||||
}
|
||||
|
||||
function series(obj, cname, n) {
|
||||
var rate = 0;
|
||||
var len = 0;
|
||||
for (var i = 0; i < n; ++i) {
|
||||
var r = run(obj, codec[cname]);
|
||||
rate += r[0];
|
||||
len += r[1];
|
||||
}
|
||||
rate /= n;
|
||||
len /= n;
|
||||
console.log(cname + ' ' + rate + ' ' + len);
|
||||
return [rate, len];
|
||||
}
|
||||
|
||||
function forObj(obj) {
|
||||
var r = {
|
||||
JSON: series(obj, 'JSON', 20),
|
||||
msgpack: series(obj, 'msgpack', 20),
|
||||
bison: series(obj, 'bison', 20)
|
||||
};
|
||||
return r;
|
||||
}
|
18
realtime/node_modules/redis/benches/sub_quit_test.js
generated
vendored
Normal file
18
realtime/node_modules/redis/benches/sub_quit_test.js
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
var client = require("redis").createClient(),
|
||||
client2 = require("redis").createClient();
|
||||
|
||||
client.subscribe("something");
|
||||
client.on("subscribe", function (channel, count) {
|
||||
console.log("Got sub: " + channel);
|
||||
client.unsubscribe("something");
|
||||
});
|
||||
|
||||
client.on("unsubscribe", function (channel, count) {
|
||||
console.log("Got unsub: " + channel + ", quitting");
|
||||
client.quit();
|
||||
});
|
||||
|
||||
// exercise unsub before sub
|
||||
client2.unsubscribe("something");
|
||||
client2.subscribe("another thing");
|
||||
client2.quit();
|
219
realtime/node_modules/redis/changelog.md
generated
vendored
Normal file
219
realtime/node_modules/redis/changelog.md
generated
vendored
Normal file
|
@ -0,0 +1,219 @@
|
|||
Changelog
|
||||
=========
|
||||
|
||||
## v0.7.2 - April 29, 2012
|
||||
|
||||
Many contributed fixes. Thank you, contributors.
|
||||
|
||||
* [GH-190] - pub/sub mode fix (Brian Noguchi)
|
||||
* [GH-165] - parser selection fix (TEHEK)
|
||||
* numerous documentation and examples updates
|
||||
* auth errors emit Errors instead of Strings (David Trejo)
|
||||
|
||||
## v0.7.1 - November 15, 2011
|
||||
|
||||
Fix regression in reconnect logic.
|
||||
|
||||
Very much need automated tests for reconnection and queue logic.
|
||||
|
||||
## v0.7.0 - November 14, 2011
|
||||
|
||||
Many contributed fixes. Thanks everybody.
|
||||
|
||||
* [GH-127] - properly re-initialize parser on reconnect
|
||||
* [GH-136] - handle passing undefined as callback (Ian Babrou)
|
||||
* [GH-139] - properly handle exceptions thrown in pub/sub event handlers (Felix Geisendörfer)
|
||||
* [GH-141] - detect closing state on stream error (Felix Geisendörfer)
|
||||
* [GH-142] - re-select database on reconnection (Jean-Hugues Pinson)
|
||||
* [GH-146] - add sort example (Maksim Lin)
|
||||
|
||||
Some more goodies:
|
||||
|
||||
* Fix bugs with node 0.6
|
||||
* Performance improvements
|
||||
* New version of `multi_bench.js` that tests more realistic scenarios
|
||||
* [GH-140] - support optional callback for subscribe commands
|
||||
* Properly flush and error out command queue when connection fails
|
||||
* Initial work on reconnection thresholds
|
||||
|
||||
## v0.6.7 - July 30, 2011
|
||||
|
||||
(accidentally skipped v0.6.6)
|
||||
|
||||
Fix and test for [GH-123]
|
||||
|
||||
Passing an Array as as the last argument should expand as users
|
||||
expect. The old behavior was to coerce the arguments into Strings,
|
||||
which did surprising things with Arrays.
|
||||
|
||||
## v0.6.5 - July 6, 2011
|
||||
|
||||
Contributed changes:
|
||||
|
||||
* Support SlowBuffers (Umair Siddique)
|
||||
* Add Multi to exports (Louis-Philippe Perron)
|
||||
* Fix for drain event calculation (Vladimir Dronnikov)
|
||||
|
||||
Thanks!
|
||||
|
||||
## v0.6.4 - June 30, 2011
|
||||
|
||||
Fix bug with optional callbacks for hmset.
|
||||
|
||||
## v0.6.2 - June 30, 2011
|
||||
|
||||
Bugs fixed:
|
||||
|
||||
* authentication retry while server is loading db (danmaz74) [GH-101]
|
||||
* command arguments processing issue with arrays
|
||||
|
||||
New features:
|
||||
|
||||
* Auto update of new commands from redis.io (Dave Hoover)
|
||||
* Performance improvements and backpressure controls.
|
||||
* Commands now return the true/false value from the underlying socket write(s).
|
||||
* Implement command_queue high water and low water for more better control of queueing.
|
||||
|
||||
See `examples/backpressure_drain.js` for more information.
|
||||
|
||||
## v0.6.1 - June 29, 2011
|
||||
|
||||
Add support and tests for Redis scripting through EXEC command.
|
||||
|
||||
Bug fix for monitor mode. (forddg)
|
||||
|
||||
Auto update of new commands from redis.io (Dave Hoover)
|
||||
|
||||
## v0.6.0 - April 21, 2011
|
||||
|
||||
Lots of bugs fixed.
|
||||
|
||||
* connection error did not properly trigger reconnection logic [GH-85]
|
||||
* client.hmget(key, [val1, val2]) was not expanding properly [GH-66]
|
||||
* client.quit() while in pub/sub mode would throw an error [GH-87]
|
||||
* client.multi(['hmset', 'key', {foo: 'bar'}]) fails [GH-92]
|
||||
* unsubscribe before subscribe would make things very confused [GH-88]
|
||||
* Add BRPOPLPUSH [GH-79]
|
||||
|
||||
## v0.5.11 - April 7, 2011
|
||||
|
||||
Added DISCARD
|
||||
|
||||
I originally didn't think DISCARD would do anything here because of the clever MULTI interface, but somebody
|
||||
pointed out to me that DISCARD can be used to flush the WATCH set.
|
||||
|
||||
## v0.5.10 - April 6, 2011
|
||||
|
||||
Added HVALS
|
||||
|
||||
## v0.5.9 - March 14, 2011
|
||||
|
||||
Fix bug with empty Array arguments - Andy Ray
|
||||
|
||||
## v0.5.8 - March 14, 2011
|
||||
|
||||
Add `MONITOR` command and special monitor command reply parsing.
|
||||
|
||||
## v0.5.7 - February 27, 2011
|
||||
|
||||
Add magical auth command.
|
||||
|
||||
Authentication is now remembered by the client and will be automatically sent to the server
|
||||
on every connection, including any reconnections.
|
||||
|
||||
## v0.5.6 - February 22, 2011
|
||||
|
||||
Fix bug in ready check with `return_buffers` set to `true`.
|
||||
|
||||
Thanks to Dean Mao and Austin Chau.
|
||||
|
||||
## v0.5.5 - February 16, 2011
|
||||
|
||||
Add probe for server readiness.
|
||||
|
||||
When a Redis server starts up, it might take a while to load the dataset into memory.
|
||||
During this time, the server will accept connections, but will return errors for all non-INFO
|
||||
commands. Now node_redis will send an INFO command whenever it connects to a server.
|
||||
If the info command indicates that the server is not ready, the client will keep trying until
|
||||
the server is ready. Once it is ready, the client will emit a "ready" event as well as the
|
||||
"connect" event. The client will queue up all commands sent before the server is ready, just
|
||||
like it did before. When the server is ready, all offline/non-ready commands will be replayed.
|
||||
This should be backward compatible with previous versions.
|
||||
|
||||
To disable this ready check behavior, set `options.no_ready_check` when creating the client.
|
||||
|
||||
As a side effect of this change, the key/val params from the info command are available as
|
||||
`client.server_options`. Further, the version string is decomposed into individual elements
|
||||
in `client.server_options.versions`.
|
||||
|
||||
## v0.5.4 - February 11, 2011
|
||||
|
||||
Fix excess memory consumption from Queue backing store.
|
||||
|
||||
Thanks to Gustaf Sjöberg.
|
||||
|
||||
## v0.5.3 - February 5, 2011
|
||||
|
||||
Fix multi/exec error reply callback logic.
|
||||
|
||||
Thanks to Stella Laurenzo.
|
||||
|
||||
## v0.5.2 - January 18, 2011
|
||||
|
||||
Fix bug where unhandled error replies confuse the parser.
|
||||
|
||||
## v0.5.1 - January 18, 2011
|
||||
|
||||
Fix bug where subscribe commands would not handle redis-server startup error properly.
|
||||
|
||||
## v0.5.0 - December 29, 2010
|
||||
|
||||
Some bug fixes:
|
||||
|
||||
* An important bug fix in reconnection logic. Previously, reply callbacks would be invoked twice after
|
||||
a reconnect.
|
||||
* Changed error callback argument to be an actual Error object.
|
||||
|
||||
New feature:
|
||||
|
||||
* Add friendly syntax for HMSET using an object.
|
||||
|
||||
## v0.4.1 - December 8, 2010
|
||||
|
||||
Remove warning about missing hiredis. You probably do want it though.
|
||||
|
||||
## v0.4.0 - December 5, 2010
|
||||
|
||||
Support for multiple response parsers and hiredis C library from Pieter Noordhuis.
|
||||
Return Strings instead of Buffers by default.
|
||||
Empty nested mb reply bug fix.
|
||||
|
||||
## v0.3.9 - November 30, 2010
|
||||
|
||||
Fix parser bug on failed EXECs.
|
||||
|
||||
## v0.3.8 - November 10, 2010
|
||||
|
||||
Fix for null MULTI response when WATCH condition fails.
|
||||
|
||||
## v0.3.7 - November 9, 2010
|
||||
|
||||
Add "drain" and "idle" events.
|
||||
|
||||
## v0.3.6 - November 3, 2010
|
||||
|
||||
Add all known Redis commands from Redis master, even ones that are coming in 2.2 and beyond.
|
||||
|
||||
Send a friendlier "error" event message on stream errors like connection refused / reset.
|
||||
|
||||
## v0.3.5 - October 21, 2010
|
||||
|
||||
A few bug fixes.
|
||||
|
||||
* Fixed bug with `nil` multi-bulk reply lengths that showed up with `BLPOP` timeouts.
|
||||
* Only emit `end` once when connection goes away.
|
||||
* Fixed bug in `test.js` where driver finished before all tests completed.
|
||||
|
||||
## unversioned wasteland
|
||||
|
||||
See the git history for what happened before.
|
87
realtime/node_modules/redis/diff_multi_bench_output.js
generated
vendored
Normal file
87
realtime/node_modules/redis/diff_multi_bench_output.js
generated
vendored
Normal file
|
@ -0,0 +1,87 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
var colors = require('colors'),
|
||||
fs = require('fs'),
|
||||
_ = require('underscore'),
|
||||
metrics = require('metrics'),
|
||||
|
||||
// `node diff_multi_bench_output.js before.txt after.txt`
|
||||
before = process.argv[2],
|
||||
after = process.argv[3];
|
||||
|
||||
if (!before || !after) {
|
||||
console.log('Please supply two file arguments:');
|
||||
var n = __filename;
|
||||
n = n.substring(n.lastIndexOf('/', n.length));
|
||||
console.log(' ./' + n + ' multiBenchBefore.txt multiBenchAfter.txt');
|
||||
console.log('To generate multiBenchBefore.txt, run');
|
||||
console.log(' node multi_bench.js > multiBenchBefore.txt');
|
||||
console.log('Thank you for benchmarking responsibly.');
|
||||
return;
|
||||
}
|
||||
|
||||
var before_lines = fs.readFileSync(before, 'utf8').split('\n'),
|
||||
after_lines = fs.readFileSync(after, 'utf8').split('\n');
|
||||
|
||||
console.log('Comparing before,', before.green, '(', before_lines.length,
|
||||
'lines)', 'to after,', after.green, '(', after_lines.length, 'lines)');
|
||||
|
||||
var total_ops = new metrics.Histogram.createUniformHistogram();
|
||||
|
||||
before_lines.forEach(function(b, i) {
|
||||
var a = after_lines[i];
|
||||
if (!a || !b || !b.trim() || !a.trim()) {
|
||||
// console.log('#ignored#', '>'+a+'<', '>'+b+'<');
|
||||
return;
|
||||
}
|
||||
|
||||
b_words = b.split(' ').filter(is_whitespace);
|
||||
a_words = a.split(' ').filter(is_whitespace);
|
||||
|
||||
var ops =
|
||||
[b_words, a_words]
|
||||
.map(function(words) {
|
||||
// console.log(words);
|
||||
return parseInt10(words.slice(-2, -1));
|
||||
}).filter(function(num) {
|
||||
var isNaN = !num && num !== 0;
|
||||
return !isNaN;
|
||||
});
|
||||
if (ops.length != 2) return
|
||||
|
||||
var delta = ops[1] - ops[0];
|
||||
|
||||
total_ops.update(delta);
|
||||
|
||||
delta = humanize_diff(delta);
|
||||
console.log(
|
||||
// name of test
|
||||
command_name(a_words) == command_name(b_words)
|
||||
? command_name(a_words) + ':'
|
||||
: '404:',
|
||||
// results of test
|
||||
ops.join(' -> '), 'ops/sec (∆', delta, ')');
|
||||
});
|
||||
|
||||
console.log('Mean difference in ops/sec:', humanize_diff(total_ops.mean()));
|
||||
|
||||
function is_whitespace(s) {
|
||||
return !!s.trim();
|
||||
}
|
||||
|
||||
function parseInt10(s) {
|
||||
return parseInt(s, 10);
|
||||
}
|
||||
|
||||
// green if greater than 0, red otherwise
|
||||
function humanize_diff(num) {
|
||||
if (num > 0) {
|
||||
return ('+' + num).green;
|
||||
}
|
||||
return ('' + num).red;
|
||||
}
|
||||
|
||||
function command_name(words) {
|
||||
var line = words.join(' ');
|
||||
return line.substr(0, line.indexOf(','));
|
||||
}
|
5
realtime/node_modules/redis/examples/auth.js
generated
vendored
Normal file
5
realtime/node_modules/redis/examples/auth.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
var redis = require("redis"),
|
||||
client = redis.createClient();
|
||||
|
||||
// This command is magical. Client stashes the password and will issue on every connect.
|
||||
client.auth("somepass");
|
33
realtime/node_modules/redis/examples/backpressure_drain.js
generated
vendored
Normal file
33
realtime/node_modules/redis/examples/backpressure_drain.js
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
var redis = require("../index"),
|
||||
client = redis.createClient(null, null, {
|
||||
command_queue_high_water: 5,
|
||||
command_queue_low_water: 1
|
||||
}),
|
||||
remaining_ops = 100000, paused = false;
|
||||
|
||||
function op() {
|
||||
if (remaining_ops <= 0) {
|
||||
console.error("Finished.");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
remaining_ops--;
|
||||
if (client.hset("test hash", "val " + remaining_ops, remaining_ops) === false) {
|
||||
console.log("Pausing at " + remaining_ops);
|
||||
paused = true;
|
||||
} else {
|
||||
process.nextTick(op);
|
||||
}
|
||||
}
|
||||
|
||||
client.on("drain", function () {
|
||||
if (paused) {
|
||||
console.log("Resuming at " + remaining_ops);
|
||||
paused = false;
|
||||
process.nextTick(op);
|
||||
} else {
|
||||
console.log("Got drain while not paused at " + remaining_ops);
|
||||
}
|
||||
});
|
||||
|
||||
op();
|
9
realtime/node_modules/redis/examples/eval.js
generated
vendored
Normal file
9
realtime/node_modules/redis/examples/eval.js
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
var redis = require("./index"),
|
||||
client = redis.createClient();
|
||||
|
||||
redis.debug_mode = true;
|
||||
|
||||
client.eval("return 100.5", 0, function (err, res) {
|
||||
console.dir(err);
|
||||
console.dir(res);
|
||||
});
|
24
realtime/node_modules/redis/examples/extend.js
generated
vendored
Normal file
24
realtime/node_modules/redis/examples/extend.js
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
var redis = require("redis"),
|
||||
client = redis.createClient();
|
||||
|
||||
// Extend the RedisClient prototype to add a custom method
|
||||
// This one converts the results from "INFO" into a JavaScript Object
|
||||
|
||||
redis.RedisClient.prototype.parse_info = function (callback) {
|
||||
this.info(function (err, res) {
|
||||
var lines = res.toString().split("\r\n").sort();
|
||||
var obj = {};
|
||||
lines.forEach(function (line) {
|
||||
var parts = line.split(':');
|
||||
if (parts[1]) {
|
||||
obj[parts[0]] = parts[1];
|
||||
}
|
||||
});
|
||||
callback(obj)
|
||||
});
|
||||
};
|
||||
|
||||
client.parse_info(function (info) {
|
||||
console.dir(info);
|
||||
client.quit();
|
||||
});
|
32
realtime/node_modules/redis/examples/file.js
generated
vendored
Normal file
32
realtime/node_modules/redis/examples/file.js
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Read a file from disk, store it in Redis, then read it back from Redis.
|
||||
|
||||
var redis = require("redis"),
|
||||
client = redis.createClient(),
|
||||
fs = require("fs"),
|
||||
filename = "kids_in_cart.jpg";
|
||||
|
||||
// Get the file I use for testing like this:
|
||||
// curl http://ranney.com/kids_in_cart.jpg -o kids_in_cart.jpg
|
||||
// or just use your own file.
|
||||
|
||||
// Read a file from fs, store it in Redis, get it back from Redis, write it back to fs.
|
||||
fs.readFile(filename, function (err, data) {
|
||||
if (err) throw err
|
||||
console.log("Read " + data.length + " bytes from filesystem.");
|
||||
|
||||
client.set(filename, data, redis.print); // set entire file
|
||||
client.get(filename, function (err, reply) { // get entire file
|
||||
if (err) {
|
||||
console.log("Get error: " + err);
|
||||
} else {
|
||||
fs.writeFile("duplicate_" + filename, reply, function (err) {
|
||||
if (err) {
|
||||
console.log("Error on write: " + err)
|
||||
} else {
|
||||
console.log("File written.");
|
||||
}
|
||||
client.end();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
5
realtime/node_modules/redis/examples/mget.js
generated
vendored
Normal file
5
realtime/node_modules/redis/examples/mget.js
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
var client = require("redis").createClient();
|
||||
|
||||
client.mget(["sessions started", "sessions started", "foo"], function (err, res) {
|
||||
console.dir(res);
|
||||
});
|
10
realtime/node_modules/redis/examples/monitor.js
generated
vendored
Normal file
10
realtime/node_modules/redis/examples/monitor.js
generated
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
var client = require("../index").createClient(),
|
||||
util = require("util");
|
||||
|
||||
client.monitor(function (err, res) {
|
||||
console.log("Entering monitoring mode.");
|
||||
});
|
||||
|
||||
client.on("monitor", function (time, args) {
|
||||
console.log(time + ": " + util.inspect(args));
|
||||
});
|
46
realtime/node_modules/redis/examples/multi.js
generated
vendored
Normal file
46
realtime/node_modules/redis/examples/multi.js
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
var redis = require("redis"),
|
||||
client = redis.createClient(), set_size = 20;
|
||||
|
||||
client.sadd("bigset", "a member");
|
||||
client.sadd("bigset", "another member");
|
||||
|
||||
while (set_size > 0) {
|
||||
client.sadd("bigset", "member " + set_size);
|
||||
set_size -= 1;
|
||||
}
|
||||
|
||||
// multi chain with an individual callback
|
||||
client.multi()
|
||||
.scard("bigset")
|
||||
.smembers("bigset")
|
||||
.keys("*", function (err, replies) {
|
||||
client.mget(replies, redis.print);
|
||||
})
|
||||
.dbsize()
|
||||
.exec(function (err, replies) {
|
||||
console.log("MULTI got " + replies.length + " replies");
|
||||
replies.forEach(function (reply, index) {
|
||||
console.log("Reply " + index + ": " + reply.toString());
|
||||
});
|
||||
});
|
||||
|
||||
client.mset("incr thing", 100, "incr other thing", 1, redis.print);
|
||||
|
||||
// start a separate multi command queue
|
||||
var multi = client.multi();
|
||||
multi.incr("incr thing", redis.print);
|
||||
multi.incr("incr other thing", redis.print);
|
||||
|
||||
// runs immediately
|
||||
client.get("incr thing", redis.print); // 100
|
||||
|
||||
// drains multi queue and runs atomically
|
||||
multi.exec(function (err, replies) {
|
||||
console.log(replies); // 101, 2
|
||||
});
|
||||
|
||||
// you can re-run the same transaction if you like
|
||||
multi.exec(function (err, replies) {
|
||||
console.log(replies); // 102, 3
|
||||
client.quit();
|
||||
});
|
29
realtime/node_modules/redis/examples/multi2.js
generated
vendored
Normal file
29
realtime/node_modules/redis/examples/multi2.js
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
var redis = require("redis"),
|
||||
client = redis.createClient(), multi;
|
||||
|
||||
// start a separate command queue for multi
|
||||
multi = client.multi();
|
||||
multi.incr("incr thing", redis.print);
|
||||
multi.incr("incr other thing", redis.print);
|
||||
|
||||
// runs immediately
|
||||
client.mset("incr thing", 100, "incr other thing", 1, redis.print);
|
||||
|
||||
// drains multi queue and runs atomically
|
||||
multi.exec(function (err, replies) {
|
||||
console.log(replies); // 101, 2
|
||||
});
|
||||
|
||||
// you can re-run the same transaction if you like
|
||||
multi.exec(function (err, replies) {
|
||||
console.log(replies); // 102, 3
|
||||
client.quit();
|
||||
});
|
||||
|
||||
client.multi([
|
||||
["mget", "multifoo", "multibar", redis.print],
|
||||
["incr", "multifoo"],
|
||||
["incr", "multibar"]
|
||||
]).exec(function (err, replies) {
|
||||
console.log(replies.toString());
|
||||
});
|
33
realtime/node_modules/redis/examples/psubscribe.js
generated
vendored
Normal file
33
realtime/node_modules/redis/examples/psubscribe.js
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
var redis = require("redis"),
|
||||
client1 = redis.createClient(),
|
||||
client2 = redis.createClient(),
|
||||
client3 = redis.createClient(),
|
||||
client4 = redis.createClient(),
|
||||
msg_count = 0;
|
||||
|
||||
redis.debug_mode = false;
|
||||
|
||||
client1.on("psubscribe", function (pattern, count) {
|
||||
console.log("client1 psubscribed to " + pattern + ", " + count + " total subscriptions");
|
||||
client2.publish("channeltwo", "Me!");
|
||||
client3.publish("channelthree", "Me too!");
|
||||
client4.publish("channelfour", "And me too!");
|
||||
});
|
||||
|
||||
client1.on("punsubscribe", function (pattern, count) {
|
||||
console.log("client1 punsubscribed from " + pattern + ", " + count + " total subscriptions");
|
||||
client4.end();
|
||||
client3.end();
|
||||
client2.end();
|
||||
client1.end();
|
||||
});
|
||||
|
||||
client1.on("pmessage", function (pattern, channel, message) {
|
||||
console.log("("+ pattern +")" + " client1 received message on " + channel + ": " + message);
|
||||
msg_count += 1;
|
||||
if (msg_count === 3) {
|
||||
client1.punsubscribe();
|
||||
}
|
||||
});
|
||||
|
||||
client1.psubscribe("channel*");
|
41
realtime/node_modules/redis/examples/pub_sub.js
generated
vendored
Normal file
41
realtime/node_modules/redis/examples/pub_sub.js
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
var redis = require("redis"),
|
||||
client1 = redis.createClient(), msg_count = 0,
|
||||
client2 = redis.createClient();
|
||||
|
||||
redis.debug_mode = false;
|
||||
|
||||
// Most clients probably don't do much on "subscribe". This example uses it to coordinate things within one program.
|
||||
client1.on("subscribe", function (channel, count) {
|
||||
console.log("client1 subscribed to " + channel + ", " + count + " total subscriptions");
|
||||
if (count === 2) {
|
||||
client2.publish("a nice channel", "I am sending a message.");
|
||||
client2.publish("another one", "I am sending a second message.");
|
||||
client2.publish("a nice channel", "I am sending my last message.");
|
||||
}
|
||||
});
|
||||
|
||||
client1.on("unsubscribe", function (channel, count) {
|
||||
console.log("client1 unsubscribed from " + channel + ", " + count + " total subscriptions");
|
||||
if (count === 0) {
|
||||
client2.end();
|
||||
client1.end();
|
||||
}
|
||||
});
|
||||
|
||||
client1.on("message", function (channel, message) {
|
||||
console.log("client1 channel " + channel + ": " + message);
|
||||
msg_count += 1;
|
||||
if (msg_count === 3) {
|
||||
client1.unsubscribe();
|
||||
}
|
||||
});
|
||||
|
||||
client1.on("ready", function () {
|
||||
// if you need auth, do it here
|
||||
client1.incr("did a thing");
|
||||
client1.subscribe("a nice channel", "another one");
|
||||
});
|
||||
|
||||
client2.on("ready", function () {
|
||||
// if you need auth, do it here
|
||||
});
|
24
realtime/node_modules/redis/examples/simple.js
generated
vendored
Normal file
24
realtime/node_modules/redis/examples/simple.js
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
var redis = require("redis"),
|
||||
client = redis.createClient();
|
||||
|
||||
client.on("error", function (err) {
|
||||
console.log("error event - " + client.host + ":" + client.port + " - " + err);
|
||||
});
|
||||
|
||||
client.set("string key", "string val", redis.print);
|
||||
client.hset("hash key", "hashtest 1", "some value", redis.print);
|
||||
client.hset(["hash key", "hashtest 2", "some other value"], redis.print);
|
||||
client.hkeys("hash key", function (err, replies) {
|
||||
if (err) {
|
||||
return console.error("error response - " + err);
|
||||
}
|
||||
|
||||
console.log(replies.length + " replies:");
|
||||
replies.forEach(function (reply, i) {
|
||||
console.log(" " + i + ": " + reply);
|
||||
});
|
||||
});
|
||||
|
||||
client.quit(function (err, res) {
|
||||
console.log("Exiting from quit command.");
|
||||
});
|
17
realtime/node_modules/redis/examples/sort.js
generated
vendored
Normal file
17
realtime/node_modules/redis/examples/sort.js
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
var redis = require("redis"),
|
||||
client = redis.createClient();
|
||||
|
||||
client.sadd("mylist", 1);
|
||||
client.sadd("mylist", 2);
|
||||
client.sadd("mylist", 3);
|
||||
|
||||
client.set("weight_1", 5);
|
||||
client.set("weight_2", 500);
|
||||
client.set("weight_3", 1);
|
||||
|
||||
client.set("object_1", "foo");
|
||||
client.set("object_2", "bar");
|
||||
client.set("object_3", "qux");
|
||||
|
||||
client.sort("mylist", "by", "weight_*", "get", "object_*", redis.print);
|
||||
// Prints Reply: qux,foo,bar
|
15
realtime/node_modules/redis/examples/subqueries.js
generated
vendored
Normal file
15
realtime/node_modules/redis/examples/subqueries.js
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Sending commands in response to other commands.
|
||||
// This example runs "type" against every key in the database
|
||||
//
|
||||
var client = require("redis").createClient();
|
||||
|
||||
client.keys("*", function (err, keys) {
|
||||
keys.forEach(function (key, pos) {
|
||||
client.type(key, function (err, keytype) {
|
||||
console.log(key + " is " + keytype);
|
||||
if (pos === (keys.length - 1)) {
|
||||
client.quit();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
19
realtime/node_modules/redis/examples/subquery.js
generated
vendored
Normal file
19
realtime/node_modules/redis/examples/subquery.js
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
var client = require("redis").createClient();
|
||||
|
||||
function print_results(obj) {
|
||||
console.dir(obj);
|
||||
}
|
||||
|
||||
// build a map of all keys and their types
|
||||
client.keys("*", function (err, all_keys) {
|
||||
var key_types = {};
|
||||
|
||||
all_keys.forEach(function (key, pos) { // use second arg of forEach to get pos
|
||||
client.type(key, function (err, type) {
|
||||
key_types[key] = type;
|
||||
if (pos === all_keys.length - 1) { // callbacks all run in order
|
||||
print_results(key_types);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
29
realtime/node_modules/redis/examples/unix_socket.js
generated
vendored
Normal file
29
realtime/node_modules/redis/examples/unix_socket.js
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
var redis = require("redis"),
|
||||
client = redis.createClient("/tmp/redis.sock"),
|
||||
profiler = require("v8-profiler");
|
||||
|
||||
client.on("connect", function () {
|
||||
console.log("Got Unix socket connection.")
|
||||
});
|
||||
|
||||
client.on("error", function (err) {
|
||||
console.log(err.message);
|
||||
});
|
||||
|
||||
client.set("space chars", "space value");
|
||||
|
||||
setInterval(function () {
|
||||
client.get("space chars");
|
||||
}, 100);
|
||||
|
||||
function done() {
|
||||
client.info(function (err, reply) {
|
||||
console.log(reply.toString());
|
||||
client.quit();
|
||||
});
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
console.log("Taking snapshot.");
|
||||
var snap = profiler.takeSnapshot();
|
||||
}, 5000);
|
31
realtime/node_modules/redis/examples/web_server.js
generated
vendored
Normal file
31
realtime/node_modules/redis/examples/web_server.js
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
// A simple web server that generates dyanmic content based on responses from Redis
|
||||
|
||||
var http = require("http"), server,
|
||||
redis_client = require("redis").createClient();
|
||||
|
||||
server = http.createServer(function (request, response) {
|
||||
response.writeHead(200, {
|
||||
"Content-Type": "text/plain"
|
||||
});
|
||||
|
||||
var redis_info, total_requests;
|
||||
|
||||
redis_client.info(function (err, reply) {
|
||||
redis_info = reply; // stash response in outer scope
|
||||
});
|
||||
redis_client.incr("requests", function (err, reply) {
|
||||
total_requests = reply; // stash response in outer scope
|
||||
});
|
||||
redis_client.hincrby("ip", request.connection.remoteAddress, 1);
|
||||
redis_client.hgetall("ip", function (err, reply) {
|
||||
// This is the last reply, so all of the previous replies must have completed already
|
||||
response.write("This page was generated after talking to redis.\n\n" +
|
||||
"Redis info:\n" + redis_info + "\n" +
|
||||
"Total requests: " + total_requests + "\n\n" +
|
||||
"IP count: \n");
|
||||
Object.keys(reply).forEach(function (ip) {
|
||||
response.write(" " + ip + ": " + reply[ip] + "\n");
|
||||
});
|
||||
response.end();
|
||||
});
|
||||
}).listen(80);
|
39
realtime/node_modules/redis/generate_commands.js
generated
vendored
Normal file
39
realtime/node_modules/redis/generate_commands.js
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
var http = require("http"),
|
||||
fs = require("fs");
|
||||
|
||||
function prettyCurrentTime() {
|
||||
var date = new Date();
|
||||
return date.toLocaleString();
|
||||
}
|
||||
|
||||
function write_file(commands, path) {
|
||||
var file_contents, out_commands;
|
||||
|
||||
console.log("Writing " + Object.keys(commands).length + " commands to " + path);
|
||||
|
||||
file_contents = "// This file was generated by ./generate_commands.js on " + prettyCurrentTime() + "\n";
|
||||
|
||||
out_commands = Object.keys(commands).map(function (key) {
|
||||
return key.toLowerCase();
|
||||
});
|
||||
|
||||
file_contents += "module.exports = " + JSON.stringify(out_commands, null, " ") + ";\n";
|
||||
|
||||
fs.writeFile(path, file_contents);
|
||||
}
|
||||
|
||||
http.get({host: "redis.io", path: "/commands.json"}, function (res) {
|
||||
var body = "";
|
||||
|
||||
console.log("Response from redis.io/commands.json: " + res.statusCode);
|
||||
|
||||
res.on('data', function (chunk) {
|
||||
body += chunk;
|
||||
});
|
||||
|
||||
res.on('end', function () {
|
||||
write_file(JSON.parse(body), "lib/commands.js");
|
||||
});
|
||||
}).on('error', function (e) {
|
||||
console.log("Error fetching command list from redis.io: " + e.message);
|
||||
});
|
1113
realtime/node_modules/redis/index.js
generated
vendored
Normal file
1113
realtime/node_modules/redis/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
147
realtime/node_modules/redis/lib/commands.js
generated
vendored
Normal file
147
realtime/node_modules/redis/lib/commands.js
generated
vendored
Normal file
|
@ -0,0 +1,147 @@
|
|||
// This file was generated by ./generate_commands.js on Mon Aug 06 2012 15:04:06 GMT-0700 (PDT)
|
||||
module.exports = [
|
||||
"append",
|
||||
"auth",
|
||||
"bgrewriteaof",
|
||||
"bgsave",
|
||||
"bitcount",
|
||||
"bitop",
|
||||
"blpop",
|
||||
"brpop",
|
||||
"brpoplpush",
|
||||
"client kill",
|
||||
"client list",
|
||||
"config get",
|
||||
"config set",
|
||||
"config resetstat",
|
||||
"dbsize",
|
||||
"debug object",
|
||||
"debug segfault",
|
||||
"decr",
|
||||
"decrby",
|
||||
"del",
|
||||
"discard",
|
||||
"dump",
|
||||
"echo",
|
||||
"eval",
|
||||
"evalsha",
|
||||
"exec",
|
||||
"exists",
|
||||
"expire",
|
||||
"expireat",
|
||||
"flushall",
|
||||
"flushdb",
|
||||
"get",
|
||||
"getbit",
|
||||
"getrange",
|
||||
"getset",
|
||||
"hdel",
|
||||
"hexists",
|
||||
"hget",
|
||||
"hgetall",
|
||||
"hincrby",
|
||||
"hincrbyfloat",
|
||||
"hkeys",
|
||||
"hlen",
|
||||
"hmget",
|
||||
"hmset",
|
||||
"hset",
|
||||
"hsetnx",
|
||||
"hvals",
|
||||
"incr",
|
||||
"incrby",
|
||||
"incrbyfloat",
|
||||
"info",
|
||||
"keys",
|
||||
"lastsave",
|
||||
"lindex",
|
||||
"linsert",
|
||||
"llen",
|
||||
"lpop",
|
||||
"lpush",
|
||||
"lpushx",
|
||||
"lrange",
|
||||
"lrem",
|
||||
"lset",
|
||||
"ltrim",
|
||||
"mget",
|
||||
"migrate",
|
||||
"monitor",
|
||||
"move",
|
||||
"mset",
|
||||
"msetnx",
|
||||
"multi",
|
||||
"object",
|
||||
"persist",
|
||||
"pexpire",
|
||||
"pexpireat",
|
||||
"ping",
|
||||
"psetex",
|
||||
"psubscribe",
|
||||
"pttl",
|
||||
"publish",
|
||||
"punsubscribe",
|
||||
"quit",
|
||||
"randomkey",
|
||||
"rename",
|
||||
"renamenx",
|
||||
"restore",
|
||||
"rpop",
|
||||
"rpoplpush",
|
||||
"rpush",
|
||||
"rpushx",
|
||||
"sadd",
|
||||
"save",
|
||||
"scard",
|
||||
"script exists",
|
||||
"script flush",
|
||||
"script kill",
|
||||
"script load",
|
||||
"sdiff",
|
||||
"sdiffstore",
|
||||
"select",
|
||||
"set",
|
||||
"setbit",
|
||||
"setex",
|
||||
"setnx",
|
||||
"setrange",
|
||||
"shutdown",
|
||||
"sinter",
|
||||
"sinterstore",
|
||||
"sismember",
|
||||
"slaveof",
|
||||
"slowlog",
|
||||
"smembers",
|
||||
"smove",
|
||||
"sort",
|
||||
"spop",
|
||||
"srandmember",
|
||||
"srem",
|
||||
"strlen",
|
||||
"subscribe",
|
||||
"sunion",
|
||||
"sunionstore",
|
||||
"sync",
|
||||
"time",
|
||||
"ttl",
|
||||
"type",
|
||||
"unsubscribe",
|
||||
"unwatch",
|
||||
"watch",
|
||||
"zadd",
|
||||
"zcard",
|
||||
"zcount",
|
||||
"zincrby",
|
||||
"zinterstore",
|
||||
"zrange",
|
||||
"zrangebyscore",
|
||||
"zrank",
|
||||
"zrem",
|
||||
"zremrangebyrank",
|
||||
"zremrangebyscore",
|
||||
"zrevrange",
|
||||
"zrevrangebyscore",
|
||||
"zrevrank",
|
||||
"zscore",
|
||||
"zunionstore"
|
||||
];
|
46
realtime/node_modules/redis/lib/parser/hiredis.js
generated
vendored
Normal file
46
realtime/node_modules/redis/lib/parser/hiredis.js
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*global Buffer require exports console setTimeout */
|
||||
|
||||
var events = require("events"),
|
||||
util = require("../util"),
|
||||
hiredis = require("hiredis");
|
||||
|
||||
exports.debug_mode = false;
|
||||
exports.name = "hiredis";
|
||||
|
||||
function HiredisReplyParser(options) {
|
||||
this.name = exports.name;
|
||||
this.options = options || {};
|
||||
this.reset();
|
||||
events.EventEmitter.call(this);
|
||||
}
|
||||
|
||||
util.inherits(HiredisReplyParser, events.EventEmitter);
|
||||
|
||||
exports.Parser = HiredisReplyParser;
|
||||
|
||||
HiredisReplyParser.prototype.reset = function () {
|
||||
this.reader = new hiredis.Reader({
|
||||
return_buffers: this.options.return_buffers || false
|
||||
});
|
||||
};
|
||||
|
||||
HiredisReplyParser.prototype.execute = function (data) {
|
||||
var reply;
|
||||
this.reader.feed(data);
|
||||
while (true) {
|
||||
try {
|
||||
reply = this.reader.get();
|
||||
} catch (err) {
|
||||
this.emit("error", err);
|
||||
break;
|
||||
}
|
||||
|
||||
if (reply === undefined) break;
|
||||
|
||||
if (reply && reply.constructor === Error) {
|
||||
this.emit("reply error", reply);
|
||||
} else {
|
||||
this.emit("reply", reply);
|
||||
}
|
||||
}
|
||||
};
|
317
realtime/node_modules/redis/lib/parser/javascript.js
generated
vendored
Normal file
317
realtime/node_modules/redis/lib/parser/javascript.js
generated
vendored
Normal file
|
@ -0,0 +1,317 @@
|
|||
/*global Buffer require exports console setTimeout */
|
||||
|
||||
// TODO - incorporate these V8 pro tips:
|
||||
// pre-allocate Arrays if length is known in advance
|
||||
// do not use delete
|
||||
// use numbers for parser state
|
||||
|
||||
var events = require("events"),
|
||||
util = require("../util");
|
||||
|
||||
exports.debug_mode = false;
|
||||
exports.name = "javascript";
|
||||
|
||||
function RedisReplyParser(options) {
|
||||
this.name = exports.name;
|
||||
this.options = options || {};
|
||||
this.reset();
|
||||
events.EventEmitter.call(this);
|
||||
}
|
||||
|
||||
util.inherits(RedisReplyParser, events.EventEmitter);
|
||||
|
||||
exports.Parser = RedisReplyParser;
|
||||
|
||||
// Buffer.toString() is quite slow for small strings
|
||||
function small_toString(buf, len) {
|
||||
var tmp = "", i;
|
||||
|
||||
for (i = 0; i < len; i += 1) {
|
||||
tmp += String.fromCharCode(buf[i]);
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// Reset parser to it's original state.
|
||||
RedisReplyParser.prototype.reset = function () {
|
||||
this.return_buffer = new Buffer(16384); // for holding replies, might grow
|
||||
this.return_string = "";
|
||||
this.tmp_string = ""; // for holding size fields
|
||||
|
||||
this.multi_bulk_length = 0;
|
||||
this.multi_bulk_replies = null;
|
||||
this.multi_bulk_pos = 0;
|
||||
this.multi_bulk_nested_length = 0;
|
||||
this.multi_bulk_nested_replies = null;
|
||||
|
||||
this.states = {
|
||||
TYPE: 1,
|
||||
SINGLE_LINE: 2,
|
||||
MULTI_BULK_COUNT: 3,
|
||||
INTEGER_LINE: 4,
|
||||
BULK_LENGTH: 5,
|
||||
ERROR_LINE: 6,
|
||||
BULK_DATA: 7,
|
||||
UNKNOWN_TYPE: 8,
|
||||
FINAL_CR: 9,
|
||||
FINAL_LF: 10,
|
||||
MULTI_BULK_COUNT_LF: 11,
|
||||
BULK_LF: 12
|
||||
};
|
||||
|
||||
this.state = this.states.TYPE;
|
||||
};
|
||||
|
||||
RedisReplyParser.prototype.parser_error = function (message) {
|
||||
this.emit("error", message);
|
||||
this.reset();
|
||||
};
|
||||
|
||||
RedisReplyParser.prototype.execute = function (incoming_buf) {
|
||||
var pos = 0, bd_tmp, bd_str, i, il, states = this.states;
|
||||
//, state_times = {}, start_execute = new Date(), start_switch, end_switch, old_state;
|
||||
//start_switch = new Date();
|
||||
|
||||
while (pos < incoming_buf.length) {
|
||||
// old_state = this.state;
|
||||
// console.log("execute: " + this.state + ", " + pos + "/" + incoming_buf.length + ", " + String.fromCharCode(incoming_buf[pos]));
|
||||
|
||||
switch (this.state) {
|
||||
case 1: // states.TYPE
|
||||
this.type = incoming_buf[pos];
|
||||
pos += 1;
|
||||
|
||||
switch (this.type) {
|
||||
case 43: // +
|
||||
this.state = states.SINGLE_LINE;
|
||||
this.return_buffer.end = 0;
|
||||
this.return_string = "";
|
||||
break;
|
||||
case 42: // *
|
||||
this.state = states.MULTI_BULK_COUNT;
|
||||
this.tmp_string = "";
|
||||
break;
|
||||
case 58: // :
|
||||
this.state = states.INTEGER_LINE;
|
||||
this.return_buffer.end = 0;
|
||||
this.return_string = "";
|
||||
break;
|
||||
case 36: // $
|
||||
this.state = states.BULK_LENGTH;
|
||||
this.tmp_string = "";
|
||||
break;
|
||||
case 45: // -
|
||||
this.state = states.ERROR_LINE;
|
||||
this.return_buffer.end = 0;
|
||||
this.return_string = "";
|
||||
break;
|
||||
default:
|
||||
this.state = states.UNKNOWN_TYPE;
|
||||
}
|
||||
break;
|
||||
case 4: // states.INTEGER_LINE
|
||||
if (incoming_buf[pos] === 13) {
|
||||
this.send_reply(+small_toString(this.return_buffer, this.return_buffer.end));
|
||||
this.state = states.FINAL_LF;
|
||||
} else {
|
||||
this.return_buffer[this.return_buffer.end] = incoming_buf[pos];
|
||||
this.return_buffer.end += 1;
|
||||
}
|
||||
pos += 1;
|
||||
break;
|
||||
case 6: // states.ERROR_LINE
|
||||
if (incoming_buf[pos] === 13) {
|
||||
this.send_error(this.return_buffer.toString("ascii", 0, this.return_buffer.end));
|
||||
this.state = states.FINAL_LF;
|
||||
} else {
|
||||
this.return_buffer[this.return_buffer.end] = incoming_buf[pos];
|
||||
this.return_buffer.end += 1;
|
||||
}
|
||||
pos += 1;
|
||||
break;
|
||||
case 2: // states.SINGLE_LINE
|
||||
if (incoming_buf[pos] === 13) {
|
||||
this.send_reply(this.return_string);
|
||||
this.state = states.FINAL_LF;
|
||||
} else {
|
||||
this.return_string += String.fromCharCode(incoming_buf[pos]);
|
||||
}
|
||||
pos += 1;
|
||||
break;
|
||||
case 3: // states.MULTI_BULK_COUNT
|
||||
if (incoming_buf[pos] === 13) { // \r
|
||||
this.state = states.MULTI_BULK_COUNT_LF;
|
||||
} else {
|
||||
this.tmp_string += String.fromCharCode(incoming_buf[pos]);
|
||||
}
|
||||
pos += 1;
|
||||
break;
|
||||
case 11: // states.MULTI_BULK_COUNT_LF
|
||||
if (incoming_buf[pos] === 10) { // \n
|
||||
if (this.multi_bulk_length) { // nested multi-bulk
|
||||
this.multi_bulk_nested_length = this.multi_bulk_length;
|
||||
this.multi_bulk_nested_replies = this.multi_bulk_replies;
|
||||
this.multi_bulk_nested_pos = this.multi_bulk_pos;
|
||||
}
|
||||
this.multi_bulk_length = +this.tmp_string;
|
||||
this.multi_bulk_pos = 0;
|
||||
this.state = states.TYPE;
|
||||
if (this.multi_bulk_length < 0) {
|
||||
this.send_reply(null);
|
||||
this.multi_bulk_length = 0;
|
||||
} else if (this.multi_bulk_length === 0) {
|
||||
this.multi_bulk_pos = 0;
|
||||
this.multi_bulk_replies = null;
|
||||
this.send_reply([]);
|
||||
} else {
|
||||
this.multi_bulk_replies = new Array(this.multi_bulk_length);
|
||||
}
|
||||
} else {
|
||||
this.parser_error(new Error("didn't see LF after NL reading multi bulk count"));
|
||||
return;
|
||||
}
|
||||
pos += 1;
|
||||
break;
|
||||
case 5: // states.BULK_LENGTH
|
||||
if (incoming_buf[pos] === 13) { // \r
|
||||
this.state = states.BULK_LF;
|
||||
} else {
|
||||
this.tmp_string += String.fromCharCode(incoming_buf[pos]);
|
||||
}
|
||||
pos += 1;
|
||||
break;
|
||||
case 12: // states.BULK_LF
|
||||
if (incoming_buf[pos] === 10) { // \n
|
||||
this.bulk_length = +this.tmp_string;
|
||||
if (this.bulk_length === -1) {
|
||||
this.send_reply(null);
|
||||
this.state = states.TYPE;
|
||||
} else if (this.bulk_length === 0) {
|
||||
this.send_reply(new Buffer(""));
|
||||
this.state = states.FINAL_CR;
|
||||
} else {
|
||||
this.state = states.BULK_DATA;
|
||||
if (this.bulk_length > this.return_buffer.length) {
|
||||
if (exports.debug_mode) {
|
||||
console.log("Growing return_buffer from " + this.return_buffer.length + " to " + this.bulk_length);
|
||||
}
|
||||
this.return_buffer = new Buffer(this.bulk_length);
|
||||
}
|
||||
this.return_buffer.end = 0;
|
||||
}
|
||||
} else {
|
||||
this.parser_error(new Error("didn't see LF after NL while reading bulk length"));
|
||||
return;
|
||||
}
|
||||
pos += 1;
|
||||
break;
|
||||
case 7: // states.BULK_DATA
|
||||
this.return_buffer[this.return_buffer.end] = incoming_buf[pos];
|
||||
this.return_buffer.end += 1;
|
||||
pos += 1;
|
||||
if (this.return_buffer.end === this.bulk_length) {
|
||||
bd_tmp = new Buffer(this.bulk_length);
|
||||
// When the response is small, Buffer.copy() is a lot slower.
|
||||
if (this.bulk_length > 10) {
|
||||
this.return_buffer.copy(bd_tmp, 0, 0, this.bulk_length);
|
||||
} else {
|
||||
for (i = 0, il = this.bulk_length; i < il; i += 1) {
|
||||
bd_tmp[i] = this.return_buffer[i];
|
||||
}
|
||||
}
|
||||
this.send_reply(bd_tmp);
|
||||
this.state = states.FINAL_CR;
|
||||
}
|
||||
break;
|
||||
case 9: // states.FINAL_CR
|
||||
if (incoming_buf[pos] === 13) { // \r
|
||||
this.state = states.FINAL_LF;
|
||||
pos += 1;
|
||||
} else {
|
||||
this.parser_error(new Error("saw " + incoming_buf[pos] + " when expecting final CR"));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 10: // states.FINAL_LF
|
||||
if (incoming_buf[pos] === 10) { // \n
|
||||
this.state = states.TYPE;
|
||||
pos += 1;
|
||||
} else {
|
||||
this.parser_error(new Error("saw " + incoming_buf[pos] + " when expecting final LF"));
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this.parser_error(new Error("invalid state " + this.state));
|
||||
}
|
||||
// end_switch = new Date();
|
||||
// if (state_times[old_state] === undefined) {
|
||||
// state_times[old_state] = 0;
|
||||
// }
|
||||
// state_times[old_state] += (end_switch - start_switch);
|
||||
// start_switch = end_switch;
|
||||
}
|
||||
// console.log("execute ran for " + (Date.now() - start_execute) + " ms, on " + incoming_buf.length + " Bytes. ");
|
||||
// Object.keys(state_times).forEach(function (state) {
|
||||
// console.log(" " + state + ": " + state_times[state]);
|
||||
// });
|
||||
};
|
||||
|
||||
RedisReplyParser.prototype.send_error = function (reply) {
|
||||
if (this.multi_bulk_length > 0 || this.multi_bulk_nested_length > 0) {
|
||||
// TODO - can this happen? Seems like maybe not.
|
||||
this.add_multi_bulk_reply(reply);
|
||||
} else {
|
||||
this.emit("reply error", reply);
|
||||
}
|
||||
};
|
||||
|
||||
RedisReplyParser.prototype.send_reply = function (reply) {
|
||||
if (this.multi_bulk_length > 0 || this.multi_bulk_nested_length > 0) {
|
||||
if (!this.options.return_buffers && Buffer.isBuffer(reply)) {
|
||||
this.add_multi_bulk_reply(reply.toString("utf8"));
|
||||
} else {
|
||||
this.add_multi_bulk_reply(reply);
|
||||
}
|
||||
} else {
|
||||
if (!this.options.return_buffers && Buffer.isBuffer(reply)) {
|
||||
this.emit("reply", reply.toString("utf8"));
|
||||
} else {
|
||||
this.emit("reply", reply);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
RedisReplyParser.prototype.add_multi_bulk_reply = function (reply) {
|
||||
if (this.multi_bulk_replies) {
|
||||
this.multi_bulk_replies[this.multi_bulk_pos] = reply;
|
||||
this.multi_bulk_pos += 1;
|
||||
if (this.multi_bulk_pos < this.multi_bulk_length) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
this.multi_bulk_replies = reply;
|
||||
}
|
||||
|
||||
if (this.multi_bulk_nested_length > 0) {
|
||||
this.multi_bulk_nested_replies[this.multi_bulk_nested_pos] = this.multi_bulk_replies;
|
||||
this.multi_bulk_nested_pos += 1;
|
||||
|
||||
this.multi_bulk_length = 0;
|
||||
this.multi_bulk_replies = null;
|
||||
this.multi_bulk_pos = 0;
|
||||
|
||||
if (this.multi_bulk_nested_length === this.multi_bulk_nested_pos) {
|
||||
this.emit("reply", this.multi_bulk_nested_replies);
|
||||
this.multi_bulk_nested_length = 0;
|
||||
this.multi_bulk_nested_pos = 0;
|
||||
this.multi_bulk_nested_replies = null;
|
||||
}
|
||||
} else {
|
||||
this.emit("reply", this.multi_bulk_replies);
|
||||
this.multi_bulk_length = 0;
|
||||
this.multi_bulk_replies = null;
|
||||
this.multi_bulk_pos = 0;
|
||||
}
|
||||
};
|
61
realtime/node_modules/redis/lib/queue.js
generated
vendored
Normal file
61
realtime/node_modules/redis/lib/queue.js
generated
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
var to_array = require("./to_array");
|
||||
|
||||
// Queue class adapted from Tim Caswell's pattern library
|
||||
// http://github.com/creationix/pattern/blob/master/lib/pattern/queue.js
|
||||
|
||||
function Queue() {
|
||||
this.tail = [];
|
||||
this.head = [];
|
||||
this.offset = 0;
|
||||
}
|
||||
|
||||
Queue.prototype.shift = function () {
|
||||
if (this.offset === this.head.length) {
|
||||
var tmp = this.head;
|
||||
tmp.length = 0;
|
||||
this.head = this.tail;
|
||||
this.tail = tmp;
|
||||
this.offset = 0;
|
||||
if (this.head.length === 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return this.head[this.offset++]; // sorry, JSLint
|
||||
};
|
||||
|
||||
Queue.prototype.push = function (item) {
|
||||
return this.tail.push(item);
|
||||
};
|
||||
|
||||
Queue.prototype.forEach = function (fn, thisv) {
|
||||
var array = this.head.slice(this.offset), i, il;
|
||||
|
||||
array.push.apply(array, this.tail);
|
||||
|
||||
if (thisv) {
|
||||
for (i = 0, il = array.length; i < il; i += 1) {
|
||||
fn.call(thisv, array[i], i, array);
|
||||
}
|
||||
} else {
|
||||
for (i = 0, il = array.length; i < il; i += 1) {
|
||||
fn(array[i], i, array);
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
};
|
||||
|
||||
Queue.prototype.getLength = function () {
|
||||
return this.head.length - this.offset + this.tail.length;
|
||||
};
|
||||
|
||||
Object.defineProperty(Queue.prototype, 'length', {
|
||||
get: function () {
|
||||
return this.getLength();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if(typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = Queue;
|
||||
}
|
12
realtime/node_modules/redis/lib/to_array.js
generated
vendored
Normal file
12
realtime/node_modules/redis/lib/to_array.js
generated
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
function to_array(args) {
|
||||
var len = args.length,
|
||||
arr = new Array(len), i;
|
||||
|
||||
for (i = 0; i < len; i += 1) {
|
||||
arr[i] = args[i];
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
module.exports = to_array;
|
11
realtime/node_modules/redis/lib/util.js
generated
vendored
Normal file
11
realtime/node_modules/redis/lib/util.js
generated
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Support for very old versions of node where the module was called "sys". At some point, we should abandon this.
|
||||
|
||||
var util;
|
||||
|
||||
try {
|
||||
util = require("util");
|
||||
} catch (err) {
|
||||
util = require("sys");
|
||||
}
|
||||
|
||||
module.exports = util;
|
11
realtime/node_modules/redis/mem.js
generated
vendored
Normal file
11
realtime/node_modules/redis/mem.js
generated
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
var client = require("redis").createClient();
|
||||
|
||||
client.set("foo", "barvalskdjlksdjflkdsjflksdjdflkdsjflksdjflksdj", function (err, res) {
|
||||
if (err) {
|
||||
console.log("Got an error, please adapt somehow.");
|
||||
} else {
|
||||
console.log("Got a result: " + res);
|
||||
}
|
||||
});
|
||||
|
||||
client.quit();
|
225
realtime/node_modules/redis/multi_bench.js
generated
vendored
Normal file
225
realtime/node_modules/redis/multi_bench.js
generated
vendored
Normal file
|
@ -0,0 +1,225 @@
|
|||
var redis = require("./index"),
|
||||
metrics = require("metrics"),
|
||||
num_clients = parseInt(process.argv[2], 10) || 5,
|
||||
num_requests = 20000,
|
||||
tests = [],
|
||||
versions_logged = false,
|
||||
client_options = {
|
||||
return_buffers: false
|
||||
},
|
||||
small_str, large_str, small_buf, large_buf;
|
||||
|
||||
redis.debug_mode = false;
|
||||
|
||||
function lpad(input, len, chr) {
|
||||
var str = input.toString();
|
||||
chr = chr || " ";
|
||||
|
||||
while (str.length < len) {
|
||||
str = chr + str;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
metrics.Histogram.prototype.print_line = function () {
|
||||
var obj = this.printObj();
|
||||
|
||||
return lpad(obj.min, 4) + "/" + lpad(obj.max, 4) + "/" + lpad(obj.mean.toFixed(2), 7) + "/" + lpad(obj.p95.toFixed(2), 7);
|
||||
};
|
||||
|
||||
function Test(args) {
|
||||
var self = this;
|
||||
|
||||
this.args = args;
|
||||
|
||||
this.callback = null;
|
||||
this.clients = [];
|
||||
this.clients_ready = 0;
|
||||
this.commands_sent = 0;
|
||||
this.commands_completed = 0;
|
||||
this.max_pipeline = this.args.pipeline || num_requests;
|
||||
this.client_options = args.client_options || client_options;
|
||||
|
||||
this.connect_latency = new metrics.Histogram();
|
||||
this.ready_latency = new metrics.Histogram();
|
||||
this.command_latency = new metrics.Histogram();
|
||||
}
|
||||
|
||||
Test.prototype.run = function (callback) {
|
||||
var self = this, i;
|
||||
|
||||
this.callback = callback;
|
||||
|
||||
for (i = 0; i < num_clients ; i++) {
|
||||
this.new_client(i);
|
||||
}
|
||||
};
|
||||
|
||||
Test.prototype.new_client = function (id) {
|
||||
var self = this, new_client;
|
||||
|
||||
new_client = redis.createClient(6379, "127.0.0.1", this.client_options);
|
||||
new_client.create_time = Date.now();
|
||||
|
||||
new_client.on("connect", function () {
|
||||
self.connect_latency.update(Date.now() - new_client.create_time);
|
||||
});
|
||||
|
||||
new_client.on("ready", function () {
|
||||
if (! versions_logged) {
|
||||
console.log("Client count: " + num_clients + ", node version: " + process.versions.node + ", server version: " +
|
||||
new_client.server_info.redis_version + ", parser: " + new_client.reply_parser.name);
|
||||
versions_logged = true;
|
||||
}
|
||||
self.ready_latency.update(Date.now() - new_client.create_time);
|
||||
self.clients_ready++;
|
||||
if (self.clients_ready === self.clients.length) {
|
||||
self.on_clients_ready();
|
||||
}
|
||||
});
|
||||
|
||||
self.clients[id] = new_client;
|
||||
};
|
||||
|
||||
Test.prototype.on_clients_ready = function () {
|
||||
process.stdout.write(lpad(this.args.descr, 13) + ", " + lpad(this.args.pipeline, 5) + "/" + this.clients_ready + " ");
|
||||
this.test_start = Date.now();
|
||||
|
||||
this.fill_pipeline();
|
||||
};
|
||||
|
||||
Test.prototype.fill_pipeline = function () {
|
||||
var pipeline = this.commands_sent - this.commands_completed;
|
||||
|
||||
while (this.commands_sent < num_requests && pipeline < this.max_pipeline) {
|
||||
this.commands_sent++;
|
||||
pipeline++;
|
||||
this.send_next();
|
||||
}
|
||||
|
||||
if (this.commands_completed === num_requests) {
|
||||
this.print_stats();
|
||||
this.stop_clients();
|
||||
}
|
||||
};
|
||||
|
||||
Test.prototype.stop_clients = function () {
|
||||
var self = this;
|
||||
|
||||
this.clients.forEach(function (client, pos) {
|
||||
if (pos === self.clients.length - 1) {
|
||||
client.quit(function (err, res) {
|
||||
self.callback();
|
||||
});
|
||||
} else {
|
||||
client.quit();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.send_next = function () {
|
||||
var self = this,
|
||||
cur_client = this.commands_sent % this.clients.length,
|
||||
command_num = this.commands_sent,
|
||||
start = Date.now();
|
||||
|
||||
this.clients[cur_client][this.args.command](this.args.args, function (err, res) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
self.commands_completed++;
|
||||
self.command_latency.update(Date.now() - start);
|
||||
self.fill_pipeline();
|
||||
});
|
||||
};
|
||||
|
||||
Test.prototype.print_stats = function () {
|
||||
var duration = Date.now() - this.test_start;
|
||||
|
||||
console.log("min/max/avg/p95: " + this.command_latency.print_line() + " " + lpad(duration, 6) + "ms total, " +
|
||||
lpad((num_requests / (duration / 1000)).toFixed(2), 8) + " ops/sec");
|
||||
};
|
||||
|
||||
small_str = "1234";
|
||||
small_buf = new Buffer(small_str);
|
||||
large_str = (new Array(4097).join("-"));
|
||||
large_buf = new Buffer(large_str);
|
||||
|
||||
tests.push(new Test({descr: "PING", command: "ping", args: [], pipeline: 1}));
|
||||
tests.push(new Test({descr: "PING", command: "ping", args: [], pipeline: 50}));
|
||||
tests.push(new Test({descr: "PING", command: "ping", args: [], pipeline: 200}));
|
||||
tests.push(new Test({descr: "PING", command: "ping", args: [], pipeline: 20000}));
|
||||
|
||||
tests.push(new Test({descr: "SET small str", command: "set", args: ["foo_rand000000000000", small_str], pipeline: 1}));
|
||||
tests.push(new Test({descr: "SET small str", command: "set", args: ["foo_rand000000000000", small_str], pipeline: 50}));
|
||||
tests.push(new Test({descr: "SET small str", command: "set", args: ["foo_rand000000000000", small_str], pipeline: 200}));
|
||||
tests.push(new Test({descr: "SET small str", command: "set", args: ["foo_rand000000000000", small_str], pipeline: 20000}));
|
||||
|
||||
tests.push(new Test({descr: "SET small buf", command: "set", args: ["foo_rand000000000000", small_buf], pipeline: 1}));
|
||||
tests.push(new Test({descr: "SET small buf", command: "set", args: ["foo_rand000000000000", small_buf], pipeline: 50}));
|
||||
tests.push(new Test({descr: "SET small buf", command: "set", args: ["foo_rand000000000000", small_buf], pipeline: 200}));
|
||||
tests.push(new Test({descr: "SET small buf", command: "set", args: ["foo_rand000000000000", small_buf], pipeline: 20000}));
|
||||
|
||||
tests.push(new Test({descr: "GET small str", command: "get", args: ["foo_rand000000000000"], pipeline: 1}));
|
||||
tests.push(new Test({descr: "GET small str", command: "get", args: ["foo_rand000000000000"], pipeline: 50}));
|
||||
tests.push(new Test({descr: "GET small str", command: "get", args: ["foo_rand000000000000"], pipeline: 200}));
|
||||
tests.push(new Test({descr: "GET small str", command: "get", args: ["foo_rand000000000000"], pipeline: 20000}));
|
||||
|
||||
tests.push(new Test({descr: "GET small buf", command: "get", args: ["foo_rand000000000000"], pipeline: 1, client_opts: { return_buffers: true} }));
|
||||
tests.push(new Test({descr: "GET small buf", command: "get", args: ["foo_rand000000000000"], pipeline: 50, client_opts: { return_buffers: true} }));
|
||||
tests.push(new Test({descr: "GET small buf", command: "get", args: ["foo_rand000000000000"], pipeline: 200, client_opts: { return_buffers: true} }));
|
||||
tests.push(new Test({descr: "GET small buf", command: "get", args: ["foo_rand000000000000"], pipeline: 20000, client_opts: { return_buffers: true} }));
|
||||
|
||||
tests.push(new Test({descr: "SET large str", command: "set", args: ["foo_rand000000000001", large_str], pipeline: 1}));
|
||||
tests.push(new Test({descr: "SET large str", command: "set", args: ["foo_rand000000000001", large_str], pipeline: 50}));
|
||||
tests.push(new Test({descr: "SET large str", command: "set", args: ["foo_rand000000000001", large_str], pipeline: 200}));
|
||||
tests.push(new Test({descr: "SET large str", command: "set", args: ["foo_rand000000000001", large_str], pipeline: 20000}));
|
||||
|
||||
tests.push(new Test({descr: "SET large buf", command: "set", args: ["foo_rand000000000001", large_buf], pipeline: 1}));
|
||||
tests.push(new Test({descr: "SET large buf", command: "set", args: ["foo_rand000000000001", large_buf], pipeline: 50}));
|
||||
tests.push(new Test({descr: "SET large buf", command: "set", args: ["foo_rand000000000001", large_buf], pipeline: 200}));
|
||||
tests.push(new Test({descr: "SET large buf", command: "set", args: ["foo_rand000000000001", large_buf], pipeline: 20000}));
|
||||
|
||||
tests.push(new Test({descr: "GET large str", command: "get", args: ["foo_rand000000000001"], pipeline: 1}));
|
||||
tests.push(new Test({descr: "GET large str", command: "get", args: ["foo_rand000000000001"], pipeline: 50}));
|
||||
tests.push(new Test({descr: "GET large str", command: "get", args: ["foo_rand000000000001"], pipeline: 200}));
|
||||
tests.push(new Test({descr: "GET large str", command: "get", args: ["foo_rand000000000001"], pipeline: 20000}));
|
||||
|
||||
tests.push(new Test({descr: "GET large buf", command: "get", args: ["foo_rand000000000001"], pipeline: 1, client_opts: { return_buffers: true} }));
|
||||
tests.push(new Test({descr: "GET large buf", command: "get", args: ["foo_rand000000000001"], pipeline: 50, client_opts: { return_buffers: true} }));
|
||||
tests.push(new Test({descr: "GET large buf", command: "get", args: ["foo_rand000000000001"], pipeline: 200, client_opts: { return_buffers: true} }));
|
||||
tests.push(new Test({descr: "GET large buf", command: "get", args: ["foo_rand000000000001"], pipeline: 20000, client_opts: { return_buffers: true} }));
|
||||
|
||||
tests.push(new Test({descr: "INCR", command: "incr", args: ["counter_rand000000000000"], pipeline: 1}));
|
||||
tests.push(new Test({descr: "INCR", command: "incr", args: ["counter_rand000000000000"], pipeline: 50}));
|
||||
tests.push(new Test({descr: "INCR", command: "incr", args: ["counter_rand000000000000"], pipeline: 200}));
|
||||
tests.push(new Test({descr: "INCR", command: "incr", args: ["counter_rand000000000000"], pipeline: 20000}));
|
||||
|
||||
tests.push(new Test({descr: "LPUSH", command: "lpush", args: ["mylist", small_str], pipeline: 1}));
|
||||
tests.push(new Test({descr: "LPUSH", command: "lpush", args: ["mylist", small_str], pipeline: 50}));
|
||||
tests.push(new Test({descr: "LPUSH", command: "lpush", args: ["mylist", small_str], pipeline: 200}));
|
||||
tests.push(new Test({descr: "LPUSH", command: "lpush", args: ["mylist", small_str], pipeline: 20000}));
|
||||
|
||||
tests.push(new Test({descr: "LRANGE 10", command: "lrange", args: ["mylist", "0", "9"], pipeline: 1}));
|
||||
tests.push(new Test({descr: "LRANGE 10", command: "lrange", args: ["mylist", "0", "9"], pipeline: 50}));
|
||||
tests.push(new Test({descr: "LRANGE 10", command: "lrange", args: ["mylist", "0", "9"], pipeline: 200}));
|
||||
tests.push(new Test({descr: "LRANGE 10", command: "lrange", args: ["mylist", "0", "9"], pipeline: 20000}));
|
||||
|
||||
tests.push(new Test({descr: "LRANGE 100", command: "lrange", args: ["mylist", "0", "99"], pipeline: 1}));
|
||||
tests.push(new Test({descr: "LRANGE 100", command: "lrange", args: ["mylist", "0", "99"], pipeline: 50}));
|
||||
tests.push(new Test({descr: "LRANGE 100", command: "lrange", args: ["mylist", "0", "99"], pipeline: 200}));
|
||||
tests.push(new Test({descr: "LRANGE 100", command: "lrange", args: ["mylist", "0", "99"], pipeline: 20000}));
|
||||
|
||||
function next() {
|
||||
var test = tests.shift();
|
||||
if (test) {
|
||||
test.run(function () {
|
||||
next();
|
||||
});
|
||||
} else {
|
||||
console.log("End of tests.");
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
41
realtime/node_modules/redis/package.json
generated
vendored
Normal file
41
realtime/node_modules/redis/package.json
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"name": "redis",
|
||||
"version": "0.7.3",
|
||||
"description": "Redis client library",
|
||||
"author": {
|
||||
"name": "Matt Ranney",
|
||||
"email": "mjr@ranney.com"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "David Trejo",
|
||||
"email": "david.daniel.trejo@gmail.com",
|
||||
"url": "http://dtrejo.com/"
|
||||
}
|
||||
],
|
||||
"main": "./index.js",
|
||||
"scripts": {
|
||||
"test": "node ./test.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"metrics": ">=0.1.5"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mranney/node_redis.git"
|
||||
},
|
||||
"_id": "redis@0.7.3",
|
||||
"dependencies": {},
|
||||
"optionalDependencies": {},
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"_engineSupported": true,
|
||||
"_npmVersion": "1.1.21",
|
||||
"_nodeVersion": "v0.6.18",
|
||||
"_defaultsLoaded": true,
|
||||
"dist": {
|
||||
"shasum": "e8b3c2a488b9d00b47570afb01577bebd6f7aa6f"
|
||||
},
|
||||
"_from": "redis@0.7.3"
|
||||
}
|
1618
realtime/node_modules/redis/test.js
generated
vendored
Normal file
1618
realtime/node_modules/redis/test.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
3
realtime/node_modules/socket.io/.npmignore
generated
vendored
Normal file
3
realtime/node_modules/socket.io/.npmignore
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
support
|
||||
test
|
||||
examples
|
6
realtime/node_modules/socket.io/.travis.yml
generated
vendored
Normal file
6
realtime/node_modules/socket.io/.travis.yml
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- 0.6
|
||||
|
||||
notifications:
|
||||
irc: "irc.freenode.org#socket.io"
|
305
realtime/node_modules/socket.io/History.md
generated
vendored
Normal file
305
realtime/node_modules/socket.io/History.md
generated
vendored
Normal file
|
@ -0,0 +1,305 @@
|
|||
|
||||
0.9.12 / 2012-12-13
|
||||
===================
|
||||
|
||||
* manager: fix for latest node which is returning a clone with `listeners` [viirya]
|
||||
|
||||
0.9.11 / 2012-11-02
|
||||
===================
|
||||
|
||||
* package: move redis to optionalDependenices [3rd-Eden]
|
||||
* bumped client
|
||||
|
||||
0.9.10 / 2012-08-10
|
||||
===================
|
||||
|
||||
* Don't lowercase log messages
|
||||
* Always set the HTTP response in case an error should be returned to the client
|
||||
* Create or destroy the flash policy server on configuration change
|
||||
* Honour configuration to disable flash policy server
|
||||
* Add express 3.0 instructions on Readme.md
|
||||
* Bump client
|
||||
|
||||
0.9.9 / 2012-08-01
|
||||
==================
|
||||
|
||||
* Fixed sync disconnect xhrs handling
|
||||
* Put license text in its own file (#965)
|
||||
* Add warning to .listen() to ease the migration to Express 3.x
|
||||
* Restored compatibility with node 0.4.x
|
||||
|
||||
0.9.8 / 2012-07-24
|
||||
==================
|
||||
|
||||
* Bumped client.
|
||||
|
||||
0.9.7 / 2012-07-24
|
||||
==================
|
||||
|
||||
* Prevent crash when socket leaves a room twice.
|
||||
* Corrects unsafe usage of for..in
|
||||
* Fix for node 0.8 with `gzip compression` [vadimi]
|
||||
* Update redis to support Node 0.8.x
|
||||
* Made ID generation securely random
|
||||
* Fix Redis Store race condition in manager onOpen unsubscribe callback
|
||||
* Fix for EventEmitters always reusing the same Array instance for listeners
|
||||
|
||||
0.9.6 / 2012-04-17
|
||||
==================
|
||||
|
||||
* Fixed XSS in jsonp-polling.
|
||||
|
||||
0.9.5 / 2012-04-05
|
||||
==================
|
||||
|
||||
* Added test for polling and socket close.
|
||||
* Ensure close upon request close.
|
||||
* Fix disconnection reason being lost for polling transports.
|
||||
* Ensure that polling transports work with Connection: close.
|
||||
* Log disconnection reason.
|
||||
|
||||
0.9.4 / 2012-04-01
|
||||
==================
|
||||
|
||||
* Disconnecting from namespace improvement (#795) [DanielBaulig]
|
||||
* Bumped client with polling reconnection loop (#438)
|
||||
|
||||
0.9.3 / 2012-03-28
|
||||
==================
|
||||
|
||||
* Fix "Syntax error" on FF Web Console with XHR Polling [mikito]
|
||||
|
||||
0.9.2 / 2012-03-13
|
||||
==================
|
||||
|
||||
* More sensible close `timeout default` (fixes disconnect issue)
|
||||
|
||||
0.9.1-1 / 2012-03-02
|
||||
====================
|
||||
|
||||
* Bumped client with NPM dependency fix.
|
||||
|
||||
0.9.1 / 2012-03-02
|
||||
==================
|
||||
|
||||
* Changed heartbeat timeout and interval defaults (60 and 25 seconds)
|
||||
* Make tests work both on 0.4 and 0.6
|
||||
* Updated client (improvements + bug fixes).
|
||||
|
||||
0.9.0 / 2012-02-26
|
||||
==================
|
||||
|
||||
* Make it possible to use a regexp to match the socket.io resource URL.
|
||||
We need this because we have to prefix the socket.io URL with a variable ID.
|
||||
* Supplemental fix to gavinuhma/authfix, it looks like the same Access-Control-Origin logic is needed in the http and xhr-polling transports
|
||||
* Updated express dep for windows compatibility.
|
||||
* Combine two substr calls into one in decodePayload to improve performance
|
||||
* Minor documentation fix
|
||||
* Minor. Conform to style of other files.
|
||||
* Switching setting to 'match origin protocol'
|
||||
* Revert "Fixes leaking Redis subscriptions for #663. The local flag was not getting passed through onClientDisconnect()."
|
||||
* Revert "Handle leaked dispatch:[id] subscription."
|
||||
* Merge pull request #667 from dshaw/patch/redis-disconnect
|
||||
* Handle leaked dispatch:[id] subscription.
|
||||
* Fixes leaking Redis subscriptions for #663. The local flag was not getting passed through onClientDisconnect().
|
||||
* Prevent memory leaking on uncompleted requests & add max post size limitation
|
||||
* Fix for testcase
|
||||
* Set Access-Control-Allow-Credentials true, regardless of cookie
|
||||
* Remove assertvarnish from package as it breaks on 0.6
|
||||
* Correct irc channel
|
||||
* Added proper return after reserved field error
|
||||
* Fixes manager.js failure to close connection after transport error has happened
|
||||
* Added implicit port 80 for origin checks. fixes #638
|
||||
* Fixed bug #432 in 0.8.7
|
||||
* Set Access-Control-Allow-Origin header to origin to enable withCredentials
|
||||
* Adding configuration variable matchOriginProtocol
|
||||
* Fixes location mismatch error in Safari.
|
||||
* Use tty to detect if we should add colors or not by default.
|
||||
* Updated the package location.
|
||||
|
||||
0.8.7 / 2011-11-05
|
||||
==================
|
||||
|
||||
* Fixed memory leaks in closed clients.
|
||||
* Fixed memory leaks in namespaces.
|
||||
* Fixed websocket handling for malformed requests from proxies. [einaros]
|
||||
* Node 0.6 compatibility. [einaros] [3rd-Eden]
|
||||
* Adapted tests and examples.
|
||||
|
||||
0.8.6 / 2011-10-27
|
||||
==================
|
||||
|
||||
* Added JSON decoding on jsonp-polling transport.
|
||||
* Fixed README example.
|
||||
* Major speed optimizations [3rd-Eden] [einaros] [visionmedia]
|
||||
* Added decode/encode benchmarks [visionmedia]
|
||||
* Added support for black-listing client sent events.
|
||||
* Fixed logging options, closes #540 [3rd-Eden]
|
||||
* Added vary header for gzip [3rd-Eden]
|
||||
* Properly cleaned up async websocket / flashsocket tests, after patching node-websocket-client
|
||||
* Patched to properly shut down when a finishClose call is made during connection establishment
|
||||
* Added support for socket.io version on url and far-future Expires [3rd-Eden] [getify]
|
||||
* Began IE10 compatibility [einaros] [tbranyen]
|
||||
* Misc WebSocket fixes [einaros]
|
||||
* Added UTF8 to respone headers for htmlfile [3rd-Eden]
|
||||
|
||||
0.8.5 / 2011-10-07
|
||||
==================
|
||||
|
||||
* Added websocket draft HyBi-16 support. [einaros]
|
||||
* Fixed websocket continuation bugs. [einaros]
|
||||
* Fixed flashsocket transport name.
|
||||
* Fixed websocket tests.
|
||||
* Ensured `parser#decodePayload` doesn't choke.
|
||||
* Added http referrer verification to manager verifyOrigin.
|
||||
* Added access control for cross domain xhr handshakes [3rd-Eden]
|
||||
* Added support for automatic generation of socket.io files [3rd-Eden]
|
||||
* Added websocket binary support [einaros]
|
||||
* Added gzip support for socket.io.js [3rd-Eden]
|
||||
* Expose socket.transport [3rd-Eden]
|
||||
* Updated client.
|
||||
|
||||
0.8.4 / 2011-09-06
|
||||
==================
|
||||
|
||||
* Client build
|
||||
|
||||
0.8.3 / 2011-09-03
|
||||
==================
|
||||
|
||||
* Fixed `\n` parsing for non-JSON packets (fixes #479).
|
||||
* Fixed parsing of certain unicode characters (fixes #451).
|
||||
* Fixed transport message packet logging.
|
||||
* Fixed emission of `error` event resulting in an uncaught exception if unhandled (fixes #476).
|
||||
* Fixed; allow for falsy values as the configuration value of `log level` (fixes #491).
|
||||
* Fixed repository URI in `package.json`. Fixes #504.
|
||||
* Added text/plain content-type to handshake responses [einaros]
|
||||
* Improved single byte writes [einaros]
|
||||
* Updated socket.io-flashsocket default port from 843 to 10843 [3rd-Eden]
|
||||
* Updated client.
|
||||
|
||||
0.8.2 / 2011-08-29
|
||||
==================
|
||||
|
||||
* Updated client.
|
||||
|
||||
0.8.1 / 2011-08-29
|
||||
==================
|
||||
|
||||
* Fixed utf8 bug in send framing in websocket [einaros]
|
||||
* Fixed typo in docs [Znarkus]
|
||||
* Fixed bug in send framing for over 64kB of data in websocket [einaros]
|
||||
* Corrected ping handling in websocket transport [einaros]
|
||||
|
||||
0.8.0 / 2011-08-28
|
||||
==================
|
||||
|
||||
* Updated to work with two-level websocket versioning. [einaros]
|
||||
* Added hybi07 support. [einaros]
|
||||
* Added hybi10 support. [einaros]
|
||||
* Added http referrer verification to manager.js verifyOrigin. [einaors]
|
||||
|
||||
0.7.11 / 2011-08-27
|
||||
===================
|
||||
|
||||
* Updated socket.io-client.
|
||||
|
||||
0.7.10 / 2011-08-27
|
||||
===================
|
||||
|
||||
* Updated socket.io-client.
|
||||
|
||||
0.7.9 / 2011-08-12
|
||||
==================
|
||||
|
||||
* Updated socket.io-client.
|
||||
* Make sure we only do garbage collection when the server we receive is actually run.
|
||||
|
||||
0.7.8 / 2011-08-08
|
||||
==================
|
||||
|
||||
* Changed; make sure sio#listen passes options to both HTTP server and socket.io manager.
|
||||
* Added docs for sio#listen.
|
||||
* Added options parameter support for Manager constructor.
|
||||
* Added memory leaks tests and test-leaks Makefile task.
|
||||
* Removed auto npm-linking from make test.
|
||||
* Make sure that you can disable heartbeats. [3rd-Eden]
|
||||
* Fixed rooms memory leak [3rd-Eden]
|
||||
* Send response once we got all POST data, not immediately [Pita]
|
||||
* Fixed onLeave behavior with missing clientsk [3rd-Eden]
|
||||
* Prevent duplicate references in rooms.
|
||||
* Added alias for `to` to `in` and `in` to `to`.
|
||||
* Fixed roomClients definition.
|
||||
* Removed dependency on redis for installation without npm [3rd-Eden]
|
||||
* Expose path and querystring in handshakeData [3rd-Eden]
|
||||
|
||||
0.7.7 / 2011-07-12
|
||||
==================
|
||||
|
||||
* Fixed double dispatch handling with emit to closed clients.
|
||||
* Added test for emitting to closed clients to prevent regression.
|
||||
* Fixed race condition in redis test.
|
||||
* Changed Transport#end instrumentation.
|
||||
* Leveraged $emit instead of emit internally.
|
||||
* Made tests faster.
|
||||
* Fixed double disconnect events.
|
||||
* Fixed disconnect logic
|
||||
* Simplified remote events handling in Socket.
|
||||
* Increased testcase timeout.
|
||||
* Fixed unknown room emitting (GH-291). [3rd-Eden]
|
||||
* Fixed `address` in handshakeData. [3rd-Eden]
|
||||
* Removed transports definition in chat example.
|
||||
* Fixed room cleanup
|
||||
* Fixed; make sure the client is cleaned up after booting.
|
||||
* Make sure to mark the client as non-open if the connection is closed.
|
||||
* Removed unneeded `buffer` declarations.
|
||||
* Fixed; make sure to clear socket handlers and subscriptions upon transport close.
|
||||
|
||||
0.7.6 / 2011-06-30
|
||||
==================
|
||||
|
||||
* Fixed general dispatching when a client has closed.
|
||||
|
||||
0.7.5 / 2011-06-30
|
||||
==================
|
||||
|
||||
* Fixed dispatching to clients that are disconnected.
|
||||
|
||||
0.7.4 / 2011-06-30
|
||||
==================
|
||||
|
||||
* Fixed; only clear handlers if they were set. [level09]
|
||||
|
||||
0.7.3 / 2011-06-30
|
||||
==================
|
||||
|
||||
* Exposed handshake data to clients.
|
||||
* Refactored dispatcher interface.
|
||||
* Changed; Moved id generation method into the manager.
|
||||
* Added sub-namespace authorization. [3rd-Eden]
|
||||
* Changed; normalized SocketNamespace local eventing [dvv]
|
||||
* Changed; Use packet.reason or default to 'packet' [3rd-Eden]
|
||||
* Changed console.error to console.log.
|
||||
* Fixed; bind both servers at the same time do that the test never times out.
|
||||
* Added 304 support.
|
||||
* Removed `Transport#name` for abstract interface.
|
||||
* Changed; lazily require http and https module only when needed. [3rd-Eden]
|
||||
|
||||
0.7.2 / 2011-06-22
|
||||
==================
|
||||
|
||||
* Make sure to write a packet (of type `noop`) when closing a poll.
|
||||
This solves a problem with cross-domain requests being flagged as aborted and
|
||||
reconnection being triggered.
|
||||
* Added `noop` message type.
|
||||
|
||||
0.7.1 / 2011-06-21
|
||||
==================
|
||||
|
||||
* Fixed cross-domain XHR.
|
||||
* Added CORS test to xhr-polling suite.
|
||||
|
||||
0.7.0 / 2010-06-21
|
||||
==================
|
||||
|
||||
* http://socket.io/announcement.html
|
22
realtime/node_modules/socket.io/LICENSE
generated
vendored
Normal file
22
realtime/node_modules/socket.io/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
(The MIT License)
|
||||
|
||||
Copyright (c) 2011 Guillermo Rauch <guillermo@learnboost.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
31
realtime/node_modules/socket.io/Makefile
generated
vendored
Normal file
31
realtime/node_modules/socket.io/Makefile
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
|
||||
ALL_TESTS = $(shell find test/ -name '*.test.js')
|
||||
ALL_BENCH = $(shell find benchmarks -name '*.bench.js')
|
||||
|
||||
run-tests:
|
||||
@./node_modules/.bin/expresso \
|
||||
-t 3000 \
|
||||
-I support \
|
||||
--serial \
|
||||
$(TESTFLAGS) \
|
||||
$(TESTS)
|
||||
|
||||
test:
|
||||
@$(MAKE) NODE_PATH=lib TESTS="$(ALL_TESTS)" run-tests
|
||||
|
||||
test-cov:
|
||||
@TESTFLAGS=--cov $(MAKE) test
|
||||
|
||||
test-leaks:
|
||||
@ls test/leaks/* | xargs node --expose_debug_as=debug --expose_gc
|
||||
|
||||
run-bench:
|
||||
@node $(PROFILEFLAGS) benchmarks/runner.js
|
||||
|
||||
bench:
|
||||
@$(MAKE) BENCHMARKS="$(ALL_BENCH)" run-bench
|
||||
|
||||
profile:
|
||||
@PROFILEFLAGS='--prof --trace-opt --trace-bailout --trace-deopt' $(MAKE) bench
|
||||
|
||||
.PHONY: test bench profile
|
364
realtime/node_modules/socket.io/Readme.md
generated
vendored
Normal file
364
realtime/node_modules/socket.io/Readme.md
generated
vendored
Normal file
|
@ -0,0 +1,364 @@
|
|||
# Socket.IO
|
||||
|
||||
Socket.IO is a Node.JS project that makes WebSockets and realtime possible in
|
||||
all browsers. It also enhances WebSockets by providing built-in multiplexing,
|
||||
horizontal scalability, automatic JSON encoding/decoding, and more.
|
||||
|
||||
## How to Install
|
||||
|
||||
```bash
|
||||
npm install socket.io
|
||||
```
|
||||
|
||||
## How to use
|
||||
|
||||
First, require `socket.io`:
|
||||
|
||||
```js
|
||||
var io = require('socket.io');
|
||||
```
|
||||
|
||||
Next, attach it to a HTTP/HTTPS server. If you're using the fantastic `express`
|
||||
web framework:
|
||||
|
||||
#### Express 3.x
|
||||
|
||||
```js
|
||||
var app = express()
|
||||
, server = require('http').createServer(app)
|
||||
, io = io.listen(server);
|
||||
|
||||
server.listen(80);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.emit('news', { hello: 'world' });
|
||||
socket.on('my other event', function (data) {
|
||||
console.log(data);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
#### Express 2.x
|
||||
|
||||
```js
|
||||
var app = express.createServer()
|
||||
, io = io.listen(app);
|
||||
|
||||
app.listen(80);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.emit('news', { hello: 'world' });
|
||||
socket.on('my other event', function (data) {
|
||||
console.log(data);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
Finally, load it from the client side code:
|
||||
|
||||
```html
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script>
|
||||
var socket = io.connect('http://localhost');
|
||||
socket.on('news', function (data) {
|
||||
console.log(data);
|
||||
socket.emit('my other event', { my: 'data' });
|
||||
});
|
||||
</script>
|
||||
```
|
||||
|
||||
For more thorough examples, look at the `examples/` directory.
|
||||
|
||||
## Short recipes
|
||||
|
||||
### Sending and receiving events.
|
||||
|
||||
Socket.IO allows you to emit and receive custom events.
|
||||
Besides `connect`, `message` and `disconnect`, you can emit custom events:
|
||||
|
||||
```js
|
||||
// note, io.listen(<port>) will create a http server for you
|
||||
var io = require('socket.io').listen(80);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
io.sockets.emit('this', { will: 'be received by everyone' });
|
||||
|
||||
socket.on('private message', function (from, msg) {
|
||||
console.log('I received a private message by ', from, ' saying ', msg);
|
||||
});
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
io.sockets.emit('user disconnected');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
### Storing data associated to a client
|
||||
|
||||
Sometimes it's necessary to store data associated with a client that's
|
||||
necessary for the duration of the session.
|
||||
|
||||
#### Server side
|
||||
|
||||
```js
|
||||
var io = require('socket.io').listen(80);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.on('set nickname', function (name) {
|
||||
socket.set('nickname', name, function () { socket.emit('ready'); });
|
||||
});
|
||||
|
||||
socket.on('msg', function () {
|
||||
socket.get('nickname', function (err, name) {
|
||||
console.log('Chat message by ', name);
|
||||
});
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
#### Client side
|
||||
|
||||
```html
|
||||
<script>
|
||||
var socket = io.connect('http://localhost');
|
||||
|
||||
socket.on('connect', function () {
|
||||
socket.emit('set nickname', prompt('What is your nickname?'));
|
||||
socket.on('ready', function () {
|
||||
console.log('Connected !');
|
||||
socket.emit('msg', prompt('What is your message?'));
|
||||
});
|
||||
});
|
||||
</script>
|
||||
```
|
||||
|
||||
### Restricting yourself to a namespace
|
||||
|
||||
If you have control over all the messages and events emitted for a particular
|
||||
application, using the default `/` namespace works.
|
||||
|
||||
If you want to leverage 3rd-party code, or produce code to share with others,
|
||||
socket.io provides a way of namespacing a `socket`.
|
||||
|
||||
This has the benefit of `multiplexing` a single connection. Instead of
|
||||
socket.io using two `WebSocket` connections, it'll use one.
|
||||
|
||||
The following example defines a socket that listens on '/chat' and one for
|
||||
'/news':
|
||||
|
||||
#### Server side
|
||||
|
||||
```js
|
||||
var io = require('socket.io').listen(80);
|
||||
|
||||
var chat = io
|
||||
.of('/chat')
|
||||
.on('connection', function (socket) {
|
||||
socket.emit('a message', { that: 'only', '/chat': 'will get' });
|
||||
chat.emit('a message', { everyone: 'in', '/chat': 'will get' });
|
||||
});
|
||||
|
||||
var news = io
|
||||
.of('/news');
|
||||
.on('connection', function (socket) {
|
||||
socket.emit('item', { news: 'item' });
|
||||
});
|
||||
```
|
||||
|
||||
#### Client side:
|
||||
|
||||
```html
|
||||
<script>
|
||||
var chat = io.connect('http://localhost/chat')
|
||||
, news = io.connect('http://localhost/news');
|
||||
|
||||
chat.on('connect', function () {
|
||||
chat.emit('hi!');
|
||||
});
|
||||
|
||||
news.on('news', function () {
|
||||
news.emit('woot');
|
||||
});
|
||||
</script>
|
||||
```
|
||||
|
||||
### Sending volatile messages.
|
||||
|
||||
Sometimes certain messages can be dropped. Let's say you have an app that
|
||||
shows realtime tweets for the keyword `bieber`.
|
||||
|
||||
If a certain client is not ready to receive messages (because of network slowness
|
||||
or other issues, or because he's connected through long polling and is in the
|
||||
middle of a request-response cycle), if he doesn't receive ALL the tweets related
|
||||
to bieber your application won't suffer.
|
||||
|
||||
In that case, you might want to send those messages as volatile messages.
|
||||
|
||||
#### Server side
|
||||
|
||||
```js
|
||||
var io = require('socket.io').listen(80);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
var tweets = setInterval(function () {
|
||||
getBieberTweet(function (tweet) {
|
||||
socket.volatile.emit('bieber tweet', tweet);
|
||||
});
|
||||
}, 100);
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
clearInterval(tweets);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
#### Client side
|
||||
|
||||
In the client side, messages are received the same way whether they're volatile
|
||||
or not.
|
||||
|
||||
### Getting acknowledgements
|
||||
|
||||
Sometimes, you might want to get a callback when the client confirmed the message
|
||||
reception.
|
||||
|
||||
To do this, simply pass a function as the last parameter of `.send` or `.emit`.
|
||||
What's more, when you use `.emit`, the acknowledgement is done by you, which
|
||||
means you can also pass data along:
|
||||
|
||||
#### Server side
|
||||
|
||||
```js
|
||||
var io = require('socket.io').listen(80);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.on('ferret', function (name, fn) {
|
||||
fn('woot');
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
#### Client side
|
||||
|
||||
```html
|
||||
<script>
|
||||
var socket = io.connect(); // TIP: .connect with no args does auto-discovery
|
||||
socket.on('connect', function () { // TIP: you can avoid listening on `connect` and listen on events directly too!
|
||||
socket.emit('ferret', 'tobi', function (data) {
|
||||
console.log(data); // data will be 'woot'
|
||||
});
|
||||
});
|
||||
</script>
|
||||
```
|
||||
|
||||
### Broadcasting messages
|
||||
|
||||
To broadcast, simply add a `broadcast` flag to `emit` and `send` method calls.
|
||||
Broadcasting means sending a message to everyone else except for the socket
|
||||
that starts it.
|
||||
|
||||
#### Server side
|
||||
|
||||
```js
|
||||
var io = require('socket.io').listen(80);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.broadcast.emit('user connected');
|
||||
socket.broadcast.json.send({ a: 'message' });
|
||||
});
|
||||
```
|
||||
|
||||
### Rooms
|
||||
|
||||
Sometimes you want to put certain sockets in the same room, so that it's easy
|
||||
to broadcast to all of them together.
|
||||
|
||||
Think of this as built-in channels for sockets. Sockets `join` and `leave`
|
||||
rooms in each socket.
|
||||
|
||||
#### Server side
|
||||
|
||||
```js
|
||||
var io = require('socket.io').listen(80);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.join('justin bieber fans');
|
||||
socket.broadcast.to('justin bieber fans').emit('new fan');
|
||||
io.sockets.in('rammstein fans').emit('new non-fan');
|
||||
});
|
||||
```
|
||||
|
||||
### Using it just as a cross-browser WebSocket
|
||||
|
||||
If you just want the WebSocket semantics, you can do that too.
|
||||
Simply leverage `send` and listen on the `message` event:
|
||||
|
||||
#### Server side
|
||||
|
||||
```js
|
||||
var io = require('socket.io').listen(80);
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
socket.on('message', function () { });
|
||||
socket.on('disconnect', function () { });
|
||||
});
|
||||
```
|
||||
|
||||
#### Client side
|
||||
|
||||
```html
|
||||
<script>
|
||||
var socket = io.connect('http://localhost/');
|
||||
socket.on('connect', function () {
|
||||
socket.send('hi');
|
||||
|
||||
socket.on('message', function (msg) {
|
||||
// my msg
|
||||
});
|
||||
});
|
||||
</script>
|
||||
```
|
||||
|
||||
### Changing configuration
|
||||
|
||||
Configuration in socket.io is TJ-style:
|
||||
|
||||
#### Server side
|
||||
|
||||
```js
|
||||
var io = require('socket.io').listen(80);
|
||||
|
||||
io.configure(function () {
|
||||
io.set('transports', ['websocket', 'flashsocket', 'xhr-polling']);
|
||||
});
|
||||
|
||||
io.configure('development', function () {
|
||||
io.set('transports', ['websocket', 'xhr-polling']);
|
||||
io.enable('log');
|
||||
});
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2011 Guillermo Rauch <guillermo@learnboost.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
64
realtime/node_modules/socket.io/benchmarks/decode.bench.js
generated
vendored
Normal file
64
realtime/node_modules/socket.io/benchmarks/decode.bench.js
generated
vendored
Normal file
|
@ -0,0 +1,64 @@
|
|||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var benchmark = require('benchmark')
|
||||
, colors = require('colors')
|
||||
, io = require('../')
|
||||
, parser = io.parser
|
||||
, suite = new benchmark.Suite('Decode packet');
|
||||
|
||||
suite.add('string', function () {
|
||||
parser.decodePacket('4:::"2"');
|
||||
});
|
||||
|
||||
suite.add('event', function () {
|
||||
parser.decodePacket('5:::{"name":"woot"}');
|
||||
});
|
||||
|
||||
suite.add('event+ack', function () {
|
||||
parser.decodePacket('5:1+::{"name":"tobi"}');
|
||||
});
|
||||
|
||||
suite.add('event+data', function () {
|
||||
parser.decodePacket('5:::{"name":"edwald","args":[{"a": "b"},2,"3"]}');
|
||||
});
|
||||
|
||||
suite.add('heartbeat', function () {
|
||||
parser.decodePacket('2:::');
|
||||
});
|
||||
|
||||
suite.add('error', function () {
|
||||
parser.decodePacket('7:::2+0');
|
||||
});
|
||||
|
||||
var payload = parser.encodePayload([
|
||||
parser.encodePacket({ type: 'message', data: '5', endpoint: '' })
|
||||
, parser.encodePacket({ type: 'message', data: '53d', endpoint: '' })
|
||||
, parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
|
||||
, parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
|
||||
, parser.encodePacket({ type: 'message', data: 'foobarbazfoobarbaz', endpoint: '' })
|
||||
, parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
|
||||
, parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
|
||||
]);
|
||||
|
||||
suite.add('payload', function () {
|
||||
parser.decodePayload(payload);
|
||||
});
|
||||
|
||||
suite.on('cycle', function (bench, details) {
|
||||
console.log('\n' + suite.name.grey, details.name.white.bold);
|
||||
console.log([
|
||||
details.hz.toFixed(2).cyan + ' ops/sec'.grey
|
||||
, details.count.toString().white + ' times executed'.grey
|
||||
, 'benchmark took '.grey + details.times.elapsed.toString().white + ' sec.'.grey
|
||||
,
|
||||
].join(', '.grey));
|
||||
});
|
||||
|
||||
if (!module.parent) {
|
||||
suite.run();
|
||||
} else {
|
||||
module.exports = suite;
|
||||
}
|
90
realtime/node_modules/socket.io/benchmarks/encode.bench.js
generated
vendored
Normal file
90
realtime/node_modules/socket.io/benchmarks/encode.bench.js
generated
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var benchmark = require('benchmark')
|
||||
, colors = require('colors')
|
||||
, io = require('../')
|
||||
, parser = io.parser
|
||||
, suite = new benchmark.Suite('Encode packet');
|
||||
|
||||
suite.add('string', function () {
|
||||
parser.encodePacket({
|
||||
type: 'json'
|
||||
, endpoint: ''
|
||||
, data: '2'
|
||||
});
|
||||
});
|
||||
|
||||
suite.add('event', function () {
|
||||
parser.encodePacket({
|
||||
type: 'event'
|
||||
, name: 'woot'
|
||||
, endpoint: ''
|
||||
, args: []
|
||||
});
|
||||
});
|
||||
|
||||
suite.add('event+ack', function () {
|
||||
parser.encodePacket({
|
||||
type: 'json'
|
||||
, id: 1
|
||||
, ack: 'data'
|
||||
, endpoint: ''
|
||||
, data: { a: 'b' }
|
||||
});
|
||||
});
|
||||
|
||||
suite.add('event+data', function () {
|
||||
parser.encodePacket({
|
||||
type: 'event'
|
||||
, name: 'edwald'
|
||||
, endpoint: ''
|
||||
, args: [{a: 'b'}, 2, '3']
|
||||
});
|
||||
});
|
||||
|
||||
suite.add('heartbeat', function () {
|
||||
parser.encodePacket({
|
||||
type: 'heartbeat'
|
||||
, endpoint: ''
|
||||
})
|
||||
});
|
||||
|
||||
suite.add('error', function () {
|
||||
parser.encodePacket({
|
||||
type: 'error'
|
||||
, reason: 'unauthorized'
|
||||
, advice: 'reconnect'
|
||||
, endpoint: ''
|
||||
})
|
||||
})
|
||||
|
||||
suite.add('payload', function () {
|
||||
parser.encodePayload([
|
||||
parser.encodePacket({ type: 'message', data: '5', endpoint: '' })
|
||||
, parser.encodePacket({ type: 'message', data: '53d', endpoint: '' })
|
||||
, parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
|
||||
, parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
|
||||
, parser.encodePacket({ type: 'message', data: 'foobarbazfoobarbaz', endpoint: '' })
|
||||
, parser.encodePacket({ type: 'message', data: 'foobarbaz', endpoint: '' })
|
||||
, parser.encodePacket({ type: 'message', data: 'foobar', endpoint: '' })
|
||||
]);
|
||||
});
|
||||
|
||||
suite.on('cycle', function (bench, details) {
|
||||
console.log('\n' + suite.name.grey, details.name.white.bold);
|
||||
console.log([
|
||||
details.hz.toFixed(2).cyan + ' ops/sec'.grey
|
||||
, details.count.toString().white + ' times executed'.grey
|
||||
, 'benchmark took '.grey + details.times.elapsed.toString().white + ' sec.'.grey
|
||||
,
|
||||
].join(', '.grey));
|
||||
});
|
||||
|
||||
if (!module.parent) {
|
||||
suite.run();
|
||||
} else {
|
||||
module.exports = suite;
|
||||
}
|
55
realtime/node_modules/socket.io/benchmarks/runner.js
generated
vendored
Normal file
55
realtime/node_modules/socket.io/benchmarks/runner.js
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* Benchmark runner dependencies
|
||||
*/
|
||||
|
||||
var colors = require('colors')
|
||||
, path = require('path');
|
||||
|
||||
/**
|
||||
* Find all the benchmarks
|
||||
*/
|
||||
|
||||
var benchmarks_files = process.env.BENCHMARKS.split(' ')
|
||||
, all = [].concat(benchmarks_files)
|
||||
, first = all.shift()
|
||||
, benchmarks = {};
|
||||
|
||||
// find the benchmarks and load them all in our obj
|
||||
benchmarks_files.forEach(function (file) {
|
||||
benchmarks[file] = require(path.join(__dirname, '..', file));
|
||||
});
|
||||
|
||||
// setup the complete listeners
|
||||
benchmarks_files.forEach(function (file) {
|
||||
var benchmark = benchmarks[file]
|
||||
, next_file = all.shift()
|
||||
, next = benchmarks[next_file];
|
||||
|
||||
/**
|
||||
* Generate a oncomplete function for the tests, either we are done or we
|
||||
* have more benchmarks to process.
|
||||
*/
|
||||
|
||||
function complete () {
|
||||
if (!next) {
|
||||
console.log(
|
||||
'\n\nBenchmark completed in'.grey
|
||||
, (Date.now() - start).toString().green + ' ms'.grey
|
||||
);
|
||||
} else {
|
||||
console.log('\nStarting benchmark '.grey + next_file.yellow);
|
||||
next.run();
|
||||
}
|
||||
}
|
||||
|
||||
// attach the listener
|
||||
benchmark.on('complete', complete);
|
||||
});
|
||||
|
||||
/**
|
||||
* Start the benchmark
|
||||
*/
|
||||
|
||||
var start = Date.now();
|
||||
console.log('Starting benchmark '.grey + first.yellow);
|
||||
benchmarks[first].run();
|
8
realtime/node_modules/socket.io/index.js
generated
vendored
Normal file
8
realtime/node_modules/socket.io/index.js
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
/*!
|
||||
* socket.io-node
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
module.exports = require('./lib/socket.io');
|
97
realtime/node_modules/socket.io/lib/logger.js
generated
vendored
Normal file
97
realtime/node_modules/socket.io/lib/logger.js
generated
vendored
Normal file
|
@ -0,0 +1,97 @@
|
|||
|
||||
/*!
|
||||
* socket.io-node
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var util = require('./util')
|
||||
, toArray = util.toArray;
|
||||
|
||||
/**
|
||||
* Log levels.
|
||||
*/
|
||||
|
||||
var levels = [
|
||||
'error'
|
||||
, 'warn'
|
||||
, 'info'
|
||||
, 'debug'
|
||||
];
|
||||
|
||||
/**
|
||||
* Colors for log levels.
|
||||
*/
|
||||
|
||||
var colors = [
|
||||
31
|
||||
, 33
|
||||
, 36
|
||||
, 90
|
||||
];
|
||||
|
||||
/**
|
||||
* Pads the nice output to the longest log level.
|
||||
*/
|
||||
|
||||
function pad (str) {
|
||||
var max = 0;
|
||||
|
||||
for (var i = 0, l = levels.length; i < l; i++)
|
||||
max = Math.max(max, levels[i].length);
|
||||
|
||||
if (str.length < max)
|
||||
return str + new Array(max - str.length + 1).join(' ');
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
/**
|
||||
* Logger (console).
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
var Logger = module.exports = function (opts) {
|
||||
opts = opts || {}
|
||||
this.colors = false !== opts.colors;
|
||||
this.level = 3;
|
||||
this.enabled = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Log method.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Logger.prototype.log = function (type) {
|
||||
var index = levels.indexOf(type);
|
||||
|
||||
if (index > this.level || !this.enabled)
|
||||
return this;
|
||||
|
||||
console.log.apply(
|
||||
console
|
||||
, [this.colors
|
||||
? ' \033[' + colors[index] + 'm' + pad(type) + ' -\033[39m'
|
||||
: type + ':'
|
||||
].concat(toArray(arguments).slice(1))
|
||||
);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate methods.
|
||||
*/
|
||||
|
||||
levels.forEach(function (name) {
|
||||
Logger.prototype[name] = function () {
|
||||
this.log.apply(this, [name].concat(toArray(arguments)));
|
||||
};
|
||||
});
|
1026
realtime/node_modules/socket.io/lib/manager.js
generated
vendored
Normal file
1026
realtime/node_modules/socket.io/lib/manager.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
355
realtime/node_modules/socket.io/lib/namespace.js
generated
vendored
Normal file
355
realtime/node_modules/socket.io/lib/namespace.js
generated
vendored
Normal file
|
@ -0,0 +1,355 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var Socket = require('./socket')
|
||||
, EventEmitter = process.EventEmitter
|
||||
, parser = require('./parser')
|
||||
, util = require('./util');
|
||||
|
||||
/**
|
||||
* Exports the constructor.
|
||||
*/
|
||||
|
||||
exports = module.exports = SocketNamespace;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @api public.
|
||||
*/
|
||||
|
||||
function SocketNamespace (mgr, name) {
|
||||
this.manager = mgr;
|
||||
this.name = name || '';
|
||||
this.sockets = {};
|
||||
this.auth = false;
|
||||
this.setFlags();
|
||||
};
|
||||
|
||||
/**
|
||||
* Inherits from EventEmitter.
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.__proto__ = EventEmitter.prototype;
|
||||
|
||||
/**
|
||||
* Copies emit since we override it.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.$emit = EventEmitter.prototype.emit;
|
||||
|
||||
/**
|
||||
* Retrieves all clients as Socket instances as an array.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.clients = function (room) {
|
||||
var room = this.name + (room !== undefined ?
|
||||
'/' + room : '');
|
||||
|
||||
if (!this.manager.rooms[room]) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return this.manager.rooms[room].map(function (id) {
|
||||
return this.socket(id);
|
||||
}, this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Access logger interface.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.__defineGetter__('log', function () {
|
||||
return this.manager.log;
|
||||
});
|
||||
|
||||
/**
|
||||
* Access store.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.__defineGetter__('store', function () {
|
||||
return this.manager.store;
|
||||
});
|
||||
|
||||
/**
|
||||
* JSON message flag.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.__defineGetter__('json', function () {
|
||||
this.flags.json = true;
|
||||
return this;
|
||||
});
|
||||
|
||||
/**
|
||||
* Volatile message flag.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.__defineGetter__('volatile', function () {
|
||||
this.flags.volatile = true;
|
||||
return this;
|
||||
});
|
||||
|
||||
/**
|
||||
* Overrides the room to relay messages to (flag).
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.in = SocketNamespace.prototype.to = function (room) {
|
||||
this.flags.endpoint = this.name + (room ? '/' + room : '');
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a session id we should prevent relaying messages to (flag).
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.except = function (id) {
|
||||
this.flags.exceptions.push(id);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the default flags.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.setFlags = function () {
|
||||
this.flags = {
|
||||
endpoint: this.name
|
||||
, exceptions: []
|
||||
};
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends out a packet.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.packet = function (packet) {
|
||||
packet.endpoint = this.name;
|
||||
|
||||
var store = this.store
|
||||
, log = this.log
|
||||
, volatile = this.flags.volatile
|
||||
, exceptions = this.flags.exceptions
|
||||
, packet = parser.encodePacket(packet);
|
||||
|
||||
this.manager.onDispatch(this.flags.endpoint, packet, volatile, exceptions);
|
||||
this.store.publish('dispatch', this.flags.endpoint, packet, volatile, exceptions);
|
||||
|
||||
this.setFlags();
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends to everyone.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.send = function (data) {
|
||||
return this.packet({
|
||||
type: this.flags.json ? 'json' : 'message'
|
||||
, data: data
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Emits to everyone (override).
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.emit = function (name) {
|
||||
if (name == 'newListener') {
|
||||
return this.$emit.apply(this, arguments);
|
||||
}
|
||||
|
||||
return this.packet({
|
||||
type: 'event'
|
||||
, name: name
|
||||
, args: util.toArray(arguments).slice(1)
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves or creates a write-only socket for a client, unless specified.
|
||||
*
|
||||
* @param {Boolean} whether the socket will be readable when initialized
|
||||
* @api public
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.socket = function (sid, readable) {
|
||||
if (!this.sockets[sid]) {
|
||||
this.sockets[sid] = new Socket(this.manager, sid, this, readable);
|
||||
}
|
||||
|
||||
return this.sockets[sid];
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets authorization for this namespace.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.authorization = function (fn) {
|
||||
this.auth = fn;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when a socket disconnects entirely.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.handleDisconnect = function (sid, reason, raiseOnDisconnect) {
|
||||
if (this.sockets[sid] && this.sockets[sid].readable) {
|
||||
if (raiseOnDisconnect) this.sockets[sid].onDisconnect(reason);
|
||||
delete this.sockets[sid];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Performs authentication.
|
||||
*
|
||||
* @param Object client request data
|
||||
* @api private
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.authorize = function (data, fn) {
|
||||
if (this.auth) {
|
||||
var self = this;
|
||||
|
||||
this.auth.call(this, data, function (err, authorized) {
|
||||
self.log.debug('client ' +
|
||||
(authorized ? '' : 'un') + 'authorized for ' + self.name);
|
||||
fn(err, authorized);
|
||||
});
|
||||
} else {
|
||||
this.log.debug('client authorized for ' + this.name);
|
||||
fn(null, true);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles a packet.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
SocketNamespace.prototype.handlePacket = function (sessid, packet) {
|
||||
var socket = this.socket(sessid)
|
||||
, dataAck = packet.ack == 'data'
|
||||
, manager = this.manager
|
||||
, self = this;
|
||||
|
||||
function ack () {
|
||||
self.log.debug('sending data ack packet');
|
||||
socket.packet({
|
||||
type: 'ack'
|
||||
, args: util.toArray(arguments)
|
||||
, ackId: packet.id
|
||||
});
|
||||
};
|
||||
|
||||
function error (err) {
|
||||
self.log.warn('handshake error ' + err + ' for ' + self.name);
|
||||
socket.packet({ type: 'error', reason: err });
|
||||
};
|
||||
|
||||
function connect () {
|
||||
self.manager.onJoin(sessid, self.name);
|
||||
self.store.publish('join', sessid, self.name);
|
||||
|
||||
// packet echo
|
||||
socket.packet({ type: 'connect' });
|
||||
|
||||
// emit connection event
|
||||
self.$emit('connection', socket);
|
||||
};
|
||||
|
||||
switch (packet.type) {
|
||||
case 'connect':
|
||||
if (packet.endpoint == '') {
|
||||
connect();
|
||||
} else {
|
||||
var handshakeData = manager.handshaken[sessid];
|
||||
|
||||
this.authorize(handshakeData, function (err, authorized, newData) {
|
||||
if (err) return error(err);
|
||||
|
||||
if (authorized) {
|
||||
manager.onHandshake(sessid, newData || handshakeData);
|
||||
self.store.publish('handshake', sessid, newData || handshakeData);
|
||||
connect();
|
||||
} else {
|
||||
error('unauthorized');
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
case 'ack':
|
||||
if (socket.acks[packet.ackId]) {
|
||||
socket.acks[packet.ackId].apply(socket, packet.args);
|
||||
} else {
|
||||
this.log.info('unknown ack packet');
|
||||
}
|
||||
break;
|
||||
|
||||
case 'event':
|
||||
// check if the emitted event is not blacklisted
|
||||
if (-~manager.get('blacklist').indexOf(packet.name)) {
|
||||
this.log.debug('ignoring blacklisted event `' + packet.name + '`');
|
||||
} else {
|
||||
var params = [packet.name].concat(packet.args);
|
||||
|
||||
if (dataAck) {
|
||||
params.push(ack);
|
||||
}
|
||||
|
||||
socket.$emit.apply(socket, params);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'disconnect':
|
||||
this.manager.onLeave(sessid, this.name);
|
||||
this.store.publish('leave', sessid, this.name);
|
||||
|
||||
socket.$emit('disconnect', packet.reason || 'packet');
|
||||
break;
|
||||
|
||||
case 'json':
|
||||
case 'message':
|
||||
var params = ['message', packet.data];
|
||||
|
||||
if (dataAck)
|
||||
params.push(ack);
|
||||
|
||||
socket.$emit.apply(socket, params);
|
||||
};
|
||||
};
|
249
realtime/node_modules/socket.io/lib/parser.js
generated
vendored
Normal file
249
realtime/node_modules/socket.io/lib/parser.js
generated
vendored
Normal file
|
@ -0,0 +1,249 @@
|
|||
|
||||
/*!
|
||||
* socket.io-node
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Packet types.
|
||||
*/
|
||||
|
||||
var packets = exports.packets = {
|
||||
'disconnect': 0
|
||||
, 'connect': 1
|
||||
, 'heartbeat': 2
|
||||
, 'message': 3
|
||||
, 'json': 4
|
||||
, 'event': 5
|
||||
, 'ack': 6
|
||||
, 'error': 7
|
||||
, 'noop': 8
|
||||
}
|
||||
, packetslist = Object.keys(packets);
|
||||
|
||||
/**
|
||||
* Errors reasons.
|
||||
*/
|
||||
|
||||
var reasons = exports.reasons = {
|
||||
'transport not supported': 0
|
||||
, 'client not handshaken': 1
|
||||
, 'unauthorized': 2
|
||||
}
|
||||
, reasonslist = Object.keys(reasons);
|
||||
|
||||
/**
|
||||
* Errors advice.
|
||||
*/
|
||||
|
||||
var advice = exports.advice = {
|
||||
'reconnect': 0
|
||||
}
|
||||
, advicelist = Object.keys(advice);
|
||||
|
||||
/**
|
||||
* Encodes a packet.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.encodePacket = function (packet) {
|
||||
var type = packets[packet.type]
|
||||
, id = packet.id || ''
|
||||
, endpoint = packet.endpoint || ''
|
||||
, ack = packet.ack
|
||||
, data = null;
|
||||
|
||||
switch (packet.type) {
|
||||
case 'message':
|
||||
if (packet.data !== '')
|
||||
data = packet.data;
|
||||
break;
|
||||
|
||||
case 'event':
|
||||
var ev = { name: packet.name };
|
||||
|
||||
if (packet.args && packet.args.length) {
|
||||
ev.args = packet.args;
|
||||
}
|
||||
|
||||
data = JSON.stringify(ev);
|
||||
break;
|
||||
|
||||
case 'json':
|
||||
data = JSON.stringify(packet.data);
|
||||
break;
|
||||
|
||||
case 'ack':
|
||||
data = packet.ackId
|
||||
+ (packet.args && packet.args.length
|
||||
? '+' + JSON.stringify(packet.args) : '');
|
||||
break;
|
||||
|
||||
case 'connect':
|
||||
if (packet.qs)
|
||||
data = packet.qs;
|
||||
break;
|
||||
|
||||
case 'error':
|
||||
var reason = packet.reason ? reasons[packet.reason] : ''
|
||||
, adv = packet.advice ? advice[packet.advice] : ''
|
||||
|
||||
if (reason !== '' || adv !== '')
|
||||
data = reason + (adv !== '' ? ('+' + adv) : '')
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// construct packet with required fragments
|
||||
var encoded = type + ':' + id + (ack == 'data' ? '+' : '') + ':' + endpoint;
|
||||
|
||||
// data fragment is optional
|
||||
if (data !== null && data !== undefined)
|
||||
encoded += ':' + data;
|
||||
|
||||
return encoded;
|
||||
};
|
||||
|
||||
/**
|
||||
* Encodes multiple messages (payload).
|
||||
*
|
||||
* @param {Array} messages
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.encodePayload = function (packets) {
|
||||
var decoded = '';
|
||||
|
||||
if (packets.length == 1)
|
||||
return packets[0];
|
||||
|
||||
for (var i = 0, l = packets.length; i < l; i++) {
|
||||
var packet = packets[i];
|
||||
decoded += '\ufffd' + packet.length + '\ufffd' + packets[i]
|
||||
}
|
||||
|
||||
return decoded;
|
||||
};
|
||||
|
||||
/**
|
||||
* Decodes a packet
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
var regexp = /([^:]+):([0-9]+)?(\+)?:([^:]+)?:?([\s\S]*)?/;
|
||||
|
||||
/**
|
||||
* Wrap the JSON.parse in a seperate function the crankshaft optimizer will
|
||||
* only punish this function for the usage for try catch
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function parse (data) {
|
||||
try { return JSON.parse(data) }
|
||||
catch (e) { return false }
|
||||
}
|
||||
|
||||
exports.decodePacket = function (data) {
|
||||
var pieces = data.match(regexp);
|
||||
|
||||
if (!pieces) return {};
|
||||
|
||||
var id = pieces[2] || ''
|
||||
, data = pieces[5] || ''
|
||||
, packet = {
|
||||
type: packetslist[pieces[1]]
|
||||
, endpoint: pieces[4] || ''
|
||||
};
|
||||
|
||||
// whether we need to acknowledge the packet
|
||||
if (id) {
|
||||
packet.id = id;
|
||||
if (pieces[3])
|
||||
packet.ack = 'data';
|
||||
else
|
||||
packet.ack = true;
|
||||
}
|
||||
|
||||
// handle different packet types
|
||||
switch (packet.type) {
|
||||
case 'message':
|
||||
packet.data = data || '';
|
||||
break;
|
||||
|
||||
case 'event':
|
||||
pieces = parse(data);
|
||||
if (pieces) {
|
||||
packet.name = pieces.name;
|
||||
packet.args = pieces.args;
|
||||
}
|
||||
|
||||
packet.args = packet.args || [];
|
||||
break;
|
||||
|
||||
case 'json':
|
||||
packet.data = parse(data);
|
||||
break;
|
||||
|
||||
case 'connect':
|
||||
packet.qs = data || '';
|
||||
break;
|
||||
|
||||
case 'ack':
|
||||
pieces = data.match(/^([0-9]+)(\+)?(.*)/);
|
||||
if (pieces) {
|
||||
packet.ackId = pieces[1];
|
||||
packet.args = [];
|
||||
|
||||
if (pieces[3]) {
|
||||
packet.args = parse(pieces[3]) || [];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'error':
|
||||
pieces = data.split('+');
|
||||
packet.reason = reasonslist[pieces[0]] || '';
|
||||
packet.advice = advicelist[pieces[1]] || '';
|
||||
}
|
||||
|
||||
return packet;
|
||||
};
|
||||
|
||||
/**
|
||||
* Decodes data payload. Detects multiple messages
|
||||
*
|
||||
* @return {Array} messages
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.decodePayload = function (data) {
|
||||
if (undefined == data || null == data) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (data[0] == '\ufffd') {
|
||||
var ret = [];
|
||||
|
||||
for (var i = 1, length = ''; i < data.length; i++) {
|
||||
if (data[i] == '\ufffd') {
|
||||
ret.push(exports.decodePacket(data.substr(i + 1, length)));
|
||||
i += Number(length) + 1;
|
||||
length = '';
|
||||
} else {
|
||||
length += data[i];
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
} else {
|
||||
return [exports.decodePacket(data)];
|
||||
}
|
||||
};
|
143
realtime/node_modules/socket.io/lib/socket.io.js
generated
vendored
Normal file
143
realtime/node_modules/socket.io/lib/socket.io.js
generated
vendored
Normal file
|
@ -0,0 +1,143 @@
|
|||
|
||||
/*!
|
||||
* socket.io-node
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var client = require('socket.io-client');
|
||||
|
||||
/**
|
||||
* Version.
|
||||
*/
|
||||
|
||||
exports.version = '0.9.11';
|
||||
|
||||
/**
|
||||
* Supported protocol version.
|
||||
*/
|
||||
|
||||
exports.protocol = 1;
|
||||
|
||||
/**
|
||||
* Client that we serve.
|
||||
*/
|
||||
|
||||
exports.clientVersion = client.version;
|
||||
|
||||
/**
|
||||
* Attaches a manager
|
||||
*
|
||||
* @param {HTTPServer/Number} a HTTP/S server or a port number to listen on.
|
||||
* @param {Object} opts to be passed to Manager and/or http server
|
||||
* @param {Function} callback if a port is supplied
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.listen = function (server, options, fn) {
|
||||
if ('function' == typeof server) {
|
||||
console.warn('Socket.IO\'s `listen()` method expects an `http.Server` instance\n'
|
||||
+ 'as its first parameter. Are you migrating from Express 2.x to 3.x?\n'
|
||||
+ 'If so, check out the "Socket.IO compatibility" section at:\n'
|
||||
+ 'https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x');
|
||||
}
|
||||
|
||||
if ('function' == typeof options) {
|
||||
fn = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
if ('undefined' == typeof server) {
|
||||
// create a server that listens on port 80
|
||||
server = 80;
|
||||
}
|
||||
|
||||
if ('number' == typeof server) {
|
||||
// if a port number is passed
|
||||
var port = server;
|
||||
|
||||
if (options && options.key)
|
||||
server = require('https').createServer(options);
|
||||
else
|
||||
server = require('http').createServer();
|
||||
|
||||
// default response
|
||||
server.on('request', function (req, res) {
|
||||
res.writeHead(200);
|
||||
res.end('Welcome to socket.io.');
|
||||
});
|
||||
|
||||
server.listen(port, fn);
|
||||
}
|
||||
|
||||
// otherwise assume a http/s server
|
||||
return new exports.Manager(server, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Manager constructor.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.Manager = require('./manager');
|
||||
|
||||
/**
|
||||
* Transport constructor.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.Transport = require('./transport');
|
||||
|
||||
/**
|
||||
* Socket constructor.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.Socket = require('./socket');
|
||||
|
||||
/**
|
||||
* Static constructor.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.Static = require('./static');
|
||||
|
||||
/**
|
||||
* Store constructor.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.Store = require('./store');
|
||||
|
||||
/**
|
||||
* Memory Store constructor.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.MemoryStore = require('./stores/memory');
|
||||
|
||||
/**
|
||||
* Redis Store constructor.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.RedisStore = require('./stores/redis');
|
||||
|
||||
/**
|
||||
* Parser.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.parser = require('./parser');
|
369
realtime/node_modules/socket.io/lib/socket.js
generated
vendored
Normal file
369
realtime/node_modules/socket.io/lib/socket.js
generated
vendored
Normal file
|
@ -0,0 +1,369 @@
|
|||
|
||||
/*!
|
||||
* socket.io-node
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var parser = require('./parser')
|
||||
, util = require('./util')
|
||||
, EventEmitter = process.EventEmitter
|
||||
|
||||
/**
|
||||
* Export the constructor.
|
||||
*/
|
||||
|
||||
exports = module.exports = Socket;
|
||||
|
||||
/**
|
||||
* Default error event listener to prevent uncaught exceptions.
|
||||
*/
|
||||
|
||||
var defaultError = function () {};
|
||||
|
||||
/**
|
||||
* Socket constructor.
|
||||
*
|
||||
* @param {Manager} manager instance
|
||||
* @param {String} session id
|
||||
* @param {Namespace} namespace the socket belongs to
|
||||
* @param {Boolean} whether the
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Socket (manager, id, nsp, readable) {
|
||||
this.id = id;
|
||||
this.namespace = nsp;
|
||||
this.manager = manager;
|
||||
this.disconnected = false;
|
||||
this.ackPackets = 0;
|
||||
this.acks = {};
|
||||
this.setFlags();
|
||||
this.readable = readable;
|
||||
this.store = this.manager.store.client(this.id);
|
||||
this.on('error', defaultError);
|
||||
};
|
||||
|
||||
/**
|
||||
* Inherits from EventEmitter.
|
||||
*/
|
||||
|
||||
Socket.prototype.__proto__ = EventEmitter.prototype;
|
||||
|
||||
/**
|
||||
* Accessor shortcut for the handshake data
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.__defineGetter__('handshake', function () {
|
||||
return this.manager.handshaken[this.id];
|
||||
});
|
||||
|
||||
/**
|
||||
* Accessor shortcut for the transport type
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.__defineGetter__('transport', function () {
|
||||
return this.manager.transports[this.id].name;
|
||||
});
|
||||
|
||||
/**
|
||||
* Accessor shortcut for the logger.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.__defineGetter__('log', function () {
|
||||
return this.manager.log;
|
||||
});
|
||||
|
||||
/**
|
||||
* JSON message flag.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.__defineGetter__('json', function () {
|
||||
this.flags.json = true;
|
||||
return this;
|
||||
});
|
||||
|
||||
/**
|
||||
* Volatile message flag.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.__defineGetter__('volatile', function () {
|
||||
this.flags.volatile = true;
|
||||
return this;
|
||||
});
|
||||
|
||||
/**
|
||||
* Broadcast message flag.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.__defineGetter__('broadcast', function () {
|
||||
this.flags.broadcast = true;
|
||||
return this;
|
||||
});
|
||||
|
||||
/**
|
||||
* Overrides the room to broadcast messages to (flag)
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.to = Socket.prototype.in = function (room) {
|
||||
this.flags.room = room;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Resets flags
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.setFlags = function () {
|
||||
this.flags = {
|
||||
endpoint: this.namespace.name
|
||||
, room: ''
|
||||
};
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Triggered on disconnect
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.onDisconnect = function (reason) {
|
||||
if (!this.disconnected) {
|
||||
this.$emit('disconnect', reason);
|
||||
this.disconnected = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Joins a user to a room.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.join = function (name, fn) {
|
||||
var nsp = this.namespace.name
|
||||
, name = (nsp + '/') + name;
|
||||
|
||||
this.manager.onJoin(this.id, name);
|
||||
this.manager.store.publish('join', this.id, name);
|
||||
|
||||
if (fn) {
|
||||
this.log.warn('Client#join callback is deprecated');
|
||||
fn();
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Un-joins a user from a room.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.leave = function (name, fn) {
|
||||
var nsp = this.namespace.name
|
||||
, name = (nsp + '/') + name;
|
||||
|
||||
this.manager.onLeave(this.id, name);
|
||||
this.manager.store.publish('leave', this.id, name);
|
||||
|
||||
if (fn) {
|
||||
this.log.warn('Client#leave callback is deprecated');
|
||||
fn();
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Transmits a packet.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.packet = function (packet) {
|
||||
if (this.flags.broadcast) {
|
||||
this.log.debug('broadcasting packet');
|
||||
this.namespace.in(this.flags.room).except(this.id).packet(packet);
|
||||
} else {
|
||||
packet.endpoint = this.flags.endpoint;
|
||||
packet = parser.encodePacket(packet);
|
||||
|
||||
this.dispatch(packet, this.flags.volatile);
|
||||
}
|
||||
|
||||
this.setFlags();
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispatches a packet
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.dispatch = function (packet, volatile) {
|
||||
if (this.manager.transports[this.id] && this.manager.transports[this.id].open) {
|
||||
this.manager.transports[this.id].onDispatch(packet, volatile);
|
||||
} else {
|
||||
if (!volatile) {
|
||||
this.manager.onClientDispatch(this.id, packet, volatile);
|
||||
}
|
||||
|
||||
this.manager.store.publish('dispatch:' + this.id, packet, volatile);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stores data for the client.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.set = function (key, value, fn) {
|
||||
this.store.set(key, value, fn);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves data for the client
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.get = function (key, fn) {
|
||||
this.store.get(key, fn);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks data for the client
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.has = function (key, fn) {
|
||||
this.store.has(key, fn);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes data for the client
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.del = function (key, fn) {
|
||||
this.store.del(key, fn);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Kicks client
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.disconnect = function () {
|
||||
if (!this.disconnected) {
|
||||
this.log.info('booting client');
|
||||
|
||||
if ('' === this.namespace.name) {
|
||||
if (this.manager.transports[this.id] && this.manager.transports[this.id].open) {
|
||||
this.manager.transports[this.id].onForcedDisconnect();
|
||||
} else {
|
||||
this.manager.onClientDisconnect(this.id);
|
||||
this.manager.store.publish('disconnect:' + this.id);
|
||||
}
|
||||
} else {
|
||||
this.packet({type: 'disconnect'});
|
||||
this.manager.onLeave(this.id, this.namespace.name);
|
||||
this.$emit('disconnect', 'booted');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Send a message.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.send = function (data, fn) {
|
||||
var packet = {
|
||||
type: this.flags.json ? 'json' : 'message'
|
||||
, data: data
|
||||
};
|
||||
|
||||
if (fn) {
|
||||
packet.id = ++this.ackPackets;
|
||||
packet.ack = true;
|
||||
this.acks[packet.id] = fn;
|
||||
}
|
||||
|
||||
return this.packet(packet);
|
||||
};
|
||||
|
||||
/**
|
||||
* Original emit function.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Socket.prototype.$emit = EventEmitter.prototype.emit;
|
||||
|
||||
/**
|
||||
* Emit override for custom events.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Socket.prototype.emit = function (ev) {
|
||||
if (ev == 'newListener') {
|
||||
return this.$emit.apply(this, arguments);
|
||||
}
|
||||
|
||||
var args = util.toArray(arguments).slice(1)
|
||||
, lastArg = args[args.length - 1]
|
||||
, packet = {
|
||||
type: 'event'
|
||||
, name: ev
|
||||
};
|
||||
|
||||
if ('function' == typeof lastArg) {
|
||||
packet.id = ++this.ackPackets;
|
||||
packet.ack = lastArg.length ? 'data' : true;
|
||||
this.acks[packet.id] = lastArg;
|
||||
args = args.slice(0, args.length - 1);
|
||||
}
|
||||
|
||||
packet.args = args;
|
||||
|
||||
return this.packet(packet);
|
||||
};
|
395
realtime/node_modules/socket.io/lib/static.js
generated
vendored
Normal file
395
realtime/node_modules/socket.io/lib/static.js
generated
vendored
Normal file
|
@ -0,0 +1,395 @@
|
|||
|
||||
/*!
|
||||
* socket.io-node
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var client = require('socket.io-client')
|
||||
, cp = require('child_process')
|
||||
, fs = require('fs')
|
||||
, util = require('./util');
|
||||
|
||||
/**
|
||||
* File type details.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
var mime = {
|
||||
js: {
|
||||
type: 'application/javascript'
|
||||
, encoding: 'utf8'
|
||||
, gzip: true
|
||||
}
|
||||
, swf: {
|
||||
type: 'application/x-shockwave-flash'
|
||||
, encoding: 'binary'
|
||||
, gzip: false
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Regexp for matching custom transport patterns. Users can configure their own
|
||||
* socket.io bundle based on the url structure. Different transport names are
|
||||
* concatinated using the `+` char. /socket.io/socket.io+websocket.js should
|
||||
* create a bundle that only contains support for the websocket.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
var bundle = /\+((?:\+)?[\w\-]+)*(?:\.v\d+\.\d+\.\d+)?(?:\.js)$/
|
||||
, versioning = /\.v\d+\.\d+\.\d+(?:\.js)$/;
|
||||
|
||||
/**
|
||||
* Export the constructor
|
||||
*/
|
||||
|
||||
exports = module.exports = Static;
|
||||
|
||||
/**
|
||||
* Static constructor
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Static (manager) {
|
||||
this.manager = manager;
|
||||
this.cache = {};
|
||||
this.paths = {};
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the Static by adding default file paths.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Static.prototype.init = function () {
|
||||
/**
|
||||
* Generates a unique id based the supplied transports array
|
||||
*
|
||||
* @param {Array} transports The array with transport types
|
||||
* @api private
|
||||
*/
|
||||
function id (transports) {
|
||||
var id = transports.join('').split('').map(function (char) {
|
||||
return ('' + char.charCodeAt(0)).split('').pop();
|
||||
}).reduce(function (char, id) {
|
||||
return char +id;
|
||||
});
|
||||
|
||||
return client.version + ':' + id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a socket.io-client file based on the supplied transports.
|
||||
*
|
||||
* @param {Array} transports The array with transport types
|
||||
* @param {Function} callback Callback for the static.write
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function build (transports, callback) {
|
||||
client.builder(transports, {
|
||||
minify: self.manager.enabled('browser client minification')
|
||||
}, function (err, content) {
|
||||
callback(err, content ? new Buffer(content) : null, id(transports));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
// add our default static files
|
||||
this.add('/static/flashsocket/WebSocketMain.swf', {
|
||||
file: client.dist + '/WebSocketMain.swf'
|
||||
});
|
||||
|
||||
this.add('/static/flashsocket/WebSocketMainInsecure.swf', {
|
||||
file: client.dist + '/WebSocketMainInsecure.swf'
|
||||
});
|
||||
|
||||
// generates dedicated build based on the available transports
|
||||
this.add('/socket.io.js', function (path, callback) {
|
||||
build(self.manager.get('transports'), callback);
|
||||
});
|
||||
|
||||
this.add('/socket.io.v', { mime: mime.js }, function (path, callback) {
|
||||
build(self.manager.get('transports'), callback);
|
||||
});
|
||||
|
||||
// allow custom builds based on url paths
|
||||
this.add('/socket.io+', { mime: mime.js }, function (path, callback) {
|
||||
var available = self.manager.get('transports')
|
||||
, matches = path.match(bundle)
|
||||
, transports = [];
|
||||
|
||||
if (!matches) return callback('No valid transports');
|
||||
|
||||
// make sure they valid transports
|
||||
matches[0].split('.')[0].split('+').slice(1).forEach(function (transport) {
|
||||
if (!!~available.indexOf(transport)) {
|
||||
transports.push(transport);
|
||||
}
|
||||
});
|
||||
|
||||
if (!transports.length) return callback('No valid transports');
|
||||
build(transports, callback);
|
||||
});
|
||||
|
||||
// clear cache when transports change
|
||||
this.manager.on('set:transports', function (key, value) {
|
||||
delete self.cache['/socket.io.js'];
|
||||
Object.keys(self.cache).forEach(function (key) {
|
||||
if (bundle.test(key)) {
|
||||
delete self.cache[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Gzip compress buffers.
|
||||
*
|
||||
* @param {Buffer} data The buffer that needs gzip compression
|
||||
* @param {Function} callback
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Static.prototype.gzip = function (data, callback) {
|
||||
var gzip = cp.spawn('gzip', ['-9', '-c', '-f', '-n'])
|
||||
, encoding = Buffer.isBuffer(data) ? 'binary' : 'utf8'
|
||||
, buffer = []
|
||||
, err;
|
||||
|
||||
gzip.stdout.on('data', function (data) {
|
||||
buffer.push(data);
|
||||
});
|
||||
|
||||
gzip.stderr.on('data', function (data) {
|
||||
err = data +'';
|
||||
buffer.length = 0;
|
||||
});
|
||||
|
||||
gzip.on('close', function () {
|
||||
if (err) return callback(err);
|
||||
|
||||
var size = 0
|
||||
, index = 0
|
||||
, i = buffer.length
|
||||
, content;
|
||||
|
||||
while (i--) {
|
||||
size += buffer[i].length;
|
||||
}
|
||||
|
||||
content = new Buffer(size);
|
||||
i = buffer.length;
|
||||
|
||||
buffer.forEach(function (buffer) {
|
||||
var length = buffer.length;
|
||||
|
||||
buffer.copy(content, index, 0, length);
|
||||
index += length;
|
||||
});
|
||||
|
||||
buffer.length = 0;
|
||||
callback(null, content);
|
||||
});
|
||||
|
||||
gzip.stdin.end(data, encoding);
|
||||
};
|
||||
|
||||
/**
|
||||
* Is the path a static file?
|
||||
*
|
||||
* @param {String} path The path that needs to be checked
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Static.prototype.has = function (path) {
|
||||
// fast case
|
||||
if (this.paths[path]) return this.paths[path];
|
||||
|
||||
var keys = Object.keys(this.paths)
|
||||
, i = keys.length;
|
||||
|
||||
while (i--) {
|
||||
if (-~path.indexOf(keys[i])) return this.paths[keys[i]];
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Add new paths new paths that can be served using the static provider.
|
||||
*
|
||||
* @param {String} path The path to respond to
|
||||
* @param {Options} options Options for writing out the response
|
||||
* @param {Function} [callback] Optional callback if no options.file is
|
||||
* supplied this would be called instead.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Static.prototype.add = function (path, options, callback) {
|
||||
var extension = /(?:\.(\w{1,4}))$/.exec(path);
|
||||
|
||||
if (!callback && typeof options == 'function') {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
options.mime = options.mime || (extension ? mime[extension[1]] : false);
|
||||
|
||||
if (callback) options.callback = callback;
|
||||
if (!(options.file || options.callback) || !options.mime) return false;
|
||||
|
||||
this.paths[path] = options;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes a static response.
|
||||
*
|
||||
* @param {String} path The path for the static content
|
||||
* @param {HTTPRequest} req The request object
|
||||
* @param {HTTPResponse} res The response object
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Static.prototype.write = function (path, req, res) {
|
||||
/**
|
||||
* Write a response without throwing errors because can throw error if the
|
||||
* response is no longer writable etc.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function write (status, headers, content, encoding) {
|
||||
try {
|
||||
res.writeHead(status, headers || undefined);
|
||||
|
||||
// only write content if it's not a HEAD request and we actually have
|
||||
// some content to write (304's doesn't have content).
|
||||
res.end(
|
||||
req.method !== 'HEAD' && content ? content : ''
|
||||
, encoding || undefined
|
||||
);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Answers requests depending on the request properties and the reply object.
|
||||
*
|
||||
* @param {Object} reply The details and content to reply the response with
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function answer (reply) {
|
||||
var cached = req.headers['if-none-match'] === reply.etag;
|
||||
if (cached && self.manager.enabled('browser client etag')) {
|
||||
return write(304);
|
||||
}
|
||||
|
||||
var accept = req.headers['accept-encoding'] || ''
|
||||
, gzip = !!~accept.toLowerCase().indexOf('gzip')
|
||||
, mime = reply.mime
|
||||
, versioned = reply.versioned
|
||||
, headers = {
|
||||
'Content-Type': mime.type
|
||||
};
|
||||
|
||||
// check if we can add a etag
|
||||
if (self.manager.enabled('browser client etag') && reply.etag && !versioned) {
|
||||
headers['Etag'] = reply.etag;
|
||||
}
|
||||
|
||||
// see if we need to set Expire headers because the path is versioned
|
||||
if (versioned) {
|
||||
var expires = self.manager.get('browser client expires');
|
||||
headers['Cache-Control'] = 'private, x-gzip-ok="", max-age=' + expires;
|
||||
headers['Date'] = new Date().toUTCString();
|
||||
headers['Expires'] = new Date(Date.now() + (expires * 1000)).toUTCString();
|
||||
}
|
||||
|
||||
if (gzip && reply.gzip) {
|
||||
headers['Content-Length'] = reply.gzip.length;
|
||||
headers['Content-Encoding'] = 'gzip';
|
||||
headers['Vary'] = 'Accept-Encoding';
|
||||
write(200, headers, reply.gzip.content, mime.encoding);
|
||||
} else {
|
||||
headers['Content-Length'] = reply.length;
|
||||
write(200, headers, reply.content, mime.encoding);
|
||||
}
|
||||
|
||||
self.manager.log.debug('served static content ' + path);
|
||||
}
|
||||
|
||||
var self = this
|
||||
, details;
|
||||
|
||||
// most common case first
|
||||
if (this.manager.enabled('browser client cache') && this.cache[path]) {
|
||||
return answer(this.cache[path]);
|
||||
} else if (this.manager.get('browser client handler')) {
|
||||
return this.manager.get('browser client handler').call(this, req, res);
|
||||
} else if ((details = this.has(path))) {
|
||||
/**
|
||||
* A small helper function that will let us deal with fs and dynamic files
|
||||
*
|
||||
* @param {Object} err Optional error
|
||||
* @param {Buffer} content The data
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function ready (err, content, etag) {
|
||||
if (err) {
|
||||
self.manager.log.warn('Unable to serve file. ' + (err.message || err));
|
||||
return write(500, null, 'Error serving static ' + path);
|
||||
}
|
||||
|
||||
// store the result in the cache
|
||||
var reply = self.cache[path] = {
|
||||
content: content
|
||||
, length: content.length
|
||||
, mime: details.mime
|
||||
, etag: etag || client.version
|
||||
, versioned: versioning.test(path)
|
||||
};
|
||||
|
||||
// check if gzip is enabled
|
||||
if (details.mime.gzip && self.manager.enabled('browser client gzip')) {
|
||||
self.gzip(content, function (err, content) {
|
||||
if (!err) {
|
||||
reply.gzip = {
|
||||
content: content
|
||||
, length: content.length
|
||||
}
|
||||
}
|
||||
|
||||
answer(reply);
|
||||
});
|
||||
} else {
|
||||
answer(reply);
|
||||
}
|
||||
}
|
||||
|
||||
if (details.file) {
|
||||
fs.readFile(details.file, ready);
|
||||
} else if(details.callback) {
|
||||
details.callback.call(this, path, ready);
|
||||
} else {
|
||||
write(404, null, 'File handle not found');
|
||||
}
|
||||
} else {
|
||||
write(404, null, 'File not found');
|
||||
}
|
||||
};
|
98
realtime/node_modules/socket.io/lib/store.js
generated
vendored
Normal file
98
realtime/node_modules/socket.io/lib/store.js
generated
vendored
Normal file
|
@ -0,0 +1,98 @@
|
|||
|
||||
/*!
|
||||
* socket.io-node
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Expose the constructor.
|
||||
*/
|
||||
|
||||
exports = module.exports = Store;
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var EventEmitter = process.EventEmitter;
|
||||
|
||||
/**
|
||||
* Store interface
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Store (options) {
|
||||
this.options = options;
|
||||
this.clients = {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Inherit from EventEmitter.
|
||||
*/
|
||||
|
||||
Store.prototype.__proto__ = EventEmitter.prototype;
|
||||
|
||||
/**
|
||||
* Initializes a client store
|
||||
*
|
||||
* @param {String} id
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Store.prototype.client = function (id) {
|
||||
if (!this.clients[id]) {
|
||||
this.clients[id] = new (this.constructor.Client)(this, id);
|
||||
}
|
||||
|
||||
return this.clients[id];
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroys a client
|
||||
*
|
||||
* @api {String} sid
|
||||
* @param {Number} number of seconds to expire client data
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Store.prototype.destroyClient = function (id, expiration) {
|
||||
if (this.clients[id]) {
|
||||
this.clients[id].destroy(expiration);
|
||||
delete this.clients[id];
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroys the store
|
||||
*
|
||||
* @param {Number} number of seconds to expire client data
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Store.prototype.destroy = function (clientExpiration) {
|
||||
var keys = Object.keys(this.clients)
|
||||
, count = keys.length;
|
||||
|
||||
for (var i = 0, l = count; i < l; i++) {
|
||||
this.destroyClient(keys[i], clientExpiration);
|
||||
}
|
||||
|
||||
this.clients = {};
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Client.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Store.Client = function (store, id) {
|
||||
this.store = store;
|
||||
this.id = id;
|
||||
};
|
143
realtime/node_modules/socket.io/lib/stores/memory.js
generated
vendored
Normal file
143
realtime/node_modules/socket.io/lib/stores/memory.js
generated
vendored
Normal file
|
@ -0,0 +1,143 @@
|
|||
|
||||
/*!
|
||||
* socket.io-node
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var crypto = require('crypto')
|
||||
, Store = require('../store');
|
||||
|
||||
/**
|
||||
* Exports the constructor.
|
||||
*/
|
||||
|
||||
exports = module.exports = Memory;
|
||||
Memory.Client = Client;
|
||||
|
||||
/**
|
||||
* Memory store
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Memory (opts) {
|
||||
Store.call(this, opts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Inherits from Store.
|
||||
*/
|
||||
|
||||
Memory.prototype.__proto__ = Store.prototype;
|
||||
|
||||
/**
|
||||
* Publishes a message.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Memory.prototype.publish = function () { };
|
||||
|
||||
/**
|
||||
* Subscribes to a channel
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Memory.prototype.subscribe = function () { };
|
||||
|
||||
/**
|
||||
* Unsubscribes
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Memory.prototype.unsubscribe = function () { };
|
||||
|
||||
/**
|
||||
* Client constructor
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function Client () {
|
||||
Store.Client.apply(this, arguments);
|
||||
this.data = {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Inherits from Store.Client
|
||||
*/
|
||||
|
||||
Client.prototype.__proto__ = Store.Client;
|
||||
|
||||
/**
|
||||
* Gets a key
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Client.prototype.get = function (key, fn) {
|
||||
fn(null, this.data[key] === undefined ? null : this.data[key]);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets a key
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Client.prototype.set = function (key, value, fn) {
|
||||
this.data[key] = value;
|
||||
fn && fn(null);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Has a key
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Client.prototype.has = function (key, fn) {
|
||||
fn(null, key in this.data);
|
||||
};
|
||||
|
||||
/**
|
||||
* Deletes a key
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Client.prototype.del = function (key, fn) {
|
||||
delete this.data[key];
|
||||
fn && fn(null);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroys the client.
|
||||
*
|
||||
* @param {Number} number of seconds to expire data
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Client.prototype.destroy = function (expiration) {
|
||||
if ('number' != typeof expiration) {
|
||||
this.data = {};
|
||||
} else {
|
||||
var self = this;
|
||||
|
||||
setTimeout(function () {
|
||||
self.data = {};
|
||||
}, expiration * 1000);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
269
realtime/node_modules/socket.io/lib/stores/redis.js
generated
vendored
Normal file
269
realtime/node_modules/socket.io/lib/stores/redis.js
generated
vendored
Normal file
|
@ -0,0 +1,269 @@
|
|||
|
||||
/*!
|
||||
* socket.io-node
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var crypto = require('crypto')
|
||||
, Store = require('../store')
|
||||
, assert = require('assert');
|
||||
|
||||
/**
|
||||
* Exports the constructor.
|
||||
*/
|
||||
|
||||
exports = module.exports = Redis;
|
||||
Redis.Client = Client;
|
||||
|
||||
/**
|
||||
* Redis store.
|
||||
* Options:
|
||||
* - nodeId (fn) gets an id that uniquely identifies this node
|
||||
* - redis (fn) redis constructor, defaults to redis
|
||||
* - redisPub (object) options to pass to the pub redis client
|
||||
* - redisSub (object) options to pass to the sub redis client
|
||||
* - redisClient (object) options to pass to the general redis client
|
||||
* - pack (fn) custom packing, defaults to JSON or msgpack if installed
|
||||
* - unpack (fn) custom packing, defaults to JSON or msgpack if installed
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Redis (opts) {
|
||||
opts = opts || {};
|
||||
|
||||
// node id to uniquely identify this node
|
||||
var nodeId = opts.nodeId || function () {
|
||||
// by default, we generate a random id
|
||||
return Math.abs(Math.random() * Math.random() * Date.now() | 0);
|
||||
};
|
||||
|
||||
this.nodeId = nodeId();
|
||||
|
||||
// packing / unpacking mechanism
|
||||
if (opts.pack) {
|
||||
this.pack = opts.pack;
|
||||
this.unpack = opts.unpack;
|
||||
} else {
|
||||
try {
|
||||
var msgpack = require('msgpack');
|
||||
this.pack = msgpack.pack;
|
||||
this.unpack = msgpack.unpack;
|
||||
} catch (e) {
|
||||
this.pack = JSON.stringify;
|
||||
this.unpack = JSON.parse;
|
||||
}
|
||||
}
|
||||
|
||||
var redis = opts.redis || require('redis')
|
||||
, RedisClient = redis.RedisClient;
|
||||
|
||||
// initialize a pubsub client and a regular client
|
||||
if (opts.redisPub instanceof RedisClient) {
|
||||
this.pub = opts.redisPub;
|
||||
} else {
|
||||
opts.redisPub || (opts.redisPub = {});
|
||||
this.pub = redis.createClient(opts.redisPub.port, opts.redisPub.host, opts.redisPub);
|
||||
}
|
||||
if (opts.redisSub instanceof RedisClient) {
|
||||
this.sub = opts.redisSub;
|
||||
} else {
|
||||
opts.redisSub || (opts.redisSub = {});
|
||||
this.sub = redis.createClient(opts.redisSub.port, opts.redisSub.host, opts.redisSub);
|
||||
}
|
||||
if (opts.redisClient instanceof RedisClient) {
|
||||
this.cmd = opts.redisClient;
|
||||
} else {
|
||||
opts.redisClient || (opts.redisClient = {});
|
||||
this.cmd = redis.createClient(opts.redisClient.port, opts.redisClient.host, opts.redisClient);
|
||||
}
|
||||
|
||||
Store.call(this, opts);
|
||||
|
||||
this.sub.setMaxListeners(0);
|
||||
this.setMaxListeners(0);
|
||||
};
|
||||
|
||||
/**
|
||||
* Inherits from Store.
|
||||
*/
|
||||
|
||||
Redis.prototype.__proto__ = Store.prototype;
|
||||
|
||||
/**
|
||||
* Publishes a message.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Redis.prototype.publish = function (name) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
this.pub.publish(name, this.pack({ nodeId: this.nodeId, args: args }));
|
||||
this.emit.apply(this, ['publish', name].concat(args));
|
||||
};
|
||||
|
||||
/**
|
||||
* Subscribes to a channel
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Redis.prototype.subscribe = function (name, consumer, fn) {
|
||||
this.sub.subscribe(name);
|
||||
|
||||
if (consumer || fn) {
|
||||
var self = this;
|
||||
|
||||
self.sub.on('subscribe', function subscribe (ch) {
|
||||
if (name == ch) {
|
||||
function message (ch, msg) {
|
||||
if (name == ch) {
|
||||
msg = self.unpack(msg);
|
||||
|
||||
// we check that the message consumed wasnt emitted by this node
|
||||
if (self.nodeId != msg.nodeId) {
|
||||
consumer.apply(null, msg.args);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
self.sub.on('message', message);
|
||||
|
||||
self.on('unsubscribe', function unsubscribe (ch) {
|
||||
if (name == ch) {
|
||||
self.sub.removeListener('message', message);
|
||||
self.removeListener('unsubscribe', unsubscribe);
|
||||
}
|
||||
});
|
||||
|
||||
self.sub.removeListener('subscribe', subscribe);
|
||||
|
||||
fn && fn();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.emit('subscribe', name, consumer, fn);
|
||||
};
|
||||
|
||||
/**
|
||||
* Unsubscribes
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Redis.prototype.unsubscribe = function (name, fn) {
|
||||
this.sub.unsubscribe(name);
|
||||
|
||||
if (fn) {
|
||||
var client = this.sub;
|
||||
|
||||
client.on('unsubscribe', function unsubscribe (ch) {
|
||||
if (name == ch) {
|
||||
fn();
|
||||
client.removeListener('unsubscribe', unsubscribe);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.emit('unsubscribe', name, fn);
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroys the store
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Redis.prototype.destroy = function () {
|
||||
Store.prototype.destroy.call(this);
|
||||
|
||||
this.pub.end();
|
||||
this.sub.end();
|
||||
this.cmd.end();
|
||||
};
|
||||
|
||||
/**
|
||||
* Client constructor
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function Client (store, id) {
|
||||
Store.Client.call(this, store, id);
|
||||
};
|
||||
|
||||
/**
|
||||
* Inherits from Store.Client
|
||||
*/
|
||||
|
||||
Client.prototype.__proto__ = Store.Client;
|
||||
|
||||
/**
|
||||
* Redis hash get
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Client.prototype.get = function (key, fn) {
|
||||
this.store.cmd.hget(this.id, key, fn);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Redis hash set
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Client.prototype.set = function (key, value, fn) {
|
||||
this.store.cmd.hset(this.id, key, value, fn);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Redis hash del
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Client.prototype.del = function (key, fn) {
|
||||
this.store.cmd.hdel(this.id, key, fn);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Redis hash has
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Client.prototype.has = function (key, fn) {
|
||||
this.store.cmd.hexists(this.id, key, function (err, has) {
|
||||
if (err) return fn(err);
|
||||
fn(null, !!has);
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroys client
|
||||
*
|
||||
* @param {Number} number of seconds to expire data
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Client.prototype.destroy = function (expiration) {
|
||||
if ('number' != typeof expiration) {
|
||||
this.store.cmd.del(this.id);
|
||||
} else {
|
||||
this.store.cmd.expire(this.id, expiration);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
534
realtime/node_modules/socket.io/lib/transport.js
generated
vendored
Normal file
534
realtime/node_modules/socket.io/lib/transport.js
generated
vendored
Normal file
|
@ -0,0 +1,534 @@
|
|||
|
||||
/*!
|
||||
* socket.io-node
|
||||
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var parser = require('./parser');
|
||||
|
||||
/**
|
||||
* Expose the constructor.
|
||||
*/
|
||||
|
||||
exports = module.exports = Transport;
|
||||
|
||||
/**
|
||||
* Transport constructor.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function Transport (mng, data, req) {
|
||||
this.manager = mng;
|
||||
this.id = data.id;
|
||||
this.disconnected = false;
|
||||
this.drained = true;
|
||||
this.handleRequest(req);
|
||||
};
|
||||
|
||||
/**
|
||||
* Access the logger.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Transport.prototype.__defineGetter__('log', function () {
|
||||
return this.manager.log;
|
||||
});
|
||||
|
||||
/**
|
||||
* Access the store.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Transport.prototype.__defineGetter__('store', function () {
|
||||
return this.manager.store;
|
||||
});
|
||||
|
||||
/**
|
||||
* Handles a request when it's set.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.handleRequest = function (req) {
|
||||
this.log.debug('setting request', req.method, req.url);
|
||||
this.req = req;
|
||||
|
||||
if (req.method == 'GET') {
|
||||
this.socket = req.socket;
|
||||
this.open = true;
|
||||
this.drained = true;
|
||||
this.setHeartbeatInterval();
|
||||
|
||||
this.setHandlers();
|
||||
this.onSocketConnect();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when a connection is first set.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.onSocketConnect = function () { };
|
||||
|
||||
/**
|
||||
* Sets transport handlers
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.setHandlers = function () {
|
||||
var self = this;
|
||||
|
||||
// we need to do this in a pub/sub way since the client can POST the message
|
||||
// over a different socket (ie: different Transport instance)
|
||||
this.store.subscribe('heartbeat-clear:' + this.id, function () {
|
||||
self.onHeartbeatClear();
|
||||
});
|
||||
|
||||
this.store.subscribe('disconnect-force:' + this.id, function () {
|
||||
self.onForcedDisconnect();
|
||||
});
|
||||
|
||||
this.store.subscribe('dispatch:' + this.id, function (packet, volatile) {
|
||||
self.onDispatch(packet, volatile);
|
||||
});
|
||||
|
||||
this.bound = {
|
||||
end: this.onSocketEnd.bind(this)
|
||||
, close: this.onSocketClose.bind(this)
|
||||
, error: this.onSocketError.bind(this)
|
||||
, drain: this.onSocketDrain.bind(this)
|
||||
};
|
||||
|
||||
this.socket.on('end', this.bound.end);
|
||||
this.socket.on('close', this.bound.close);
|
||||
this.socket.on('error', this.bound.error);
|
||||
this.socket.on('drain', this.bound.drain);
|
||||
|
||||
this.handlersSet = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes transport handlers
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.clearHandlers = function () {
|
||||
if (this.handlersSet) {
|
||||
this.store.unsubscribe('disconnect-force:' + this.id);
|
||||
this.store.unsubscribe('heartbeat-clear:' + this.id);
|
||||
this.store.unsubscribe('dispatch:' + this.id);
|
||||
|
||||
this.socket.removeListener('end', this.bound.end);
|
||||
this.socket.removeListener('close', this.bound.close);
|
||||
this.socket.removeListener('error', this.bound.error);
|
||||
this.socket.removeListener('drain', this.bound.drain);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when the connection dies
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.onSocketEnd = function () {
|
||||
this.end('socket end');
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when the connection dies
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.onSocketClose = function (error) {
|
||||
this.end(error ? 'socket error' : 'socket close');
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when the connection has an error.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.onSocketError = function (err) {
|
||||
if (this.open) {
|
||||
this.socket.destroy();
|
||||
this.onClose();
|
||||
}
|
||||
|
||||
this.log.info('socket error ' + err.stack);
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when the connection is drained.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.onSocketDrain = function () {
|
||||
this.drained = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon receiving a heartbeat packet.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.onHeartbeatClear = function () {
|
||||
this.clearHeartbeatTimeout();
|
||||
this.setHeartbeatInterval();
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon a forced disconnection.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.onForcedDisconnect = function () {
|
||||
if (!this.disconnected) {
|
||||
this.log.info('transport end by forced client disconnection');
|
||||
if (this.open) {
|
||||
this.packet({ type: 'disconnect' });
|
||||
}
|
||||
this.end('booted');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Dispatches a packet.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.onDispatch = function (packet, volatile) {
|
||||
if (volatile) {
|
||||
this.writeVolatile(packet);
|
||||
} else {
|
||||
this.write(packet);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the close timeout.
|
||||
*/
|
||||
|
||||
Transport.prototype.setCloseTimeout = function () {
|
||||
if (!this.closeTimeout) {
|
||||
var self = this;
|
||||
|
||||
this.closeTimeout = setTimeout(function () {
|
||||
self.log.debug('fired close timeout for client', self.id);
|
||||
self.closeTimeout = null;
|
||||
self.end('close timeout');
|
||||
}, this.manager.get('close timeout') * 1000);
|
||||
|
||||
this.log.debug('set close timeout for client', this.id);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clears the close timeout.
|
||||
*/
|
||||
|
||||
Transport.prototype.clearCloseTimeout = function () {
|
||||
if (this.closeTimeout) {
|
||||
clearTimeout(this.closeTimeout);
|
||||
this.closeTimeout = null;
|
||||
|
||||
this.log.debug('cleared close timeout for client', this.id);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the heartbeat timeout
|
||||
*/
|
||||
|
||||
Transport.prototype.setHeartbeatTimeout = function () {
|
||||
if (!this.heartbeatTimeout && this.manager.enabled('heartbeats')) {
|
||||
var self = this;
|
||||
|
||||
this.heartbeatTimeout = setTimeout(function () {
|
||||
self.log.debug('fired heartbeat timeout for client', self.id);
|
||||
self.heartbeatTimeout = null;
|
||||
self.end('heartbeat timeout');
|
||||
}, this.manager.get('heartbeat timeout') * 1000);
|
||||
|
||||
this.log.debug('set heartbeat timeout for client', this.id);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clears the heartbeat timeout
|
||||
*
|
||||
* @param text
|
||||
*/
|
||||
|
||||
Transport.prototype.clearHeartbeatTimeout = function () {
|
||||
if (this.heartbeatTimeout && this.manager.enabled('heartbeats')) {
|
||||
clearTimeout(this.heartbeatTimeout);
|
||||
this.heartbeatTimeout = null;
|
||||
this.log.debug('cleared heartbeat timeout for client', this.id);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the heartbeat interval. To be called when a connection opens and when
|
||||
* a heartbeat is received.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.setHeartbeatInterval = function () {
|
||||
if (!this.heartbeatInterval && this.manager.enabled('heartbeats')) {
|
||||
var self = this;
|
||||
|
||||
this.heartbeatInterval = setTimeout(function () {
|
||||
self.heartbeat();
|
||||
self.heartbeatInterval = null;
|
||||
}, this.manager.get('heartbeat interval') * 1000);
|
||||
|
||||
this.log.debug('set heartbeat interval for client', this.id);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clears all timeouts.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.clearTimeouts = function () {
|
||||
this.clearCloseTimeout();
|
||||
this.clearHeartbeatTimeout();
|
||||
this.clearHeartbeatInterval();
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a heartbeat
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.heartbeat = function () {
|
||||
if (this.open) {
|
||||
this.log.debug('emitting heartbeat for client', this.id);
|
||||
this.packet({ type: 'heartbeat' });
|
||||
this.setHeartbeatTimeout();
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles a message.
|
||||
*
|
||||
* @param {Object} packet object
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.onMessage = function (packet) {
|
||||
var current = this.manager.transports[this.id];
|
||||
|
||||
if ('heartbeat' == packet.type) {
|
||||
this.log.debug('got heartbeat packet');
|
||||
|
||||
if (current && current.open) {
|
||||
current.onHeartbeatClear();
|
||||
} else {
|
||||
this.store.publish('heartbeat-clear:' + this.id);
|
||||
}
|
||||
} else {
|
||||
if ('disconnect' == packet.type && packet.endpoint == '') {
|
||||
this.log.debug('got disconnection packet');
|
||||
|
||||
if (current) {
|
||||
current.onForcedDisconnect();
|
||||
} else {
|
||||
this.store.publish('disconnect-force:' + this.id);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet.id && packet.ack != 'data') {
|
||||
this.log.debug('acknowledging packet automatically');
|
||||
|
||||
var ack = parser.encodePacket({
|
||||
type: 'ack'
|
||||
, ackId: packet.id
|
||||
, endpoint: packet.endpoint || ''
|
||||
});
|
||||
|
||||
if (current && current.open) {
|
||||
current.onDispatch(ack);
|
||||
} else {
|
||||
this.manager.onClientDispatch(this.id, ack);
|
||||
this.store.publish('dispatch:' + this.id, ack);
|
||||
}
|
||||
}
|
||||
|
||||
// handle packet locally or publish it
|
||||
if (current) {
|
||||
this.manager.onClientMessage(this.id, packet);
|
||||
} else {
|
||||
this.store.publish('message:' + this.id, packet);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clears the heartbeat interval
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.clearHeartbeatInterval = function () {
|
||||
if (this.heartbeatInterval && this.manager.enabled('heartbeats')) {
|
||||
clearTimeout(this.heartbeatInterval);
|
||||
this.heartbeatInterval = null;
|
||||
this.log.debug('cleared heartbeat interval for client', this.id);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Finishes the connection and makes sure client doesn't reopen
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.disconnect = function (reason) {
|
||||
this.packet({ type: 'disconnect' });
|
||||
this.end(reason);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Closes the connection.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.close = function () {
|
||||
if (this.open) {
|
||||
this.doClose();
|
||||
this.onClose();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Called upon a connection close.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.onClose = function () {
|
||||
if (this.open) {
|
||||
this.setCloseTimeout();
|
||||
this.clearHandlers();
|
||||
this.open = false;
|
||||
this.manager.onClose(this.id);
|
||||
this.store.publish('close', this.id);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Cleans up the connection, considers the client disconnected.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.end = function (reason) {
|
||||
if (!this.disconnected) {
|
||||
this.log.info('transport end (' + reason + ')');
|
||||
|
||||
var local = this.manager.transports[this.id];
|
||||
|
||||
this.close();
|
||||
this.clearTimeouts();
|
||||
this.disconnected = true;
|
||||
|
||||
if (local) {
|
||||
this.manager.onClientDisconnect(this.id, reason, true);
|
||||
} else {
|
||||
this.store.publish('disconnect:' + this.id, reason);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Signals that the transport should pause and buffer data.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Transport.prototype.discard = function () {
|
||||
this.log.debug('discarding transport');
|
||||
this.discarded = true;
|
||||
this.clearTimeouts();
|
||||
this.clearHandlers();
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes an error packet with the specified reason and advice.
|
||||
*
|
||||
* @param {Number} advice
|
||||
* @param {Number} reason
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Transport.prototype.error = function (reason, advice) {
|
||||
this.packet({
|
||||
type: 'error'
|
||||
, reason: reason
|
||||
, advice: advice
|
||||
});
|
||||
|
||||
this.log.warn(reason, advice ? ('client should ' + advice) : '');
|
||||
this.end('error');
|
||||
};
|
||||
|
||||
/**
|
||||
* Write a packet.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Transport.prototype.packet = function (obj) {
|
||||
return this.write(parser.encodePacket(obj));
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes a volatile message.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Transport.prototype.writeVolatile = function (msg) {
|
||||
if (this.open) {
|
||||
if (this.drained) {
|
||||
this.write(msg);
|
||||
} else {
|
||||
this.log.debug('ignoring volatile packet, buffer not drained');
|
||||
}
|
||||
} else {
|
||||
this.log.debug('ignoring volatile packet, transport not open');
|
||||
}
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue