README.md in sinatra-websocketio-0.0.6 vs README.md in sinatra-websocketio-0.1.0
- old
+ new
@@ -35,12 +35,14 @@
set :websocketio, :port => 8080
run Sinatra::Application
```
```ruby
-WebSocketIO.push :temperature, 35 # to all clients
-WebSocketIO.push :light, {:value => 150}, {:to => session_id} # to specific client
+io = Sinatra::WebSocketIO
+
+io.push :temperature, 35 # to all clients
+io.push :light, {:value => 150}, {:to => session_id} # to specific client
```
Client Side
```html
@@ -67,11 +69,11 @@
```
Server Side
```ruby
-WebSocketIO.on :chat do |data, session|
+io.on :chat do |data, session|
puts "#{data['name']} : #{data['message']} <#{session}>"
end
## => "shokai : hello <12abcde345f6g7h8ijk>"
```
@@ -90,15 +92,15 @@
```
Server Side
```ruby
-WebSocketIO.on :connect do |session|
+io.on :connect do |session|
puts "new client <#{session}>"
end
-WebSocketIO.on :disconnect do |session|
+io.on :disconnect do |session|
puts "client disconnected <#{session}>"
end
```
### On "error" Event
@@ -111,29 +113,29 @@
});
```
Server Side
```ruby
-WebSocketIO.on :error do |e|
+io.on :error do |e|
STDERR.puts e
end
```
### Remove Event Listener
Server Side
```ruby
-event_id = WebSocketIO.on :chat do |data, from|
+event_id = io.on :chat do |data, from|
puts "#{data} - from#{from}"
end
-WebSocketIO.removeListener event_id
+io.removeListener event_id
```
or
```ruby
-WebSocketIO.removeListener :chat # remove all "chat" listener
+io.removeListener :chat # remove all "chat" listener
```
Client Side