Class: WebRTC::DataChannelObserver

Inherits:
Object
  • Object
show all
Defined in:
lib/webrtc/observers.rb

Instance Method Summary collapse

Constructor Details

#initialize(on_open: nil, on_close: nil, on_message: nil, on_error: nil) ⇒ DataChannelObserver

Returns a new instance of DataChannelObserver.



26
27
28
29
30
31
# File 'lib/webrtc/observers.rb', line 26

def initialize(on_open: nil, on_close: nil, on_message: nil, on_error: nil)
  @on_open = on_open
  @on_close = on_close
  @on_message = on_message
  @on_error = on_error
end

Instance Method Details

#bind(channel) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/webrtc/observers.rb', line 33

def bind(channel)
  channel.on_open { @on_open&.call }
  channel.on_close { @on_close&.call }
  channel.on_message { |message| @on_message&.call(message) }
  channel.on_error { |error| @on_error&.call(error) }
  channel
end