From 0d42a9b1c76d29745fa4c84eefdebdbb44f0aadb Mon Sep 17 00:00:00 2001 From: Aleksander Nicacio da Silva Date: Mon, 30 Dec 2024 14:33:53 -0300 Subject: [PATCH] feat: stream changes --- app/lib/voip/RemoteStream.ts | 52 +++++-------------------------- app/lib/voip/Stream.ts | 14 ++++++--- app/views/RoomView/definitions.ts | 1 + app/views/RoomView/index.tsx | 8 +++-- index.js | 7 +++++ 5 files changed, 32 insertions(+), 50 deletions(-) diff --git a/app/lib/voip/RemoteStream.ts b/app/lib/voip/RemoteStream.ts index b870cb2bae..0f42c9de27 100644 --- a/app/lib/voip/RemoteStream.ts +++ b/app/lib/voip/RemoteStream.ts @@ -11,65 +11,29 @@ * detecting voice energy etc. Which will be implemented as when needed */ +import { MediaStream, RTCPeerConnection } from 'react-native-webrtc'; + import Stream from './Stream'; export default class RemoteStream extends Stream { - private renderingMediaElement: HTMLMediaElement | undefined; - constructor(mediaStream: MediaStream) { super(mediaStream); } - /** - * Called for initializing the class - * @remarks - */ - - init(rmElement: HTMLMediaElement): void { - if (this.renderingMediaElement) { - // Someone already has setup the stream and initializing it once again - // Clear the existing stream object - this.renderingMediaElement.pause(); - this.renderingMediaElement.srcObject = null; - } - this.renderingMediaElement = rmElement; - } - /** * Called for playing the stream * @remarks * Plays the stream on media element. Stream will be autoplayed and muted based on the settings. * throws and error if the play fails. */ - - play(autoPlay = true, muteAudio = false): void { - if (this.renderingMediaElement && this.mediaStream) { - this.renderingMediaElement.autoplay = autoPlay; - this.renderingMediaElement.srcObject = this.mediaStream; - if (autoPlay) { - this.renderingMediaElement.play().catch((error: Error) => { - throw error; - }); - } - if (muteAudio) { - this.renderingMediaElement.volume = 0; - } + play(): void { + if (!this.mediaStream || this.mediaStream.getAudioTracks().length === 0) { + throw Error('No audio tracks available in the media stream.'); } - } - /** - * Called for pausing the stream - * @remarks - */ - pause(): void { - this.renderingMediaElement?.pause(); - } + const [audioTrack] = this.mediaStream.getAudioTracks(); + const peerConnection = new RTCPeerConnection(); - clear(): void { - super.clear(); - if (this.renderingMediaElement) { - this.renderingMediaElement.pause(); - this.renderingMediaElement.srcObject = null; - } + peerConnection.addTrack(audioTrack, this.mediaStream); } } diff --git a/app/lib/voip/Stream.ts b/app/lib/voip/Stream.ts index 8473b8558d..604e4e64e0 100644 --- a/app/lib/voip/Stream.ts +++ b/app/lib/voip/Stream.ts @@ -1,3 +1,5 @@ +import { MediaStream } from 'react-native-webrtc'; + /** * This class is used for stream manipulation. * @remarks @@ -36,8 +38,8 @@ export default class Stream { * @remarks */ - onTrackAdded(callBack: any): void { - this.mediaStream?.onaddtrack?.(callBack); + onTrackAdded(callback: any): void { + this.mediaStream?.addEventListener('addtrack', callback); } /** @@ -45,8 +47,12 @@ export default class Stream { * @remarks */ - onTrackRemoved(callBack: any): void { - this.mediaStream?.onremovetrack?.(callBack); + onTrackRemoved(callback: any): void { + this.mediaStream?.addEventListener('removetrack', callback); + } + + getURL() { + return this.mediaStream?.toURL(); } /** diff --git a/app/views/RoomView/definitions.ts b/app/views/RoomView/definitions.ts index f37199757d..a73cef1161 100644 --- a/app/views/RoomView/definitions.ts +++ b/app/views/RoomView/definitions.ts @@ -25,6 +25,7 @@ export interface IRoomViewProps extends IActionSheetProvider, IBaseScreen { render() { console.count(`${this.constructor.name}.render calls`); const { room, loading, action, selectedMessages } = this.state; - const { user, baseUrl, theme, width, serverVersion, navigation, encryptionEnabled } = this.props; + const { remoteStreamUrl, user, baseUrl, theme, width, serverVersion, navigation, encryptionEnabled } = this.props; const { rid, t } = room; let bannerClosed; let announcement; @@ -1516,6 +1517,8 @@ class RoomView extends React.Component { getText: this.getText }}> + {remoteStreamUrl ? : null} + ({ livechatAllowManualOnHold: state.settings.Livechat_allow_manual_on_hold as boolean, airGappedRestrictionRemainingDays: state.settings.Cloud_Workspace_AirGapped_Restrictions_Remaining_Days, inAppFeedback: state.inAppFeedback, - encryptionEnabled: state.encryption.enabled + encryptionEnabled: state.encryption.enabled, + remoteStreamUrl: state.voip.remoteStreamUrl }); export default connect(mapStateToProps)(withDimensions(withTheme(withSafeAreaInsets(withActionSheet(RoomView))))); diff --git a/index.js b/index.js index 3007724045..6ef24e7a47 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,14 @@ if (!isFDroidBuild && isAndroid) { } AppRegistry.registerComponent(appName, () => require('./app/index').default); +AppRegistry.registerHeadlessTask( + 'RNCallKeepBackgroundMessage', + () => + ({ name, callUUID, handle }) => + // Make your call here + Promise.resolve() +); // For storybook, comment everything above and uncomment below // import 'react-native-gesture-handler'; // import 'react-native-console-time-polyfill';