-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-native): add livestream player component (#1373)
- Loading branch information
1 parent
c048655
commit a821e23
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions
48
...ocusaurus/docs/reactnative/04-ui-components/livestream/03-livestream-player.mdx
This file contains 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
id: livestream-player | ||
title: LivestreamPlayer | ||
--- | ||
|
||
import ImageShowcase from '@site/src/components/ImageShowcase'; | ||
import ViewerLivestream from '../../assets/04-ui-components/livestream/viewer-livestream.png'; | ||
|
||
The `LivestreamPlayer` is a UI component that plays a WebRTC livestream given the call ID and the call type. Under the hood, it uses the [`ViewerLivestream`](./02-viewer-livestream.mdx) component. | ||
|
||
![Preview of the LivestreamPlayer component.](../../assets/04-ui-components/livestream/viewer-livestream.png) | ||
|
||
## General usage | ||
|
||
Let's see how to show the `LivestreamPlayer` UI: | ||
|
||
```tsx | ||
import { | ||
StreamVideo, | ||
LivestreamPlayer, | ||
} from '@stream-io/video-react-native-sdk'; | ||
|
||
const LivestreamScreen() { | ||
return ( | ||
<StreamVideo client={client}> | ||
<LivestreamPlayer callType="livestream" callId={callId} /> | ||
</StreamVideo> | ||
); | ||
} | ||
``` | ||
|
||
## Props | ||
|
||
### `callType` | ||
|
||
The call type. Usually `livestream`. | ||
|
||
### `callId` | ||
|
||
The call ID. | ||
|
||
### `ViewerLivestream` | ||
|
||
Component to override the ViewerLivestream component that is used under the hood. | ||
|
||
| Type | Default Value | | ||
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| `ComponentType`\| `undefined` | [`ViewerLivestream`](https://github.com/GetStream/stream-video-js/blob/main/packages/react-native-sdk/src/components/Livestream/ViewerLivestream/ViewerLivestream.tsx) | |
59 changes: 59 additions & 0 deletions
59
packages/react-native-sdk/src/components/Livestream/LivestreamPlayer/LivestreamPlayer.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { useMemo, useEffect } from 'react'; | ||
import { | ||
ViewerLivestream as DefaultViewerLivestream, | ||
ViewerLivestreamProps, | ||
} from '..'; | ||
import { StreamCall, useStreamVideoClient } from '../../..'; | ||
|
||
export type LivestreamPlayerProps = { | ||
/** | ||
* The call type. Usually `livestream`. | ||
*/ | ||
callType: string; | ||
/** | ||
* The call ID. | ||
*/ | ||
callId: string; | ||
/** | ||
* Component to override the ViewerLivestream component used under the hood. | ||
* **Default** [ViewerLivestream](https://github.com/GetStream/stream-video-js/blob/main/packages/react-native-sdk/src/components/Livestream/ViewerLivestream/ViewerLivestream.tsx) | ||
*/ | ||
ViewerLivestream?: React.ComponentType<ViewerLivestreamProps>; | ||
}; | ||
|
||
export const LivestreamPlayer = ({ | ||
callType, | ||
callId, | ||
ViewerLivestream = DefaultViewerLivestream, | ||
}: LivestreamPlayerProps) => { | ||
const client = useStreamVideoClient(); | ||
|
||
const call = useMemo( | ||
() => client?.call(callType, callId), | ||
[callType, callId, client], | ||
); | ||
|
||
useEffect(() => { | ||
if (!call) { | ||
return; | ||
} | ||
call.join().catch((e) => { | ||
console.error('Failed to join call', e); | ||
}); | ||
return () => { | ||
call.leave().catch((e) => { | ||
console.error('Failed to leave call', e); | ||
}); | ||
}; | ||
}, [call]); | ||
|
||
if (!call) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<StreamCall call={call}> | ||
<ViewerLivestream /> | ||
</StreamCall> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/react-native-sdk/src/components/Livestream/LivestreamPlayer/index.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './LivestreamPlayer'; |