Class: JanusGateway::Resource::Session
- Inherits:
-
JanusGateway::Resource
- Object
- JanusGateway::Resource
- JanusGateway::Resource::Session
- Defined in:
- lib/janus_gateway/resource/session.rb
Instance Attribute Summary
Attributes inherited from JanusGateway::Resource
Instance Method Summary collapse
- #create ⇒ Concurrent::Promise
- #destroy ⇒ Concurrent::Promise
- #heartbeat ⇒ Thread
-
#initialize(client) ⇒ Session
constructor
A new instance of Session.
Constructor Details
#initialize(client) ⇒ Session
Returns a new instance of Session.
4 5 6 7 8 |
# File 'lib/janus_gateway/resource/session.rb', line 4 def initialize(client) @heartbeat_thread = nil super end |
Instance Method Details
#create ⇒ Concurrent::Promise
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/janus_gateway/resource/session.rb', line 11 def create promise = Concurrent::Promise.new client.send_transaction( janus: 'create' ).then do |*args| _on_created(*args) heartbeat promise.set(self).execute end.rescue do |error| promise.fail(error).execute end promise end |
#destroy ⇒ Concurrent::Promise
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/janus_gateway/resource/session.rb', line 29 def destroy promise = Concurrent::Promise.new client.send_transaction( janus: 'destroy', session_id: id ).then do |*_args| _on_destroyed promise.set(self).execute end.rescue do |error| promise.fail(error).execute end promise end |
#heartbeat ⇒ Thread
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/janus_gateway/resource/session.rb', line 47 def heartbeat @heartbeat_thread.exit unless @heartbeat_thread.nil? @heartbeat_thread = Thread.new do sleep_time = 5 loop do sleep(sleep_time) client.send_transaction( janus: 'keepalive', session_id: id ).then do |*_args| sleep_time = 30 end.rescue do |_error| sleep_time = 1 end end end end |