Sha256: 54f28d29e49a060201a86eecef13ab7378add555aef6fd04ffb60df433adf18e

Contents?: true

Size: 813 Bytes

Versions: 2

Compression:

Stored size: 813 Bytes

Contents

module P2pStreamsChannel
    module_function

    CONNECTION_MESSAGE_TYPE = "Connection".freeze

    def resolve(message)
        case message["type"]
        when CONNECTION_MESSAGE_TYPE
            handle_session(message)
        else
        end
    end

    def handle_session(data)
        case data["state"]
        when P2pStreamsChannel::STATE_SESSION_JOIN
            if session = P2pStreamsChannel.fetch_session(data["session_id"])
                session.join_peer(data["peer_id"])
            end
        else
            data
        end
    end

    def disconnect_if_host_peer(session_id, peer_id)
        if session = P2pStreamsChannel.fetch_session(session_id)
            if session.is_host_peer?(peer_id)
                session.disconnect_peer(peer_id)
            end
        end
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
p2p_streams_channel-0.0.3 lib/p2p_streams_channel/session_handler.rb
p2p_streams_channel-0.0.2 lib/p2p_streams_channel/session_handler.rb