src/client.js
function _encryptEventIfNeeded(client, event, room) {
    if (event.isEncrypted()) {
        // this event has already been encrypted; this happens if the
        // encryption step succeeded, but the send step failed on the first
        // attempt.
        return null;
    }

    if (!client.isRoomEncrypted(event.getRoomId())) {
        // looks like this room isn't encrypted.
        return null;
    }

    if (!client._crypto) {
        throw new Error(
            "This room is configured to use encryption, but your client does " +
            "not support encryption.",
        );
    }

    return client._crypto.encryptEvent(event, room);
}
function _encryptEventIfNeeded(client, event, room) {
    if (event.isEncrypted()) {
        // this event has already been encrypted; this happens if the
        // encryption step succeeded, but the send step failed on the first
        // attempt.
        return null;
    }

    if (!client.isRoomEncrypted(event.getRoomId())) {
        // looks like this room isn't encrypted.
        return null;
    }

    if (!client._crypto) {
        throw new Error(
            "This room is configured to use encryption, but your client does " +
            "not support encryption.",
        );
    }

    return client._crypto.encryptEvent(event, room);
}
function _encryptEventIfNeeded ( client , event , room ) { if ( event . isEncrypted ( ) ) { // this event has already been encrypted; this happens if the // encryption step succeeded, but the send step failed on the first // attempt. return null ; } if ( ! client . isRoomEncrypted ( event . getRoomId ( ) ) ) { // looks like this room isn't encrypted. return null ; } if ( ! client . _crypto ) { throw new Error ( "This room is configured to use encryption, but your client does " + "not support encryption." , ) ; } return client . _crypto . encryptEvent ( event , room ) ; }
Encrypt an event according to the configuration of the room, if necessary.

@param {MatrixClient} client

@param {module:models/event.MatrixEvent} event  event to be sent

@param {module:models/room?} room destination room. Null if the destination
is not a room we have seen over the sync pipe.

@return {module:client.Promise?} Promise which resolves when the event has been
encrypted, or null if nothing was needed
Encrypt an event according to the configuration of the room if necessary .