Method: Chatrix::Client#initialize

Defined in:
lib/chatrix/client.rb

#initialize(token, id, homeserver: nil) ⇒ Client

Initializes a new Client instance.

Currently it requires a token, future versions will allow login with arbitrary details.

Parameters:

  • token (String)

    The access token to use.

  • id (String)

    The user ID of the token owner.

  • homeserver (String, nil) (defaults to: nil)

    Homeserver to connect to. If not set, the default homeserver defined in Chatrix::Matrix will be used.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/chatrix/client.rb', line 27

def initialize(token, id, homeserver: nil)
  @matrix = Matrix.new token, homeserver

  @users = Users.new
  @rooms = Rooms.new @users, @matrix

  @me = @users.send(:get_user, id)

  @rooms.on(:added) do |room|
    broadcast(:room_added, room)
    room.on(:invited) { |s, i| broadcast(:invited, room, s, i) }
    room.timeline.on(:message) { |r, m| broadcast(:room_message, r, m) }
  end

  on(:disconnected) { stop_syncing }
end