sinatra_sockets 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/server_skeleton/README.md +13 -0
- data/lib/server_skeleton/client.rb +30 -0
- data/lib/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85832d4bf9cf5f368b6e6a837e75acfe647c6829
|
4
|
+
data.tar.gz: 289bf9344a3e70b8fcaf585570be04df8c8235c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b44d3168ac29c9c4deed9f404b736abc5cadb4a5086a6eb9ff43071161276a765cef761364c954405da49584b05d62694551f2297ab168f154899868c00a76e1
|
7
|
+
data.tar.gz: b35d412caf5189d3dde2afb682e8947b8ec3cca4c23510d6c3be90e7213579d5a7d689fd5cc9a6ed0006fa6854c7a076b62250107b1025e2fa69e06d7953e5f9
|
@@ -0,0 +1,13 @@
|
|
1
|
+
A simple sinatra websocket server with faye/eventmaching
|
2
|
+
|
3
|
+
to start: `thin start`
|
4
|
+
|
5
|
+
to use command line client, open a new terminal and run `ruby client.rb`.
|
6
|
+
|
7
|
+
To understand what's going on, look at the source code,
|
8
|
+
and raise an issue on [the github page](http://github.com/maxpleaner/sinatra_sockets)
|
9
|
+
if there's any confusion.
|
10
|
+
|
11
|
+
**required ruby version** `2.3`
|
12
|
+
|
13
|
+
**platform** tested only on MRI and unix
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'faye/websocket'
|
2
|
+
require 'eventmachine'
|
3
|
+
require 'byebug'
|
4
|
+
require 'gemmy'
|
5
|
+
|
6
|
+
Settings = {awaiting_input: false }
|
7
|
+
EM.run do
|
8
|
+
|
9
|
+
EM.tick_loop do
|
10
|
+
if !Settings[:awaiting_input]
|
11
|
+
Thread.new do
|
12
|
+
Settings[:awaiting_input] = true
|
13
|
+
inp = gets.chomp
|
14
|
+
Settings[:awaiting_input] = false
|
15
|
+
Ws.send inp
|
16
|
+
end
|
17
|
+
sleep 0.2
|
18
|
+
end
|
19
|
+
end.on_stop { EM.stop }
|
20
|
+
|
21
|
+
ServerWebsocketUrl = ENV["SERVER_WS_URL"] || 'ws://localhost:3000/'
|
22
|
+
|
23
|
+
Ws = Faye::WebSocket::Client.new ServerWebsocketUrl
|
24
|
+
|
25
|
+
Ws.on :message do |event|
|
26
|
+
puts event.data
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra_sockets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- maxpleaner
|
@@ -33,6 +33,8 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- bin/sinatra_sockets
|
35
35
|
- lib/server_skeleton/Gemfile
|
36
|
+
- lib/server_skeleton/README.md
|
37
|
+
- lib/server_skeleton/client.rb
|
36
38
|
- lib/server_skeleton/config.ru
|
37
39
|
- lib/server_skeleton/lib/routes.rb
|
38
40
|
- lib/server_skeleton/lib/routes/index.rb
|