Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "matrix-js-sdk in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'matrix-js-sdk' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

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
    });
  };
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,
}
                else {
                    console.error("Unknown conf call type: %s", payload.type);
                }
            }

            var members = room.getJoinedMembers();
            if (members.length <= 1) {
                Modal.createDialog(ErrorDialog, {
                    description: "You cannot place a call with yourself."
                });
                return;
            }
            else if (members.length === 2) {
                console.log("Place %s call in %s", payload.type, payload.room_id);
                var call = Matrix.createNewMatrixCall(
                    MatrixClientPeg.get(), payload.room_id
                );
                placeCall(call);
            }
            else { // > 2
                console.log("Place conference call in %s", payload.room_id);
                var confCall = new ConferenceCall(
                    MatrixClientPeg.get(), payload.room_id
                );
                confCall.setup().done(function(call) {
                    placeCall(call);
                }, function(err) {
                    console.error("Failed to setup conference call: %s", err);
                });
            }
            break;
const room = MatrixClientPeg.get().getRoom(payload.room_id);
                if (!room) {
                    console.error("Room %s does not exist.", payload.room_id);
                    return;
                }

                const members = room.getJoinedMembers();
                if (members.length <= 1) {
                    const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
                    Modal.createTrackedDialog('Call Handler', 'Cannot place call with self', ErrorDialog, {
                        description: _t('You cannot place a call with yourself.'),
                    });
                    return;
                } else if (members.length === 2) {
                    console.log("Place %s call in %s", payload.type, payload.room_id);
                    const call = Matrix.createNewMatrixCall(MatrixClientPeg.get(), payload.room_id);
                    placeCall(call);
                } else { // > 2
                    dis.dispatch({
                        action: "place_conference_call",
                        room_id: payload.room_id,
                        type: payload.type,
                        remote_element: payload.remote_element,
                        local_element: payload.local_element,
                    });
                }
            }
            break;
        case 'place_conference_call':
            console.log("Place conference call in %s", payload.room_id);
            _startCallApp(payload.room_id, payload.type);
            break;
}
        }

        let discoveryResult = null;
        if (wkConfig) {
            console.log("Config uses a default_server_config - validating object");
            discoveryResult = await AutoDiscovery.fromDiscoveryConfig(wkConfig);
        }

        if (serverName) {
            console.log("Config uses a default_server_name - doing .well-known lookup");
            console.warn(
                "DEPRECATED CONFIG OPTION: In the future, default_server_name will not be accepted. Please " +
                "use default_server_config instead.",
            );
            discoveryResult = await AutoDiscovery.findClientConfig(serverName);
        }

        validatedConfig = AutoDiscoveryUtils.buildValidatedConfigFromDiscovery(serverName, discoveryResult, true);
    } catch (e) {
        const {hsUrl, isUrl, userId} = Lifecycle.getLocalStorageSessionVars();
        if (hsUrl && userId) {
            console.error(e);
            console.warn("A session was found - suppressing config error and using the session's homeserver");

            console.log("Using pre-existing hsUrl and isUrl: ", {hsUrl, isUrl});
            validatedConfig = await AutoDiscoveryUtils.validateServerConfigWithStaticUrls(hsUrl, isUrl, true);
        } else {
            // the user is not logged in, so scream
            throw e;
        }
    }
}, 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;
                    });
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
return promise.then(function(eventContent) {
        self.opts.backingStore.setPowerLevelContent(roomId, eventContent);
        var event = {
            content: eventContent,
            room_id: roomId,
            user_id: "",
            event_id: "_",
            state_key: "",
            type: "m.room.power_levels"
        }
        var powerLevelEvent = new MatrixEvent(event);
        // What level do we need for this event type?
        var defaultLevel = event.content.events_default;
        if (STATE_EVENT_TYPES.indexOf(eventType) !== -1) {
            defaultLevel = event.content.state_default;
        }
        var requiredLevel = event.content.events[eventType] || defaultLevel;

        // Parse out what level the client has by abusing the JS SDK
        var roomMember = new RoomMember(roomId, userId);
        roomMember.setPowerLevelEvent(powerLevelEvent);

        if (requiredLevel > roomMember.powerLevel) {
            // can the bot update our power level?
            var bot = new RoomMember(roomId, self.botClient.credentials.userId);
            bot.setPowerLevelEvent(powerLevelEvent);
            var levelRequiredToModifyPowerLevels = event.content.events[
.forEach(function(roomId)
            {
                // XXX: todo: merge overlapping results somehow?
                // XXX: why doesn't searching on name work?
                if (self.state.searchScope === 'All') {
                    ret.push(<li><h1>Room: { cli.getRoom(roomId).name }</h1></li>);
                }

                var resultList = roomIdGroups[roomId].results.map(function(eventId) { return results[eventId]; });
                for (var i = resultList.length - 1; i &gt;= 0; i--) {
                    var ts1 = resultList[i].result.origin_server_ts;
                    ret.push(<li></li>); // Rank: {resultList[i].rank}
                    var mxEv = new Matrix.MatrixEvent(resultList[i].result);
                    if (resultList[i].context.events_before[0]) {
                        var mxEv2 = new Matrix.MatrixEvent(resultList[i].context.events_before[0]);
                        if (EventTile.haveTileForEvent(mxEv2)) {
                            ret.push(<li></li>);
                        }
                    }
                    if (EventTile.haveTileForEvent(mxEv)) {
                        ret.push(<li></li>);
                    }
                    if (resultList[i].context.events_after[0]) {
                        var mxEv2 = new Matrix.MatrixEvent(resultList[i].context.events_after[0]);
                        if (EventTile.haveTileForEvent(mxEv2)) {
                            ret.push(<li></li>);
                        }
                    }
                }
var resultList = roomIdGroups[roomId].results.map(function(eventId) { return results[eventId]; });
                for (var i = resultList.length - 1; i &gt;= 0; i--) {
                    var ts1 = resultList[i].result.origin_server_ts;
                    ret.push(<li></li>); // Rank: {resultList[i].rank}
                    var mxEv = new Matrix.MatrixEvent(resultList[i].result);
                    if (resultList[i].context.events_before[0]) {
                        var mxEv2 = new Matrix.MatrixEvent(resultList[i].context.events_before[0]);
                        if (EventTile.haveTileForEvent(mxEv2)) {
                            ret.push(<li></li>);
                        }
                    }
                    if (EventTile.haveTileForEvent(mxEv)) {
                        ret.push(<li></li>);
                    }
                    if (resultList[i].context.events_after[0]) {
                        var mxEv2 = new Matrix.MatrixEvent(resultList[i].context.events_after[0]);
                        if (EventTile.haveTileForEvent(mxEv2)) {
                            ret.push(<li></li>);
                        }
                    }
                }
            });
            return ret;

Is your System Free of Underlying Vulnerabilities?
Find Out Now