@@ -105,28 +105,25 @@ const reducer = (
105105 reducerState : SessionState ,
106106 action :
107107 | {
108- type : 'toggleWidget' | 'selectPeer' | 'instance_updated' | 'reset' | 'mute' | 'hold' ;
109- payload ?: Partial < SessionState > ;
108+ type : 'reset' ;
109+ }
110+ | {
111+ type : 'selectPeer' ;
112+ payload : { peerInfo ?: PeerInfo } ;
113+ }
114+ | {
115+ type : 'toggleWidget' ;
116+ payload : { peerInfo ?: PeerInfo } ;
117+ }
118+ | {
119+ type : 'instance_updated' ;
120+ payload : SessionState ;
110121 }
111122 | {
112123 type : 'status_updated' ;
113124 payload ?: { status ?: UserStatus } ;
114125 } ,
115126) : SessionState => {
116- if ( action . type === 'mute' ) {
117- return {
118- ...reducerState ,
119- muted : action . payload ?. muted ?? reducerState . muted ,
120- } ;
121- }
122-
123- if ( action . type === 'hold' ) {
124- return {
125- ...reducerState ,
126- held : action . payload ?. held ?? reducerState . held ,
127- } ;
128- }
129-
130127 if ( action . type === 'toggleWidget' ) {
131128 if ( reducerState . state === 'closed' ) {
132129 return { ...reducerState , state : 'new' , peerInfo : action . payload ?. peerInfo } ;
@@ -138,7 +135,7 @@ const reducer = (
138135 }
139136
140137 if ( action . type === 'instance_updated' ) {
141- return { ...reducerState , ...action . payload } as SessionState ;
138+ return { ...reducerState , ...action . payload } ;
142139 }
143140
144141 if ( action . type === 'selectPeer' ) {
@@ -198,6 +195,12 @@ export const useMediaSession = (instance?: MediaSignalingSession): MediaSessionS
198195 callId,
199196 } = mainCall ;
200197 const state = deriveWidgetStateFromCallState ( callState , role ) ;
198+
199+ if ( ! state ) {
200+ dispatch ( { type : 'reset' } ) ;
201+ return ;
202+ }
203+
201204 const connectionState = deriveConnectionStateFromCallState ( callState ) ;
202205
203206 const transferredBy = callTransferredBy ?. displayName || callTransferredBy ?. username || undefined ;
0 commit comments