mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
introduce error boundary in call member
This commit is contained in:
parent
f0d2c19184
commit
b1687d7115
@ -19,6 +19,7 @@ import {makeTxnId, makeId} from "../../common";
|
|||||||
import {EventType, CallErrorCode} from "../callEventTypes";
|
import {EventType, CallErrorCode} from "../callEventTypes";
|
||||||
import {formatToDeviceMessagesPayload} from "../../common";
|
import {formatToDeviceMessagesPayload} from "../../common";
|
||||||
import {sortedIndex} from "../../../utils/sortedIndex";
|
import {sortedIndex} from "../../../utils/sortedIndex";
|
||||||
|
import { ErrorBoundary } from "../../../utils/ErrorBoundary";
|
||||||
|
|
||||||
import type {MuteSettings} from "../common";
|
import type {MuteSettings} from "../common";
|
||||||
import type {Options as PeerCallOptions, RemoteMedia} from "../PeerCall";
|
import type {Options as PeerCallOptions, RemoteMedia} from "../PeerCall";
|
||||||
@ -94,6 +95,9 @@ class MemberConnection {
|
|||||||
export class Member {
|
export class Member {
|
||||||
private connection?: MemberConnection;
|
private connection?: MemberConnection;
|
||||||
private expireTimeout?: Timeout;
|
private expireTimeout?: Timeout;
|
||||||
|
private errorBoundary = new ErrorBoundary(err => {
|
||||||
|
this.options.emitUpdate(this, "error");
|
||||||
|
});
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public member: RoomMember,
|
public member: RoomMember,
|
||||||
@ -104,6 +108,10 @@ export class Member {
|
|||||||
this._renewExpireTimeout(updateMemberLog);
|
this._renewExpireTimeout(updateMemberLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get error(): Error | undefined {
|
||||||
|
return this.errorBoundary.error;
|
||||||
|
}
|
||||||
|
|
||||||
private _renewExpireTimeout(log: ILogItem) {
|
private _renewExpireTimeout(log: ILogItem) {
|
||||||
this.expireTimeout?.dispose();
|
this.expireTimeout?.dispose();
|
||||||
this.expireTimeout = undefined;
|
this.expireTimeout = undefined;
|
||||||
@ -166,6 +174,7 @@ export class Member {
|
|||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
connect(localMedia: LocalMedia, localMuteSettings: MuteSettings, turnServer: BaseObservableValue<RTCIceServer>, memberLogItem: ILogItem): ILogItem | undefined {
|
connect(localMedia: LocalMedia, localMuteSettings: MuteSettings, turnServer: BaseObservableValue<RTCIceServer>, memberLogItem: ILogItem): ILogItem | undefined {
|
||||||
|
return this.errorBoundary.try(() => {
|
||||||
if (this.connection) {
|
if (this.connection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -177,12 +186,14 @@ export class Member {
|
|||||||
memberLogItem
|
memberLogItem
|
||||||
);
|
);
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
let connectLogItem;
|
let connectLogItem: ILogItem | undefined;
|
||||||
connection.logItem.wrap("connect", async log => {
|
connection.logItem.wrap("connect", async log => {
|
||||||
connectLogItem = log;
|
connectLogItem = log;
|
||||||
await this.callIfNeeded(log);
|
await this.callIfNeeded(log);
|
||||||
});
|
});
|
||||||
|
throw new Error("connect failed!");
|
||||||
return connectLogItem;
|
return connectLogItem;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private callIfNeeded(log: ILogItem): Promise<void> {
|
private callIfNeeded(log: ILogItem): Promise<void> {
|
||||||
@ -211,6 +222,7 @@ export class Member {
|
|||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
disconnect(hangup: boolean): ILogItem | undefined {
|
disconnect(hangup: boolean): ILogItem | undefined {
|
||||||
|
return this.errorBoundary.try(() => {
|
||||||
const {connection} = this;
|
const {connection} = this;
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
return;
|
return;
|
||||||
@ -226,15 +238,18 @@ export class Member {
|
|||||||
connection.dispose();
|
connection.dispose();
|
||||||
this.connection = undefined;
|
this.connection = undefined;
|
||||||
return disconnectLogItem;
|
return disconnectLogItem;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
updateCallInfo(callDeviceMembership: CallDeviceMembership, causeItem: ILogItem) {
|
updateCallInfo(callDeviceMembership: CallDeviceMembership, causeItem: ILogItem) {
|
||||||
|
this.errorBoundary.try(() => {
|
||||||
this.callDeviceMembership = callDeviceMembership;
|
this.callDeviceMembership = callDeviceMembership;
|
||||||
this._renewExpireTimeout(causeItem);
|
this._renewExpireTimeout(causeItem);
|
||||||
if (this.connection) {
|
if (this.connection) {
|
||||||
this.connection.logItem.refDetached(causeItem);
|
this.connection.logItem.refDetached(causeItem);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
@ -308,6 +323,7 @@ export class Member {
|
|||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
handleDeviceMessage(message: SignallingMessage<MGroupCallBase>, syncLog: ILogItem): void {
|
handleDeviceMessage(message: SignallingMessage<MGroupCallBase>, syncLog: ILogItem): void {
|
||||||
|
this.errorBoundary.try(() => {
|
||||||
const {connection} = this;
|
const {connection} = this;
|
||||||
if (connection) {
|
if (connection) {
|
||||||
const destSessionId = message.content.dest_session_id;
|
const destSessionId = message.content.dest_session_id;
|
||||||
@ -351,6 +367,7 @@ export class Member {
|
|||||||
} else {
|
} else {
|
||||||
syncLog.log({l: "member not connected", userId: this.userId, deviceId: this.deviceId});
|
syncLog.log({l: "member not connected", userId: this.userId, deviceId: this.deviceId});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private dequeueSignallingMessages(connection: MemberConnection, peerCall: PeerCall, newMessage: SignallingMessage<MGroupCallBase>, syncLog: ILogItem): boolean {
|
private dequeueSignallingMessages(connection: MemberConnection, peerCall: PeerCall, newMessage: SignallingMessage<MGroupCallBase>, syncLog: ILogItem): boolean {
|
||||||
@ -373,19 +390,23 @@ export class Member {
|
|||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
async setMedia(localMedia: LocalMedia, previousMedia: LocalMedia): Promise<void> {
|
async setMedia(localMedia: LocalMedia, previousMedia: LocalMedia): Promise<void> {
|
||||||
|
return this.errorBoundary.try(async () => {
|
||||||
const {connection} = this;
|
const {connection} = this;
|
||||||
if (connection) {
|
if (connection) {
|
||||||
connection.localMedia = localMedia.replaceClone(connection.localMedia, previousMedia);
|
connection.localMedia = localMedia.replaceClone(connection.localMedia, previousMedia);
|
||||||
await connection.peerCall?.setMedia(connection.localMedia, connection.logItem);
|
await connection.peerCall?.setMedia(connection.localMedia, connection.logItem);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async setMuted(muteSettings: MuteSettings): Promise<void> {
|
async setMuted(muteSettings: MuteSettings): Promise<void> {
|
||||||
|
return this.errorBoundary.try(async () => {
|
||||||
const {connection} = this;
|
const {connection} = this;
|
||||||
if (connection) {
|
if (connection) {
|
||||||
connection.localMuteSettings = muteSettings;
|
connection.localMuteSettings = muteSettings;
|
||||||
await connection.peerCall?.setMuted(muteSettings, connection.logItem);
|
await connection.peerCall?.setMuted(muteSettings, connection.logItem);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _createPeerCall(callId: string): PeerCall {
|
private _createPeerCall(callId: string): PeerCall {
|
||||||
|
Loading…
Reference in New Issue
Block a user