Super lightweight Matrix client and simple event listener.

Far from perfect, but works both on browser and on OpenWRT with NodeJS 8 and full POC takes only 50k as compiled single bundle file (including all the dependencies) :)

Hierarchy

  • SimpleMatrixClient

Implements

Constructors

  • Create an instance of SimpleMatrixClient.

    Parameters

    • url: string

      The URL of the Matrix server to login

    • homeServerUrl: string = undefined

      Optional. The Matrix server URL for a logged in session.

    • identityServerUrl: string = undefined

      Optional. The Matrix identity server URL for a logged in session.

    • accessToken: string = undefined

      Optional. The access key for a logged in session.

    • userId: string = undefined

      Optional. The Matrix user ID for a logged in session.

    • pollTimeout: number = 30000

      Optional. The default poll time in milliseconds to poll changes from upstream Matrix server.

    • pollWaitTime: number = 1000

      Optional. The default wait time between polls, in milliseconds.

    Returns SimpleMatrixClient

Properties

_accessToken: string
_homeServerUrl: string
_identityServerUrl: string
_initSyncAgainTimer: any
_nextSyncBatch: string
_observer: Observer<EVENT>
_originalUrl: string
_stopSyncOnNext: boolean
_syncAgainTimeMs: number
_syncAgainTimeoutCallback: VoidCallback
_syncAgainTimer: any
_syncRequestTimeoutMs: number
_userId: string
Event: typeof SimpleMatrixClientEvent = SimpleMatrixClientEvent

Methods

  • Private

    The state must be AUTHENTICATED to call this method.

    While this method is executing the state will be AUTHENTICATED_AND_STARTING.

    This method controls state change to:

    1. AUTHENTICATED_AND_STARTED if successful
    2. AUTHENTICATED if previous stop request was received while the request was executing
    3. AUTHENTICATED_AND_RESTARTING if not successful (see _startInitSyncAgainLater)

    Parameters

    • triggerEvents: boolean

    Returns Promise<void>

  • Private

    Called when it's time to try again previous failed init sync

    Parameters

    • triggerEvents: boolean

    Returns void

  • Private

    Will start a timeout until this._initSync() is called again after a failed request.

    The state must be AUTHENTICATED_AND_RESTARTING.

    Parameters

    • triggerEvents: boolean

    Returns void

  • Private

    Will start a timeout until this._syncNextBatch() is called.

    The state must be AUTHENTICATED_AND_STARTED;

    Returns void

  • Start the long polling event listener from Matrix server.

    The state SHOULD be AUTHENTICATED.

    Nothing is done if the state is AUTHENTICATED_AND_STARTING, AUTHENTICATED_AND_RESTARTING, AUTHENTICATED_AND_STARTED or AUTHENTICATED_AND_SYNCING -- except if stop request has been scheduled, which will be cancelled.

    The state must not be UNAUTHENTICATED or AUTHENTICATING.

    @FIXME: This could be started automatically from listeners in our own observer. If so, this method could be changed to private later.

    Parameters

    • triggerEvents: boolean

    Returns void

  • Stops the internal long polling loop against the Matrix server.

    State should be AUTHENTICATED_AND_STARTED.

    Will schedule stop later if state is AUTHENTICATED_AND_STARTING, AUTHENTICATED_AND_RESTARTING or AUTHENTICATED_AND_SYNCING.

    Will not do anything (but warning) if state is UNAUTHENTICATED, AUTHENTICATING or AUTHENTICATED.

    @FIXME: This could be stopped automatically when listeners are removed from our own observer. If so, this method could be changed to private later.

    Returns void

  • Private

    The state MUST be AUTHENTICATED_AND_STARTED to call this method.

    While this method is executing the state will be AUTHENTICATED_AND_SYNCING.

    It will result in a state:

    1. AUTHENTICATED_AND_STARTED if successful
    2. AUTHENTICATED if previous stop request was received

    Returns Promise<void>

  • Destroys the current client instance, including all observers.

    You should not use this instance anymore after you call this method.

    Returns void

  • Forgets a room.

    Once every member has forgot it, the room will be marked for deletion in homeserver.

    Parameters

    • roomId: string

    Returns Promise<void>

  • Invite user to a room.

    Parameters

    • roomId: string
    • userId: string

    Returns Promise<void>

  • Log in to the matrix server

    Returns

    New instance of SimpleMatrixClient which is initialized in to the authenticated state

    Parameters

    • userId: string

      The Matrix user ID to log into

    • password: string

      The Matrix user password

    Returns Promise<SimpleMatrixClient>

  • Resolve room name (eg. alias) into room ID.

    Eg. if you say 'foo' here, it will be converted to '#foo:homeServerHostname'.

    Parameters

    • name: string

    Returns Promise<string>

  • Send text message to the room.

    Parameters

    • roomId: string

      The room ID

    • body: string

      The message string

    Returns Promise<void>

  • Start the long polling event listener from Matrix server.

    @FIXME: This could be started automatically from listeners in our own observer. If so, this method could be changed to private later.

    Parameters

    • triggerEvents: boolean = true

    Returns void

  • Stop the long polling event listener from Matrix server.

    It will not remove any listeners.

    @FIXME: This could be stopped automatically when listeners are removed from our own observer. If so, this method could be changed to private later.

    Returns void

  • Parameters

    • events: readonly string[]
    • onlyInRooms: readonly string[] = undefined
    • timeout: number = undefined

      Optional. The default is 30 seconds.

    • triggerEvents: boolean = true

      Optional. If true, events from the first sync call are triggered.

    Returns Promise<boolean>

Generated using TypeDoc