sinatra-cometio 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/README.rdoc +13 -2
- data/lib/js/cometio.js +23 -4
- data/lib/sinatra/cometio.rb +1 -1
- data/lib/sinatra-cometio.rb +1 -1
- metadata +2 -2
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -74,16 +74,27 @@ Client Side
|
|
74
74
|
|
75
75
|
Server Side
|
76
76
|
|
77
|
-
|
77
|
+
event_id = CometIO.on :chat do |data, from|
|
78
78
|
puts "#{data} - from#{from}"
|
79
79
|
end
|
80
|
-
CometIO.removeListener
|
80
|
+
CometIO.removeListener event_id
|
81
81
|
|
82
82
|
or
|
83
83
|
|
84
84
|
CometIO.removeListener :chat # remove all chat listener
|
85
85
|
|
86
86
|
|
87
|
+
Client Side
|
88
|
+
|
89
|
+
var event_id = io.on("error", function(err){
|
90
|
+
console.error("CometIO error : "err);
|
91
|
+
});
|
92
|
+
io.removeListener(event_id);
|
93
|
+
|
94
|
+
or
|
95
|
+
|
96
|
+
io.removeListener("error"); // remove all error listener
|
97
|
+
|
87
98
|
== Sample App
|
88
99
|
|
89
100
|
chat app
|
data/lib/js/cometio.js
CHANGED
@@ -23,7 +23,7 @@ var CometIO = function(){
|
|
23
23
|
};
|
24
24
|
|
25
25
|
this.connect = function(){
|
26
|
-
self.on("
|
26
|
+
self.on("__session_id", function(session){
|
27
27
|
self.session = session;
|
28
28
|
self.emit("connect", self.session);
|
29
29
|
});
|
@@ -57,9 +57,14 @@ var CometIO = function(){
|
|
57
57
|
|
58
58
|
this.events = new Array();
|
59
59
|
this.on = function(type, listener){
|
60
|
-
if(typeof listener
|
61
|
-
|
62
|
-
|
60
|
+
if(typeof listener !== "function") return;
|
61
|
+
var event_id = self.events.length > 0 ? 1 + self.events[self.events.length-1].id : 0
|
62
|
+
self.events.push({
|
63
|
+
id: event_id,
|
64
|
+
type: type,
|
65
|
+
listener: listener
|
66
|
+
});
|
67
|
+
return event_id;
|
63
68
|
};
|
64
69
|
|
65
70
|
this.emit = function(type, data){
|
@@ -69,4 +74,18 @@ var CometIO = function(){
|
|
69
74
|
}
|
70
75
|
};
|
71
76
|
|
77
|
+
this.removeListener = function(id_or_type){
|
78
|
+
for(var i = self.events.length-1; i >= 0; i--){
|
79
|
+
var e = self.events[i];
|
80
|
+
switch(typeof id_or_type){
|
81
|
+
case "number":
|
82
|
+
if(e.id == id_or_type) self.events.splice(i,1);
|
83
|
+
break
|
84
|
+
case "string":
|
85
|
+
if(e.type == id_or_type) self.events.splice(i,1);
|
86
|
+
break
|
87
|
+
}
|
88
|
+
}
|
89
|
+
};
|
90
|
+
|
72
91
|
};
|
data/lib/sinatra/cometio.rb
CHANGED
data/lib/sinatra-cometio.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-cometio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -194,7 +194,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
194
194
|
version: '0'
|
195
195
|
segments:
|
196
196
|
- 0
|
197
|
-
hash:
|
197
|
+
hash: 3731248774010908495
|
198
198
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
199
|
none: false
|
200
200
|
requirements:
|