Skip to content

Commit 1558f06

Browse files
authored
fix: accept children in LivestreamPlayer components (#1968)
Allows integrators to provide `children` components to our `LivestreamPlayer` components to allow easier extension and more convenient access to the underlying `call` instance. e.g.: ```tsx <LivestreamPlayer callType="livestream" callId="123"> <MyComponent /> </LivestreamPlayer> const MyComponent = () => { // will have access to the `call` instance created by the player const call = useCall(); // do stuff }; ```
1 parent b96de03 commit 1558f06

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

packages/react-native-sdk/src/components/Livestream/LivestreamPlayer/LivestreamPlayer.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { PropsWithChildren, useEffect, useState } from 'react';
22
import {
33
ViewerLivestream as DefaultViewerLivestream,
44
type ViewerLivestreamProps,
@@ -27,7 +27,7 @@ export type LivestreamPlayerProps = {
2727
*
2828
* `"asap"` behavior means joining the call as soon as it is possible
2929
* (either the `join_ahead_time_seconds` setting allows it, or the user
30-
* has a the capability to join backstage).
30+
* has the capability to join backstage).
3131
*
3232
* `"live"` behavior means joining the call when it goes live.
3333
*
@@ -41,7 +41,8 @@ export const LivestreamPlayer = ({
4141
callId,
4242
ViewerLivestream = DefaultViewerLivestream,
4343
joinBehavior = 'asap',
44-
}: LivestreamPlayerProps) => {
44+
children,
45+
}: PropsWithChildren<LivestreamPlayerProps>) => {
4546
const client = useStreamVideoClient();
4647

4748
const [call, setCall] = useState<Call>();
@@ -82,6 +83,7 @@ export const LivestreamPlayer = ({
8283
return (
8384
<StreamCall call={call}>
8485
<ViewerLivestream joinBehavior={joinBehavior} />
86+
{children}
8587
</StreamCall>
8688
);
8789
};

packages/react-sdk/src/wrappers/LivestreamPlayer/LivestreamPlayer.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { useEffect, useState } from 'react';
1+
import { PropsWithChildren, useEffect, useState } from 'react';
22
import { Call, CallingState } from '@stream-io/video-client';
33
import {
44
useCall,
55
useCallStateHooks,
6+
useEffectEvent,
67
useStreamVideoClient,
78
} from '@stream-io/video-react-bindings';
89
import {
@@ -12,7 +13,6 @@ import {
1213
LivestreamLayoutProps,
1314
StreamCall,
1415
} from '../../core';
15-
import { useEffectEvent } from '@stream-io/video-react-bindings';
1616

1717
export type LivestreamPlayerProps = {
1818
/**
@@ -28,7 +28,7 @@ export type LivestreamPlayerProps = {
2828
*
2929
* `"asap"` behavior means joining the call as soon as it is possible
3030
* (either the `join_ahead_time_seconds` setting allows it, or the user
31-
* has a the capability to join backstage).
31+
* has the capability to join backstage).
3232
*
3333
* `"live"` behavior means joining the call when it goes live.
3434
*
@@ -49,8 +49,10 @@ export type LivestreamPlayerProps = {
4949
onError?: (error: any) => void;
5050
};
5151

52-
export const LivestreamPlayer = (props: LivestreamPlayerProps) => {
53-
const { callType, callId, ...restProps } = props;
52+
export const LivestreamPlayer = (
53+
props: PropsWithChildren<LivestreamPlayerProps>,
54+
) => {
55+
const { callType, callId, children, ...restProps } = props;
5456
const client = useStreamVideoClient();
5557
const [call, setCall] = useState<Call>();
5658
const onError = useEffectEvent(props.onError ?? (() => {}));
@@ -78,6 +80,7 @@ export const LivestreamPlayer = (props: LivestreamPlayerProps) => {
7880
return (
7981
<StreamCall call={call}>
8082
<LivestreamCall {...restProps} />
83+
{children}
8184
</StreamCall>
8285
);
8386
};

0 commit comments

Comments
 (0)