Sha256: effb06e3467fd11f091336a7de19c53a2e6f90043520f8bb248053c24cbe8833

Contents?: true

Size: 1.2 KB

Versions: 16

Compression:

Stored size: 1.2 KB

Contents

module Startback
  module Websocket
    module Hub
      class Room < App

        def initialize(name)
          @name = name
          @participants = []
        end
        attr_reader :name, :participants

        def add(participant)
          raise "Participant instance expected" unless participant.is_a? Participant
          @participants << participant
          participant.socket.on :close do |event|
            remove(participant)
          end
        end

        def remove(participant)
          raise "Participant instance expected" unless participant.is_a? Participant
          @participants.delete participant
        end

        def include?(participant)
          raise "Participant instance expected" unless participant.is_a? Participant
          @participants.include? participant
        end

        def broadcast(message)
          puts "Broadcasting to #{@participants.size} participants"
          @participants.each do |p|
            p.socket.send({
              headers: {
                room: @name,
              },
              body: message
            }.to_json)
          end
        end

      end # class Room
    end # module Hub
  end # module Websocket
end # module Startback

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
startback-websocket-0.17.4 lib/startback/websocket/hub/room.rb
startback-websocket-0.17.3 lib/startback/websocket/hub/room.rb
startback-websocket-0.17.2 lib/startback/websocket/hub/room.rb
startback-websocket-0.17.1 lib/startback/websocket/hub/room.rb
startback-websocket-0.17.0 lib/startback/websocket/hub/room.rb
startback-websocket-0.16.0 lib/startback/websocket/hub/room.rb
startback-websocket-0.15.5 lib/startback/websocket/hub/room.rb
startback-websocket-0.15.4 lib/startback/websocket/hub/room.rb
startback-websocket-0.15.3 lib/startback/websocket/hub/room.rb
startback-websocket-0.15.2 lib/startback/websocket/hub/room.rb
startback-websocket-0.15.1 lib/startback/websocket/hub/room.rb
startback-websocket-0.15.0 lib/startback/websocket/hub/room.rb
startback-websocket-0.14.4 lib/startback/websocket/hub/room.rb
startback-websocket-0.14.3 lib/startback/websocket/hub/room.rb
startback-websocket-0.14.2 lib/startback/websocket/hub/room.rb
startback-websocket-0.14.1 lib/startback/websocket/hub/room.rb