From d11283f0f106de8df21ceef8a1edab21bc350800 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 29 Jun 2021 07:39:53 -0700 Subject: [PATCH] Update RingRTC to v2.10.6 --- package.json | 2 +- ts/components/GroupCallRemoteParticipant.tsx | 4 +- ts/services/calling.ts | 51 ++++++++++--------- .../fakeGetGroupCallVideoFrameSource.ts | 6 +-- ts/types/Calling.ts | 2 +- yarn.lock | 10 ++-- 6 files changed, 42 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index 67ee2df69..8d350ec70 100644 --- a/package.json +++ b/package.json @@ -147,7 +147,7 @@ "redux-ts-utils": "3.2.2", "reselect": "4.0.0", "rimraf": "2.6.2", - "ringrtc": "https://github.com/signalapp/signal-ringrtc-node.git#a669f0becf3ec392707e78b3d3521100fde24b97", + "ringrtc": "https://github.com/signalapp/signal-ringrtc-node.git#868f7ecb699b984171b5ad02f9b043bfa55ad804", "rotating-file-stream": "2.1.5", "sanitize-filename": "1.6.3", "sanitize.css": "11.0.0", diff --git a/ts/components/GroupCallRemoteParticipant.tsx b/ts/components/GroupCallRemoteParticipant.tsx index 1b816be68..625cf7cd2 100644 --- a/ts/components/GroupCallRemoteParticipant.tsx +++ b/ts/components/GroupCallRemoteParticipant.tsx @@ -129,7 +129,9 @@ export const GroupCallRemoteParticipant: React.FC = React.memo( // for other participants, or pixel data from a previous frame. That's why we // return early and use the `frameWidth` and `frameHeight`. const frameBuffer = getFrameBuffer(); - const frameDimensions = videoFrameSource.receiveVideoFrame(frameBuffer); + const frameDimensions = videoFrameSource.receiveVideoFrame( + Buffer.from(frameBuffer) + ); if (!frameDimensions) { return; } diff --git a/ts/services/calling.ts b/ts/services/calling.ts index cf89c7ed7..fda49d145 100644 --- a/ts/services/calling.ts +++ b/ts/services/calling.ts @@ -50,8 +50,8 @@ import { } from '../types/Calling'; import { LocalizerType } from '../types/Util'; import { ConversationModel } from '../models/conversations'; +import * as Bytes from '../Bytes'; import { - base64ToArrayBuffer, uuidToArrayBuffer, arrayBufferToUuid, typedArrayToArrayBuffer, @@ -384,8 +384,8 @@ export class CallingClass { return getMembershipList(conversationId).map( member => new GroupMemberInfo( - uuidToArrayBuffer(member.uuid), - typedArrayToArrayBuffer(member.uuidCiphertext) + Buffer.from(uuidToArrayBuffer(member.uuid)), + Buffer.from(member.uuidCiphertext) ) ); } @@ -425,11 +425,11 @@ export class CallingClass { if (!proof) { throw new Error('No membership proof. Cannot peek group call'); } - const membershipProof = new TextEncoder().encode(proof).buffer; + const membershipProof = Bytes.fromString(proof); return RingRTC.peekGroupCall( this.sfuUrl, - membershipProof, + Buffer.from(membershipProof), this.getGroupCallMembers(conversationId) ); } @@ -468,7 +468,7 @@ export class CallingClass { throw new Error('Missing SFU URL; not connecting group call'); } - const groupIdBuffer = base64ToArrayBuffer(groupId); + const groupIdBuffer = Buffer.from(Bytes.fromBase64(groupId)); let updateMessageState = GroupCallUpdateMessageState.SentNothing; let isRequestingMembershipProof = false; @@ -548,8 +548,7 @@ export class CallingClass { secretParams, }); if (proof) { - const proofArray = new TextEncoder().encode(proof); - groupCall.setMembershipProof(proofArray.buffer); + groupCall.setMembershipProof(Buffer.from(Bytes.fromString(proof))); } } catch (err) { window.log.error('Failed to fetch membership proof', err); @@ -672,7 +671,7 @@ export class CallingClass { ): GroupCallPeekInfoType { return { uuids: peekInfo.joinedMembers.map(uuidBuffer => { - let uuid = arrayBufferToUuid(uuidBuffer); + let uuid = arrayBufferToUuid(typedArrayToArrayBuffer(uuidBuffer)); if (!uuid) { window.log.error( 'Calling.formatGroupCallPeekInfoForRedux: could not convert peek UUID ArrayBuffer to string; using fallback UUID' @@ -681,7 +680,9 @@ export class CallingClass { } return uuid; }), - creatorUuid: peekInfo.creator && arrayBufferToUuid(peekInfo.creator), + creatorUuid: + peekInfo.creator && + arrayBufferToUuid(typedArrayToArrayBuffer(peekInfo.creator)), eraId: peekInfo.eraId, maxDevices: peekInfo.maxDevices ?? Infinity, deviceCount: peekInfo.deviceCount, @@ -718,7 +719,9 @@ export class CallingClass { ? this.formatGroupCallPeekInfoForRedux(peekInfo) : undefined, remoteParticipants: remoteDeviceStates.map(remoteDeviceState => { - let uuid = arrayBufferToUuid(remoteDeviceState.userId); + let uuid = arrayBufferToUuid( + typedArrayToArrayBuffer(remoteDeviceState.userId) + ); if (!uuid) { window.log.error( 'Calling.formatGroupCallForRedux: could not convert remote participant UUID ArrayBuffer to string; using fallback UUID' @@ -1315,13 +1318,13 @@ export class CallingClass { RingRTC.handleCallingMessage( remoteUserId, - sourceUuid, + sourceUuid ? Buffer.from(sourceUuid) : null, remoteDeviceId, this.localDeviceId, messageAgeSec, callingMessage, - senderIdentityKey, - receiverIdentityKey + Buffer.from(senderIdentityKey), + Buffer.from(receiverIdentityKey) ); } @@ -1395,17 +1398,17 @@ export class CallingClass { } private async handleSendCallMessage( - recipient: ArrayBuffer, - data: ArrayBuffer + recipient: Uint8Array, + data: Uint8Array ): Promise { - const userId = arrayBufferToUuid(recipient); + const userId = arrayBufferToUuid(typedArrayToArrayBuffer(recipient)); if (!userId) { window.log.error('handleSendCallMessage(): bad recipient UUID'); return false; } const message = new CallingMessage(); message.opaque = new OpaqueMessage(); - message.opaque.data = data; + message.opaque.data = Buffer.from(data); return this.handleOutgoingSignaling(userId, message); } @@ -1585,7 +1588,7 @@ export class CallingClass { url: string, method: HttpMethod, headers: { [name: string]: string }, - body: ArrayBuffer | undefined + body: Uint8Array | undefined ) { if (!window.textsecure.messaging) { RingRTC.httpRequestFailed(requestId, 'We are offline'); @@ -1607,14 +1610,14 @@ export class CallingClass { url, httpMethod, headers, - body + body ? typedArrayToArrayBuffer(body) : undefined ); } catch (err) { if (err.code !== -1) { // WebAPI treats certain response codes as errors, but RingRTC still needs to // see them. It does not currently look at the response body, so we're giving // it an empty one. - RingRTC.receivedHttpResponse(requestId, err.code, new ArrayBuffer(0)); + RingRTC.receivedHttpResponse(requestId, err.code, Buffer.alloc(0)); } else { window.log.error('handleSendHttpRequest: fetch failed with error', err); RingRTC.httpRequestFailed(requestId, String(err)); @@ -1625,7 +1628,7 @@ export class CallingClass { RingRTC.receivedHttpResponse( requestId, result.response.status, - result.data + Buffer.from(result.data) ); } @@ -1749,7 +1752,9 @@ export class CallingClass { if (!peekInfo || !peekInfo.eraId || !peekInfo.creator) { return; } - const creatorUuid = arrayBufferToUuid(peekInfo.creator); + const creatorUuid = arrayBufferToUuid( + typedArrayToArrayBuffer(peekInfo.creator) + ); if (!creatorUuid) { window.log.error('updateCallHistoryForGroupCall(): bad creator UUID'); return; diff --git a/ts/test-both/helpers/fakeGetGroupCallVideoFrameSource.ts b/ts/test-both/helpers/fakeGetGroupCallVideoFrameSource.ts index b148af1e1..8f6dad6be 100644 --- a/ts/test-both/helpers/fakeGetGroupCallVideoFrameSource.ts +++ b/ts/test-both/helpers/fakeGetGroupCallVideoFrameSource.ts @@ -31,15 +31,13 @@ class FakeGroupCallVideoFrameSource implements VideoFrameSource { this.dimensions = [width, height]; } - receiveVideoFrame( - destinationBuffer: ArrayBuffer - ): [number, number] | undefined { + receiveVideoFrame(destinationBuffer: Buffer): [number, number] | undefined { // Simulate network jitter. Also improves performance when testing. if (Math.random() < 0.5) { return undefined; } - new Uint8Array(destinationBuffer).set(this.sourceArray); + destinationBuffer.set(this.sourceArray); return this.dimensions; } } diff --git a/ts/types/Calling.ts b/ts/types/Calling.ts index 647ed8295..38d2bed3d 100644 --- a/ts/types/Calling.ts +++ b/ts/types/Calling.ts @@ -134,7 +134,7 @@ export type GroupCallVideoRequest = { // Should match RingRTC's VideoFrameSource export type VideoFrameSource = { - receiveVideoFrame(buffer: ArrayBuffer): [number, number] | undefined; + receiveVideoFrame(buffer: Buffer): [number, number] | undefined; }; // Must be kept in sync with RingRTC.AudioDevice diff --git a/yarn.lock b/yarn.lock index 3b56296e3..5d8498699 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15754,9 +15754,13 @@ rimraf@^3.0.2, rimraf@~3.0.2: dependencies: glob "^7.1.3" -"ringrtc@https://github.com/signalapp/signal-ringrtc-node.git#a669f0becf3ec392707e78b3d3521100fde24b97": - version "2.10.5" - resolved "https://github.com/signalapp/signal-ringrtc-node.git#a669f0becf3ec392707e78b3d3521100fde24b97" +"ringrtc@https://github.com/signalapp/signal-ringrtc-node.git#0956fdc542cb7d1a0f3a06f28b8966adf359bb61": + version "2.10.6" + resolved "https://github.com/signalapp/signal-ringrtc-node.git#0956fdc542cb7d1a0f3a06f28b8966adf359bb61" + +"ringrtc@https://github.com/signalapp/signal-ringrtc-node.git#868f7ecb699b984171b5ad02f9b043bfa55ad804": + version "2.10.6" + resolved "https://github.com/signalapp/signal-ringrtc-node.git#868f7ecb699b984171b5ad02f9b043bfa55ad804" ripemd160@^2.0.0, ripemd160@^2.0.1: version "2.0.1"