@@ -14,11 +14,14 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- import { useCallback , useEffect , useState } from "react" ;
17+ import { useCallback , useEffect , useReducer , useState } from "react" ;
1818import {
1919 GroupCallEvent ,
2020 GroupCallState ,
2121 GroupCall ,
22+ GroupCallErrorCode ,
23+ GroupCallUnknownDeviceError ,
24+ GroupCallError ,
2225} from "matrix-js-sdk/src/webrtc/groupCall" ;
2326import { MatrixCall } from "matrix-js-sdk/src/webrtc/call" ;
2427import { CallFeed } from "matrix-js-sdk/src/webrtc/callFeed" ;
@@ -48,6 +51,7 @@ export interface UseGroupCallType {
4851 localDesktopCapturerSourceId : string ;
4952 participants : RoomMember [ ] ;
5053 hasLocalParticipant : boolean ;
54+ unencryptedEventsFromUsers : Set < string > ;
5155}
5256
5357interface State {
@@ -106,6 +110,13 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallType {
106110 hasLocalParticipant : false ,
107111 } ) ;
108112
113+ const [ unencryptedEventsFromUsers , addUnencryptedEventUser ] = useReducer (
114+ ( state : Set < string > , newVal : string ) => {
115+ return new Set ( state ) . add ( newVal ) ;
116+ } ,
117+ new Set < string > ( )
118+ ) ;
119+
109120 const updateState = ( state : Partial < State > ) =>
110121 setState ( ( prevState ) => ( { ...prevState , ...state } ) ) ;
111122
@@ -180,6 +191,13 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallType {
180191 } ) ;
181192 }
182193
194+ function onError ( e : GroupCallError ) : void {
195+ if ( e . code === GroupCallErrorCode . UnknownDevice ) {
196+ const unknownDeviceError = e as GroupCallUnknownDeviceError ;
197+ addUnencryptedEventUser ( unknownDeviceError . userId ) ;
198+ }
199+ }
200+
183201 groupCall . on ( GroupCallEvent . GroupCallStateChanged , onGroupCallStateChanged ) ;
184202 groupCall . on ( GroupCallEvent . UserMediaFeedsChanged , onUserMediaFeedsChanged ) ;
185203 groupCall . on (
@@ -194,6 +212,7 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallType {
194212 ) ;
195213 groupCall . on ( GroupCallEvent . CallsChanged , onCallsChanged ) ;
196214 groupCall . on ( GroupCallEvent . ParticipantsChanged , onParticipantsChanged ) ;
215+ groupCall . on ( GroupCallEvent . Error , onError ) ;
197216
198217 updateState ( {
199218 error : null ,
@@ -242,6 +261,7 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallType {
242261 GroupCallEvent . ParticipantsChanged ,
243262 onParticipantsChanged
244263 ) ;
264+ groupCall . removeListener ( GroupCallEvent . Error , onError ) ;
245265 groupCall . leave ( ) ;
246266 } ;
247267 } , [ groupCall ] ) ;
@@ -319,5 +339,6 @@ export function useGroupCall(groupCall: GroupCall): UseGroupCallType {
319339 localDesktopCapturerSourceId,
320340 participants,
321341 hasLocalParticipant,
342+ unencryptedEventsFromUsers,
322343 } ;
323344}
0 commit comments