Class: SignalingChannel

Inherits:
Turbo::StreamsChannel
  • Object
show all
Defined in:
app/channels/signaling_channel.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sync(data, to:) ⇒ Object



26
27
28
# File 'app/channels/signaling_channel.rb', line 26

def self.sync(data, to:)
    ActionCable.server.broadcast stream_name_from(to), data
end

Instance Method Details

#receive(data) ⇒ Object



12
13
14
15
16
17
18
# File 'app/channels/signaling_channel.rb', line 12

def receive(data)
    puts "Signaling Server peer #{@peer_id} receive #{data} #{params}"
    send_back_msg = P2pStreamsChannel.resolve(data)
    if send_back_msg.present?
        SignalingChannel.sync send_back_msg, to: P2pStreamsChannel.fetch_session(data["session_id"])
    end
end

#subscribedObject



4
5
6
7
8
9
10
# File 'app/channels/signaling_channel.rb', line 4

def subscribed
    super
    
    # TODO: user_id, session_id, is_host
    @session_id = params["session_id"]
    @peer_id = params["peer_id"]
end

#unsubscribedObject



20
21
22
23
24
# File 'app/channels/signaling_channel.rb', line 20

def unsubscribed
    super

    P2pStreamsChannel.disconnect_if_host_peer(@session_id, @peer_id)
end