-
Notifications
You must be signed in to change notification settings - Fork 2
FCE-2487: Fix media stream usage docs #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,35 @@ | ||
| import type { | ||
| MediaStream as RNMediaStream, | ||
| RTCVideoViewProps as OriginalRTCVideoViewProps, | ||
| } from '@fishjam-cloud/react-native-webrtc'; | ||
| import { RTCView as OriginalRTCView } from '@fishjam-cloud/react-native-webrtc'; | ||
| import type { MediaStream as RNMediaStream } from '@fishjam-cloud/react-native-webrtc'; | ||
| import { RTCPIPView as OriginalRTCPIPView, RTCView as OriginalRTCView } from '@fishjam-cloud/react-native-webrtc'; | ||
| import type React from 'react'; | ||
| import { useMemo } from 'react'; | ||
|
|
||
| export type RTCVideoViewProps = Omit<OriginalRTCVideoViewProps, 'streamURL'> & { mediaStream: MediaStream }; | ||
| export type RTCVideoViewProps = Omit<React.ComponentPropsWithRef<typeof OriginalRTCView>, 'streamURL'> & { | ||
| mediaStream: MediaStream; | ||
| }; | ||
|
|
||
| export type RTCPIPViewProps = Omit<React.ComponentPropsWithRef<typeof OriginalRTCPIPView>, 'streamURL'> & { | ||
| mediaStream: MediaStream; | ||
| }; | ||
|
|
||
| const convertMediaStreamToURL = (mediaStream: MediaStream | undefined): string | undefined => { | ||
| const rnMediaStream = mediaStream as unknown as RNMediaStream; | ||
| if (rnMediaStream && typeof rnMediaStream.toURL === 'function') { | ||
| return rnMediaStream.toURL(); | ||
| } else { | ||
| console.error( | ||
| 'mediaStream.toURL is not a function. Make sure to use the MediaStream type from @fishjam-cloud/react-native-webrtc', | ||
| rnMediaStream, | ||
| ); | ||
| return undefined; | ||
| } | ||
| }; | ||
|
|
||
| export const RTCView = ({ ref, ...props }: RTCVideoViewProps) => { | ||
| const streamURL = useMemo(() => convertMediaStreamToURL(props.mediaStream), [props.mediaStream]); | ||
| return <OriginalRTCView {...props} ref={ref} streamURL={streamURL} />; | ||
| }; | ||
|
|
||
| export const RTCView = (props: RTCVideoViewProps) => { | ||
| const streamURL = useMemo(() => { | ||
| const mediaStream = props.mediaStream as unknown as RNMediaStream; | ||
| if (mediaStream && typeof mediaStream.toURL === 'function') { | ||
| return mediaStream.toURL(); | ||
| } else { | ||
| console.error( | ||
| 'RTCView: mediaStream.toURL is not a function. Make sure to use the MediaStream type from @fishjam-cloud/react-native-webrtc', | ||
| mediaStream, | ||
| ); | ||
| return undefined; | ||
| } | ||
| }, [props.mediaStream]); | ||
| return <OriginalRTCView {...props} streamURL={streamURL} />; | ||
| export const RTCPIPView = ({ ref, ...props }: RTCPIPViewProps) => { | ||
| const streamURL = useMemo(() => convertMediaStreamToURL(props.mediaStream), [props.mediaStream]); | ||
| return <OriginalRTCPIPView {...props} ref={ref} streamURL={streamURL} />; | ||
MiloszFilimowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.