domotics-core 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/domotics/core/element/dimmer.rb +4 -0
- data/lib/domotics/core/element/rgb_strip.rb +5 -3
- data/lib/domotics/core/helper/helper.rb +1 -1
- data/lib/domotics/core/room.rb +1 -0
- data/lib/domotics/core/server.rb +7 -1
- data/lib/domotics/core/version.rb +1 -1
- data/lib/domotics/core/ws_server.rb +16 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d31d71816c9455bade9c824b113015a28910e2d6
|
4
|
+
data.tar.gz: 05587d42ffd80c7c24a82397293e9f47a9971715
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79d8973f4ea95522a1398e06532642858a7379abf44181a7819aae2988b4b8ed9feb0ca3af9336fb8470d59b545722dde781008bffbc0a85fa2e11929b96a153
|
7
|
+
data.tar.gz: e210292eb529442ab3d7de20dc706e2fd320207064c0b25fdcbdb951b0cf1542e42599519989f22c01c0a833d46993c668823a00b41472fdbc66f5796205d180
|
data/lib/domotics/core/room.rb
CHANGED
@@ -58,6 +58,7 @@ module Domotics::Core
|
|
58
58
|
def event_handler(msg = {})
|
59
59
|
event, element = msg[:event], msg[:element]
|
60
60
|
@logger.info { "Event message :#{event} from #{element} with state [#{element.state}]" }
|
61
|
+
Domotics::Core::WsServer.publish "#{element.room.name}/#{element.name}"
|
61
62
|
end
|
62
63
|
|
63
64
|
def destroy
|
data/lib/domotics/core/server.rb
CHANGED
@@ -2,6 +2,8 @@ module Domotics::Core
|
|
2
2
|
class Server
|
3
3
|
def initialize(args = {})
|
4
4
|
@logger = Domotics::Core::Setup.logger || Logger.new(STDERR)
|
5
|
+
@args = {}
|
6
|
+
@args[:Host], @args[:Port] = args[:host], args[:port]
|
5
7
|
end
|
6
8
|
def call(env)
|
7
9
|
# [object]/[action]/[params]
|
@@ -22,7 +24,7 @@ module Domotics::Core
|
|
22
24
|
result = object.public_send(action, *request.map { |param| param.to_isym })
|
23
25
|
rescue Exception => e
|
24
26
|
@logger.error { e.message }
|
25
|
-
@logger.debug { e }
|
27
|
+
@logger.debug { e.backtrace.join $/ }
|
26
28
|
return invalid 'request'
|
27
29
|
end
|
28
30
|
case form
|
@@ -36,6 +38,10 @@ module Domotics::Core
|
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
41
|
+
def run
|
42
|
+
Rack::Handler::Thin.run Rack::Builder.new{ run Domotics::Core::Server.new }, @args
|
43
|
+
end
|
44
|
+
|
39
45
|
private
|
40
46
|
|
41
47
|
def invalid(param)
|
@@ -1,21 +1,28 @@
|
|
1
1
|
module Domotics::Core
|
2
2
|
class WsServer
|
3
|
+
@@channel = EM::Channel.new
|
3
4
|
def initialize(args = {})
|
5
|
+
@logger = Domotics::Core::Setup.logger || Logger.new(STDERR)
|
4
6
|
@args = args
|
5
|
-
@channel = EM::Channel.new
|
6
7
|
end
|
7
8
|
def run
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
ws.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
Thread.new do
|
10
|
+
@logger.info { "Starting WebSocet Server on #{@args[:host]}:#{@args[:port]}" }
|
11
|
+
EventMachine::WebSocket.start(@args) do |ws|
|
12
|
+
ws.onopen do
|
13
|
+
sid = @@channel.subscribe { |msg| ws.send msg }
|
14
|
+
ws.onmessage do |msg|
|
15
|
+
@logger.info { "WebSocket message [#{msg}] from client [#{sid}]" }
|
16
|
+
end
|
17
|
+
ws.onclose do
|
18
|
+
@@channel.unsubscribe(sid)
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
24
|
+
def self.publish(msg)
|
25
|
+
@@channel.push msg
|
26
|
+
end
|
20
27
|
end
|
21
28
|
end
|