How to use the matrix-js-sdk.createClient function in matrix-js-sdk

To help you get started, we’ve selected a few matrix-js-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github matrix-hacks / matrix-puppet-imessage / bridge.js View on Github external
matrixClient.loginWithPassword(config.owner, config.ownerPassword).then( (accessDat) => {
      console.log("log in success");

      // Reinitialize client with access token.
      matrixClient = matrixSdk.createClient({
        baseUrl: config.bridge.homeserverUrl,
        userId: config.owner,
        // TODO: Instead of storing our password in the config file, prompt for
        // the username/password interactively on the terminal at startup, then
        // persist the access token on the fs. If access token login fails in a
        // subsequent startup, re-prompt for password.
        accessToken: accessDat.access_token,
      });

      matrixClient.startClient(); // This function blocks
    });
  };
github FabricLabs / fabric / src / Lifecycle.js View on Github external
function _registerAsGuest(hsUrl, isUrl, defaultDeviceDisplayName) {
    console.log(`Doing guest login on ${hsUrl}`);

    // create a temporary MatrixClient to do the login
    const client = Matrix.createClient({
        baseUrl: hsUrl,
    });

    return client.registerGuest({
        body: {
            initial_device_display_name: defaultDeviceDisplayName,
        },
    }).then((creds) => {
        console.log(`Registered as guest: ${creds.user_id}`);
        return _doSetLoggedIn({
            userId: creds.user_id,
            deviceId: creds.device_id,
            accessToken: creds.access_token,
            homeserverUrl: hsUrl,
            identityServerUrl: isUrl,
            guest: true,
github FabricLabs / fabric / src / Signup.js View on Github external
}, function(error) {
            if (error.httpStatus == 400 && loginParams.medium) {
                error.friendlyText = (
                    'This Home Server does not support login using email address.'
                );
            }
            else if (error.httpStatus === 403) {
                error.friendlyText = (
                    'Incorrect username and/or password.'
                );
                if (self._fallbackHsUrl) {
                    var fbClient = Matrix.createClient({
                        baseUrl: self._fallbackHsUrl,
                        idBaseUrl: this._isUrl,
                    });

                    return fbClient.login('m.login.password', loginParams).then(function(data) {
                        return q({
                            homeserverUrl: self._fallbackHsUrl,
                            identityServerUrl: self._isUrl,
                            userId: data.user_id,
                            deviceId: data.device_id,
                            accessToken: data.access_token
                        });
                    }, function(fallback_error) {
                        // throw the original error
                        throw error;
                    });
github turt2live / matrix-email-bot / src / MatrixHandler.js View on Github external
constructor() {
        this._roomList = [];
        this._userId = config.get("matrix.userId");
        this._client = sdk.createClient({
            baseUrl: config.get("matrix.homeserverUrl"),
            accessToken: config.get("matrix.accessToken"),
            userId: this._userId
        });

        this._client.on('sync', (state, prevState, data) => {
            switch (state) {
                case 'PREPARED':
                    this._updateRoomList();
                    break;
            }
        });

        this._client.on('Room', this._updateRoomList.bind(this));

        this._client.startClient(25); // limit number of messages to keep, we're not interesting in keeping history here
github FabricLabs / fabric / src / PasswordReset.js View on Github external
constructor(homeserverUrl, identityUrl) {
        this.client = Matrix.createClient({
            baseUrl: homeserverUrl,
            idBaseUrl: identityUrl,
        });
        this.clientSecret = this.client.generateClientSecret();
        this.identityServerDomain = identityUrl.split("://")[1];
    }
github gluon-project / gluon-rxp / src / Services / Matrix / index.ts View on Github external
export const login = (username: string, password: string, baseUrl: string) => {
  const tmpClient = Matrix.createClient({baseUrl, request})
  return new Promise((resolve, reject) => {
    tmpClient.login('m.login.password', {user: username, password: password}, (err: any, resp: any) => {
      console.log(err)
      if (err) {
        reject(err)
      } else {
        console.log(resp)

        client = Matrix.createClient({
            baseUrl,
            userId: resp.user_id,
            accessToken: resp.access_token,
            request,
            timelineSupport: true,
        })
        createFileFilter()
github FabricLabs / fabric / src / Signup.js View on Github external
_createTemporaryClient() {
        return Matrix.createClient({
            baseUrl: this._hsUrl,
            idBaseUrl: this._isUrl,
        });
    }
}
github lukebarnard1 / journal / src / logic / main.js View on Github external
createClient = (opts) => {
        if (window.indexedDB && localStorage) {
            Object.assign(opts, {
                store: new matrixSdk.IndexedDBStore({
                    indexedDB: window.indexedDB,
                }),
            });
        }
        return matrixSdk.createClient(opts);
    }
github FabricLabs / fabric / src / Login.js View on Github external
_createTemporaryClient() {
        return Matrix.createClient({
            baseUrl: this._hsUrl,
            idBaseUrl: this._isUrl,
        });
    }
github matrix-hacks / matrix-puppet-server / src / puppet.ts View on Github external
private login(token: string) : Promise {
    this.client = matrixSdk.createClient({
      baseUrl: this.homeserverUrl,
      userId: this.userId,
      accessToken: token
    })
    this.client.startClient();
    return new Promise((resolve, _reject) => {
      this.matrixRoomMembers = {};
      this.client.on("RoomState.members", (event, state, _member) => {
        this.matrixRoomMembers[state.roomId] = Object.keys(state.members);
      });

      this.client.on("Room.receipt", (event, room) => {
        if (this.adapter && this.adapter.sendReadReceipt) {
          if (room.roomId in this.thirdPartyRooms) {
            let content = event.getContent();
            for (var eventId in content) {