Add better leave call behavior
This commit is contained in:
parent
d040a7b733
commit
802a08987d
2 changed files with 30 additions and 0 deletions
|
@ -406,6 +406,22 @@ export class ConferenceCallManager extends EventEmitter {
|
||||||
};
|
};
|
||||||
|
|
||||||
leaveCall() {
|
leaveCall() {
|
||||||
|
const userId = this.client.getUserId();
|
||||||
|
const currentMemberState = this.room.currentState.getStateEvents(
|
||||||
|
"m.room.member",
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
|
||||||
|
this.client.sendStateEvent(
|
||||||
|
this.roomId,
|
||||||
|
"m.room.member",
|
||||||
|
{
|
||||||
|
...currentMemberState.getContent(),
|
||||||
|
[CONF_PARTICIPANT]: null,
|
||||||
|
},
|
||||||
|
userId
|
||||||
|
);
|
||||||
|
|
||||||
for (const participant of this.participants) {
|
for (const participant of this.participants) {
|
||||||
if (!participant.local && participant.call) {
|
if (!participant.local && participant.call) {
|
||||||
participant.call.hangup("user_hangup", false);
|
participant.call.hangup("user_hangup", false);
|
||||||
|
@ -416,6 +432,7 @@ export class ConferenceCallManager extends EventEmitter {
|
||||||
this.participants = [this.localParticipant];
|
this.participants = [this.localParticipant];
|
||||||
this.localParticipant.feed = null;
|
this.localParticipant.feed = null;
|
||||||
this.localParticipant.call = null;
|
this.localParticipant.call = null;
|
||||||
|
|
||||||
this.emit("participants_changed");
|
this.emit("participants_changed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,6 +116,18 @@ export function useVideoRoom(manager, roomId, timeout = 5000) {
|
||||||
error: undefined,
|
error: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
function onBeforeUnload(event) {
|
||||||
|
manager.leaveCall();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("beforeunload", onBeforeUnload);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("beforeunload", onBeforeUnload);
|
||||||
|
};
|
||||||
|
}, [manager]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setState((prevState) => ({
|
setState((prevState) => ({
|
||||||
...prevState,
|
...prevState,
|
||||||
|
@ -169,6 +181,7 @@ export function useVideoRoom(manager, roomId, timeout = 5000) {
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
manager.client.removeListener("Room", roomCallback);
|
manager.client.removeListener("Room", roomCallback);
|
||||||
|
manager.leaveCall();
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
};
|
};
|
||||||
}, [roomId]);
|
}, [roomId]);
|
||||||
|
|
Loading…
Reference in a new issue