websocket-gui 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/websocket-gui.rb +0 -1
- data/lib/websocket-gui/base.rb +15 -15
- data/lib/websocket-gui/version.rb +1 -1
- data/spec/base_spec.rb +3 -3
- data/websocket-gui.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9002a935110186c94b8c3a51e2e70396f445af4f
|
|
4
|
+
data.tar.gz: 40428bc42041557c35b511733dba4e35312ef022
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d4e65a9522527651c1e73a630f49433e07931ed93e4f0f7d7bdb1fc516fc82dd009ec5f3cb7b6bb2b64c249c123b54279d5c8a2ae98c7c7aeeecf60d77617ab1
|
|
7
|
+
data.tar.gz: 99cf03e0e5351f26bda15455e7f543f6389bccb815c6d95ad0d845fe2259b581895594ae790d3ea8623251ac3942d6c759369b4d0bfdb2362fae6d66c03e727b
|
data/lib/websocket-gui.rb
CHANGED
data/lib/websocket-gui/base.rb
CHANGED
|
@@ -4,7 +4,7 @@ module WebsocketGui
|
|
|
4
4
|
|
|
5
5
|
# class-level config, so you can wire your settings into your class
|
|
6
6
|
# These can also be provided when calling run!
|
|
7
|
-
@@
|
|
7
|
+
@@websocket_config = {
|
|
8
8
|
socket_port: 8080,
|
|
9
9
|
socket_host: '127.0.0.1',
|
|
10
10
|
http_port: 3000,
|
|
@@ -14,30 +14,30 @@ module WebsocketGui
|
|
|
14
14
|
}
|
|
15
15
|
def self.method_missing(method, *args, &block)
|
|
16
16
|
if block_given?
|
|
17
|
-
@@
|
|
17
|
+
@@websocket_config[method] = block
|
|
18
18
|
else
|
|
19
|
-
@@
|
|
19
|
+
@@websocket_config[method] = args.first
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
attr_reader :
|
|
23
|
+
attr_reader :websocket_config
|
|
24
24
|
|
|
25
25
|
def initialize(config = {})
|
|
26
|
-
@
|
|
26
|
+
@websocket_config = @@websocket_config.merge(config)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# start the socket server and the web server, and launch a browser to fetch the view from the web server
|
|
30
30
|
def run!(runtime_config = {})
|
|
31
|
-
@
|
|
31
|
+
@websocket_config.merge! runtime_config
|
|
32
32
|
|
|
33
33
|
EM.run do
|
|
34
|
-
if @
|
|
35
|
-
EM.add_periodic_timer(@
|
|
34
|
+
if @websocket_config[:tick_interval]
|
|
35
|
+
EM.add_periodic_timer(@websocket_config[:tick_interval]) do
|
|
36
36
|
socket_trigger(:on_tick, @socket_connected)
|
|
37
37
|
end
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
EventMachine::WebSocket.run(host: @
|
|
40
|
+
EventMachine::WebSocket.run(host: @websocket_config[:socket_host], port: @websocket_config[:socket_port]) do |socket|
|
|
41
41
|
@socket_active = socket
|
|
42
42
|
socket.onopen do |handshake|
|
|
43
43
|
@socket_connected = true
|
|
@@ -54,11 +54,11 @@ module WebsocketGui
|
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
Launchy.open("http://#{@
|
|
58
|
-
WebsocketGui::SinatraWrapper.view_path = @
|
|
57
|
+
Launchy.open("http://#{@websocket_config[:http_host]}:#{@websocket_config[:http_port]}/")
|
|
58
|
+
WebsocketGui::SinatraWrapper.view_path = @websocket_config[:view]
|
|
59
59
|
WebsocketGui::SinatraWrapper.run!(
|
|
60
|
-
port: @
|
|
61
|
-
bind: @
|
|
60
|
+
port: @websocket_config[:http_port],
|
|
61
|
+
bind: @websocket_config[:http_host])
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
@@ -73,11 +73,11 @@ module WebsocketGui
|
|
|
73
73
|
private
|
|
74
74
|
|
|
75
75
|
def handler_exists?(method)
|
|
76
|
-
@
|
|
76
|
+
@websocket_config[method].kind_of? Proc
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
def socket_trigger(method, *args)
|
|
80
|
-
self.instance_exec(*args, &@
|
|
80
|
+
self.instance_exec(*args, &@websocket_config[method]) if handler_exists? method
|
|
81
81
|
end
|
|
82
82
|
|
|
83
83
|
def process_message(msg)
|
data/spec/base_spec.rb
CHANGED
|
@@ -6,13 +6,13 @@ describe ExampleWebSocketApp do
|
|
|
6
6
|
it { should respond_to(:run!) }
|
|
7
7
|
it { should respond_to(:socket_send) }
|
|
8
8
|
it { should respond_to(:socket_close) }
|
|
9
|
-
its(:
|
|
9
|
+
its(:websocket_config) { should be_an_instance_of(Hash) }
|
|
10
10
|
|
|
11
11
|
context "override Base defaults" do
|
|
12
12
|
let(:example) {
|
|
13
13
|
ExampleWebSocketApp.new(http_port: 80, http_host: "localhost")
|
|
14
14
|
}
|
|
15
|
-
let(:config) { example.
|
|
15
|
+
let(:config) { example.websocket_config }
|
|
16
16
|
|
|
17
17
|
it "has defaults inherited from Base" do
|
|
18
18
|
config[:socket_port].should equal(8080)
|
|
@@ -34,7 +34,7 @@ describe ExampleWebSocketApp do
|
|
|
34
34
|
let(:example) {
|
|
35
35
|
ExampleWebSocketApp.new(tick_interval: 1)
|
|
36
36
|
}
|
|
37
|
-
let(:config) { example.
|
|
37
|
+
let(:config) { example.websocket_config }
|
|
38
38
|
|
|
39
39
|
it "overrides already overridden defaults in constructor" do
|
|
40
40
|
config[:tick_interval].should equal(1)
|
data/websocket-gui.gemspec
CHANGED
|
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
|
27
27
|
spec.add_development_dependency "rspec"
|
|
28
28
|
spec.add_runtime_dependency 'em-websocket', '~> 0.5.0'
|
|
29
29
|
spec.add_runtime_dependency 'sinatra', '~> 1.4.3'
|
|
30
|
-
spec.add_runtime_dependency 'thin', '
|
|
30
|
+
spec.add_runtime_dependency 'thin', '~> 1.5.1'
|
|
31
31
|
spec.add_runtime_dependency 'launchy', '~> 2.3.0'
|
|
32
32
|
spec.add_runtime_dependency 'json', '>= 1.7.7'
|
|
33
33
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: websocket-gui
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jason Pollentier
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-10-
|
|
11
|
+
date: 2013-10-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -84,14 +84,14 @@ dependencies:
|
|
|
84
84
|
name: thin
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
|
-
- -
|
|
87
|
+
- - ~>
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
89
|
version: 1.5.1
|
|
90
90
|
type: :runtime
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
|
-
- -
|
|
94
|
+
- - ~>
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: 1.5.1
|
|
97
97
|
- !ruby/object:Gem::Dependency
|