1- import { DailyCall , DailyEventObject } from '@daily-co/daily-js' ;
1+ import {
2+ DailyCall ,
3+ DailyEventObject ,
4+ DailyEventObjectNonFatalError ,
5+ } from '@daily-co/daily-js' ;
26import { useCallback } from 'react' ;
37import { useRecoilValue } from 'recoil' ;
48
59import { liveStreamingState } from '../DailyLiveStreaming' ;
10+ import { Reconstruct } from '../types/Reconstruct' ;
611import { useDaily } from './useDaily' ;
712import { useDailyEvent } from './useDailyEvent' ;
813
14+ type DailyEventObjectLiveStreamingWarning = Reconstruct <
15+ DailyEventObjectNonFatalError ,
16+ 'type' ,
17+ 'live-streaming-warning'
18+ > ;
19+
920interface UseLiveStreamingArgs {
1021 onLiveStreamingStarted ?( ev : DailyEventObject < 'live-streaming-started' > ) : void ;
1122 onLiveStreamingStopped ?( ev : DailyEventObject < 'live-streaming-stopped' > ) : void ;
1223 onLiveStreamingUpdated ?( ev : DailyEventObject < 'live-streaming-updated' > ) : void ;
1324 onLiveStreamingError ?( ev : DailyEventObject < 'live-streaming-error' > ) : void ;
25+ onLiveStreamingWarning ?( ev : DailyEventObjectLiveStreamingWarning ) : void ;
1426}
1527
1628/**
@@ -24,6 +36,7 @@ export const useLiveStreaming = ({
2436 onLiveStreamingStarted,
2537 onLiveStreamingStopped,
2638 onLiveStreamingUpdated,
39+ onLiveStreamingWarning,
2740} : UseLiveStreamingArgs = { } ) => {
2841 const daily = useDaily ( ) ;
2942 const state = useRecoilValue ( liveStreamingState ) ;
@@ -37,7 +50,6 @@ export const useLiveStreaming = ({
3750 [ onLiveStreamingStarted ]
3851 )
3952 ) ;
40-
4153 useDailyEvent (
4254 'live-streaming-stopped' ,
4355 useCallback (
@@ -47,7 +59,6 @@ export const useLiveStreaming = ({
4759 [ onLiveStreamingStopped ]
4860 )
4961 ) ;
50-
5162 useDailyEvent (
5263 'live-streaming-updated' ,
5364 useCallback (
@@ -57,7 +68,6 @@ export const useLiveStreaming = ({
5768 [ onLiveStreamingUpdated ]
5869 )
5970 ) ;
60-
6171 useDailyEvent (
6272 'live-streaming-error' ,
6373 useCallback (
@@ -67,6 +77,16 @@ export const useLiveStreaming = ({
6777 [ onLiveStreamingError ]
6878 )
6979 ) ;
80+ useDailyEvent (
81+ 'nonfatal-error' ,
82+ useCallback (
83+ ( ev ) => {
84+ if ( ev . type !== 'live-streaming-warning' ) return ;
85+ onLiveStreamingWarning ?.( ev as DailyEventObjectLiveStreamingWarning ) ;
86+ } ,
87+ [ onLiveStreamingWarning ]
88+ )
89+ ) ;
7090
7191 const startLiveStreaming = useCallback (
7292 ( ...args : Parameters < DailyCall [ 'startLiveStreaming' ] > ) => {
0 commit comments