sinatra-websocketio 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/README.md +4 -1
- data/lib/js/event_emitter.js +9 -6
- data/lib/js/websocketio.js +10 -4
- data/lib/sinatra-websocketio/version.rb +1 -1
- data/sample/Gemfile.lock +1 -1
- data/sinatra-websocketio.gemspec +1 -1
- metadata +6 -6
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -66,7 +66,9 @@ io.on("light", function(data){
|
|
66
66
|
Client Side
|
67
67
|
|
68
68
|
```javascript
|
69
|
-
io.
|
69
|
+
io.on("connect", function{
|
70
|
+
io.push("chat", {name: "shokai", message: "hello"}); // client -> server
|
71
|
+
});
|
70
72
|
```
|
71
73
|
|
72
74
|
Server Side
|
@@ -97,6 +99,7 @@ Server Side
|
|
97
99
|
```ruby
|
98
100
|
io.on :connect do |session|
|
99
101
|
puts "new client <#{session}>"
|
102
|
+
io.push :hello, "hello!!"
|
100
103
|
end
|
101
104
|
|
102
105
|
io.on :disconnect do |session|
|
data/lib/js/event_emitter.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
// event_emitter.js v0.0.
|
1
|
+
// event_emitter.js v0.0.8
|
2
2
|
// https://github.com/shokai/event_emitter.js
|
3
3
|
// (c) 2013 Sho Hashimoto <hashimoto@shokai.org>
|
4
4
|
// The MIT License
|
@@ -38,13 +38,15 @@ var EventEmitter = function(){
|
|
38
38
|
switch(e.type){
|
39
39
|
case type:
|
40
40
|
e.listener(data);
|
41
|
+
if(e.once) e.type = null;
|
41
42
|
break
|
42
|
-
case
|
43
|
+
case "*":
|
43
44
|
e.listener(type, data);
|
45
|
+
if(e.once) e.type = null;
|
44
46
|
break
|
45
47
|
}
|
46
|
-
if(e.once) self.removeListener(e.id);
|
47
48
|
}
|
49
|
+
self.removeListener();
|
48
50
|
};
|
49
51
|
|
50
52
|
this.removeListener = function(id_or_type){
|
@@ -52,10 +54,11 @@ var EventEmitter = function(){
|
|
52
54
|
var e = self.__events[i];
|
53
55
|
switch(typeof id_or_type){
|
54
56
|
case "number":
|
55
|
-
if(e.id
|
57
|
+
if(e.id === id_or_type) self.__events.splice(i,1);
|
56
58
|
break
|
57
59
|
case "string":
|
58
|
-
|
60
|
+
case "object":
|
61
|
+
if(e.type === id_or_type) self.__events.splice(i,1);
|
59
62
|
break
|
60
63
|
}
|
61
64
|
}
|
@@ -63,6 +66,6 @@ var EventEmitter = function(){
|
|
63
66
|
|
64
67
|
};
|
65
68
|
|
66
|
-
if(typeof module !==
|
69
|
+
if(typeof module !== "undefined" && typeof module.exports !== "undefined"){
|
67
70
|
module.exports = EventEmitter;
|
68
71
|
}
|
data/lib/js/websocketio.js
CHANGED
@@ -15,7 +15,7 @@ var WebSocketIO = function(){
|
|
15
15
|
|
16
16
|
this.connect = function(){
|
17
17
|
if(typeof WebSocket === 'undefined'){
|
18
|
-
self.emit("error", "websocket not exists");
|
18
|
+
self.emit("error", "websocket not exists in this browser");
|
19
19
|
return null;
|
20
20
|
}
|
21
21
|
self.running = true;
|
@@ -27,12 +27,14 @@ var WebSocketIO = function(){
|
|
27
27
|
self.emit(data_.type, data_.data);
|
28
28
|
}
|
29
29
|
catch(e){
|
30
|
-
self.emit("error", "WebSocketIO
|
30
|
+
self.emit("error", "WebSocketIO data parse error");
|
31
31
|
}
|
32
32
|
};
|
33
33
|
self.websocket.onclose = function(){
|
34
|
-
if(self.connecting)
|
35
|
-
|
34
|
+
if(self.connecting){
|
35
|
+
self.connecting = false;
|
36
|
+
self.emit("disconnect");
|
37
|
+
}
|
36
38
|
if(self.running){
|
37
39
|
reconnect_timer_id = setTimeout(self.connect, 10000);
|
38
40
|
}
|
@@ -50,6 +52,10 @@ var WebSocketIO = function(){
|
|
50
52
|
};
|
51
53
|
|
52
54
|
this.push = function(type, data){
|
55
|
+
if(!self.connecting){
|
56
|
+
self.emit("error", "websocket not connected");
|
57
|
+
return;
|
58
|
+
}
|
53
59
|
self.websocket.send(JSON.stringify({type: type, data: data, session: self.session}));
|
54
60
|
};
|
55
61
|
};
|
data/sample/Gemfile.lock
CHANGED
data/sinatra-websocketio.gemspec
CHANGED
@@ -21,5 +21,5 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_dependency 'em-websocket', '>= 0.5.0'
|
22
22
|
gem.add_dependency 'eventmachine', '>= 1.0.0'
|
23
23
|
gem.add_dependency 'json', '>= 1.7.0'
|
24
|
-
gem.add_dependency 'event_emitter', '
|
24
|
+
gem.add_dependency 'event_emitter', '>= 0.2.4'
|
25
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-websocketio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra-contrib
|
@@ -112,17 +112,17 @@ dependencies:
|
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ! '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 0.2.4
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
122
122
|
requirements:
|
123
|
-
- -
|
123
|
+
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
125
|
+
version: 0.2.4
|
126
126
|
description: WebSocket component for Sinatra RocketIO
|
127
127
|
email:
|
128
128
|
- hashimoto@shokai.org
|