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 CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.1.7 2013-03-21
2
+
3
+ * emit "error" on push before websocket connect
4
+
1
5
  === 0.1.6 2013-03-20
2
6
 
3
7
  * bugfix gem dependencies
data/README.md CHANGED
@@ -66,7 +66,9 @@ io.on("light", function(data){
66
66
  Client Side
67
67
 
68
68
  ```javascript
69
- io.push("chat", {name: "shokai", message: "hello"}); // client -> server
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|
@@ -1,4 +1,4 @@
1
- // event_emitter.js v0.0.7
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 == id_or_type) self.__events.splice(i,1);
57
+ if(e.id === id_or_type) self.__events.splice(i,1);
56
58
  break
57
59
  case "string":
58
- if(e.type == id_or_type) self.__events.splice(i,1);
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 !== 'undefined' && typeof module.exports !== 'undefined'){
69
+ if(typeof module !== "undefined" && typeof module.exports !== "undefined"){
67
70
  module.exports = EventEmitter;
68
71
  }
@@ -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 get error");
30
+ self.emit("error", "WebSocketIO data parse error");
31
31
  }
32
32
  };
33
33
  self.websocket.onclose = function(){
34
- if(self.connecting) self.emit("disconnect");
35
- self.connecting = false;
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
  };
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module WebSocketIO
3
- VERSION = "0.1.6"
3
+ VERSION = "0.1.7"
4
4
  end
5
5
  end
data/sample/Gemfile.lock CHANGED
@@ -10,7 +10,7 @@ GEM
10
10
  em-websocket-client (0.1.1)
11
11
  eventmachine
12
12
  libwebsocket
13
- event_emitter (0.2.3)
13
+ event_emitter (0.2.4)
14
14
  eventmachine (1.0.3)
15
15
  foreman (0.62.0)
16
16
  thor (>= 0.13.6)
@@ -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', '~> 0.2'
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.6
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-19 00:00:00.000000000 Z
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: '0.2'
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: '0.2'
125
+ version: 0.2.4
126
126
  description: WebSocket component for Sinatra RocketIO
127
127
  email:
128
128
  - hashimoto@shokai.org