Class: RComet::User

Inherits:
Object
  • Object
show all
Defined in:
lib/rcomet/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter) ⇒ User

Create a new Comet user



7
8
9
10
11
12
13
14
15
# File 'lib/rcomet/user.rb', line 7

def initialize(adapter)
  @connected = false
  @id = RComet.random(64)
  
  @channels = Hash.new
  @event_mutex = Mutex.new
  @messages = []
  @adapter = adapter
end

Instance Attribute Details

#connectedObject

Returns the value of attribute connected.



4
5
6
# File 'lib/rcomet/user.rb', line 4

def connected
  @connected
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/rcomet/user.rb', line 3

def id
  @id
end

Instance Method Details

#has_channel?Boolean

:nodoc:



57
58
59
# File 'lib/rcomet/user.rb', line 57

def has_channel? #:nodoc:
  return( not @channels.empty? )
end

#send(message) ⇒ Object

:nodoc:



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rcomet/user.rb', line 27

def send( message ) #:nodoc:
  if @connected == false
    ## ADD TIMEOUT !
    unless @adapter.timeout.nil?
      @adapter.timeout.call(self)
    end
  end
  
  @messages << message
  @continue = false
end

#subscribe(channel) ⇒ Object

Subscribe to a given channel



40
41
42
43
# File 'lib/rcomet/user.rb', line 40

def subscribe( channel )
  channel.add_user( self )
  @channels[channel.path] = channel
end

#unsubscribe(channel) ⇒ Object

Unsubscribe to a given channel



46
47
48
49
# File 'lib/rcomet/user.rb', line 46

def unsubscribe( channel )
  c = @channels.delete(channel)
  c.delete_user(self) if c
end

#unsubscribe_allObject



51
52
53
54
55
# File 'lib/rcomet/user.rb', line 51

def unsubscribe_all( )
  @channels.each do |c|
    unsubscribe(c)
  end
end

#wait(messages) ⇒ Object

:nodoc:



17
18
19
20
21
22
23
24
25
# File 'lib/rcomet/user.rb', line 17

def wait( messages ) #:nodoc:
  @continue = @messages.empty?
  @messages << messages
  while @continue; end
  
  messages = @messages.clone
  @messages = []
  return messages
end