Improve debugging and fix a few bugs
This commit is contained in:
parent
a005b22787
commit
ade6c19eba
2 changed files with 47 additions and 46 deletions
|
@ -143,6 +143,7 @@ export class ConferenceCallManager extends EventEmitter {
|
||||||
};
|
};
|
||||||
this.participants = [this.localParticipant];
|
this.participants = [this.localParticipant];
|
||||||
this.pendingCalls = [];
|
this.pendingCalls = [];
|
||||||
|
this.callUserMap = new Map();
|
||||||
this.debugState = new Map();
|
this.debugState = new Map();
|
||||||
this._setDebugState(client.getUserId(), "you");
|
this._setDebugState(client.getUserId(), "you");
|
||||||
this.client.on("event", this._onEvent);
|
this.client.on("event", this._onEvent);
|
||||||
|
@ -184,11 +185,19 @@ export class ConferenceCallManager extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
_onEvent = (event) => {
|
_onEvent = (event) => {
|
||||||
|
const roomId = event.getRoomId();
|
||||||
const type = event.getType();
|
const type = event.getType();
|
||||||
|
|
||||||
if (type.startsWith("m.call.") || type.startsWith("me.robertlong.conf")) {
|
if (type.startsWith("m.call.") || type.startsWith("me.robertlong.conf")) {
|
||||||
const content = event.getContent();
|
const content = event.getContent();
|
||||||
const details = { content };
|
const details = { content: event.toJSON(), roomId };
|
||||||
|
|
||||||
|
if (content.invitee && content.call_id) {
|
||||||
|
this.callUserMap.set(content.call_id, content.invitee);
|
||||||
|
details.to = content.invitee;
|
||||||
|
} else if (content.call_id) {
|
||||||
|
details.to = this.callUserMap.get(content.call_id);
|
||||||
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "m.call.invite":
|
case "m.call.invite":
|
||||||
|
@ -257,7 +266,7 @@ export class ConferenceCallManager extends EventEmitter {
|
||||||
const participantTimeout = memberStateEvent.getContent()[CONF_PARTICIPANT];
|
const participantTimeout = memberStateEvent.getContent()[CONF_PARTICIPANT];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof participantTimeout === "number" &&
|
typeof participantTimeout !== "number" ||
|
||||||
new Date().getTime() - participantTimeout > PARTICIPANT_TIMEOUT
|
new Date().getTime() - participantTimeout > PARTICIPANT_TIMEOUT
|
||||||
) {
|
) {
|
||||||
// Member is inactive so don't call them.
|
// Member is inactive so don't call them.
|
||||||
|
@ -275,18 +284,10 @@ export class ConferenceCallManager extends EventEmitter {
|
||||||
const call = this.client.createCall(this.roomId, userId);
|
const call = this.client.createCall(this.roomId, userId);
|
||||||
this._addCall(call, userId);
|
this._addCall(call, userId);
|
||||||
this._setDebugState(userId, "calling");
|
this._setDebugState(userId, "calling");
|
||||||
this._addDebugEvent(this.client.getUserId(), "placeVideoCall", {
|
|
||||||
callId: call.callId,
|
|
||||||
to: userId,
|
|
||||||
});
|
|
||||||
call.placeVideoCall();
|
call.placeVideoCall();
|
||||||
}
|
}
|
||||||
|
|
||||||
_onIncomingCall = (call) => {
|
_onIncomingCall = (call) => {
|
||||||
this._addDebugEvent(call.opponentMember.userId, "incoming call", {
|
|
||||||
callId: call.callId,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!this.joined) {
|
if (!this.joined) {
|
||||||
const onHangup = (call) => {
|
const onHangup = (call) => {
|
||||||
const index = this.pendingCalls.findIndex((p) => p.call === call);
|
const index = this.pendingCalls.findIndex((p) => p.call === call);
|
||||||
|
@ -322,7 +323,6 @@ export class ConferenceCallManager extends EventEmitter {
|
||||||
const userId = call.opponentMember.userId;
|
const userId = call.opponentMember.userId;
|
||||||
this._addCall(call, userId);
|
this._addCall(call, userId);
|
||||||
this._setDebugState(userId, "answered");
|
this._setDebugState(userId, "answered");
|
||||||
this._addDebugEvent(userId, "answer", { callId: call.callId });
|
|
||||||
call.answer();
|
call.answer();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -346,7 +346,6 @@ export class ConferenceCallManager extends EventEmitter {
|
||||||
});
|
});
|
||||||
|
|
||||||
this._setDebugCallId(userId, call.callId);
|
this._setDebugCallId(userId, call.callId);
|
||||||
this._addDebugEvent(userId, "add participant");
|
|
||||||
|
|
||||||
call.on("feeds_changed", () => this._onCallFeedsChanged(call));
|
call.on("feeds_changed", () => this._onCallFeedsChanged(call));
|
||||||
call.on("hangup", () => this._onCallHangup(call));
|
call.on("hangup", () => this._onCallHangup(call));
|
||||||
|
@ -391,11 +390,6 @@ export class ConferenceCallManager extends EventEmitter {
|
||||||
};
|
};
|
||||||
|
|
||||||
_onCallHangup = (call) => {
|
_onCallHangup = (call) => {
|
||||||
this._addDebugEvent(call.opponentMember.userId, "hangup", {
|
|
||||||
callId: call.callId,
|
|
||||||
reason: call.hangupReason,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (call.hangupReason === "replaced") {
|
if (call.hangupReason === "replaced") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -463,6 +457,10 @@ export class ConferenceCallManager extends EventEmitter {
|
||||||
};
|
};
|
||||||
|
|
||||||
leaveCall() {
|
leaveCall() {
|
||||||
|
if (!this.joined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const userId = this.client.getUserId();
|
const userId = this.client.getUserId();
|
||||||
const currentMemberState = this.room.currentState.getStateEvents(
|
const currentMemberState = this.room.currentState.getStateEvents(
|
||||||
"m.room.member",
|
"m.room.member",
|
||||||
|
@ -503,7 +501,7 @@ export class ConferenceCallManager extends EventEmitter {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const { events } = this.debugState.get(sender);
|
const { events } = this.debugState.get(sender);
|
||||||
events.push({ type, ...content });
|
events.push({ type, roomId: this.roomId, ...content });
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emit("debug");
|
this.emit("debug");
|
||||||
|
|
|
@ -46,6 +46,7 @@ export function DevTools({ manager }) {
|
||||||
{Array.from(debugState.entries()).map(([userId, props]) => (
|
{Array.from(debugState.entries()).map(([userId, props]) => (
|
||||||
<UserState
|
<UserState
|
||||||
key={userId}
|
key={userId}
|
||||||
|
roomId={manager.roomId}
|
||||||
onSelectEvent={setSelectedEvent}
|
onSelectEvent={setSelectedEvent}
|
||||||
userId={userId}
|
userId={userId}
|
||||||
{...props}
|
{...props}
|
||||||
|
@ -61,7 +62,7 @@ export function DevTools({ manager }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function UserState({ userId, state, callId, events, onSelectEvent }) {
|
function UserState({ roomId, userId, state, callId, events, onSelectEvent }) {
|
||||||
const eventsRef = useRef();
|
const eventsRef = useRef();
|
||||||
const [autoScroll, setAutoScroll] = useState(true);
|
const [autoScroll, setAutoScroll] = useState(true);
|
||||||
|
|
||||||
|
@ -90,33 +91,35 @@ function UserState({ userId, state, callId, events, onSelectEvent }) {
|
||||||
{callId && <CallId callId={callId} />}
|
{callId && <CallId callId={callId} />}
|
||||||
</div>
|
</div>
|
||||||
<div ref={eventsRef} className={styles.events} onScroll={onScroll}>
|
<div ref={eventsRef} className={styles.events} onScroll={onScroll}>
|
||||||
{events.map((event, idx) => (
|
{events
|
||||||
<div
|
.filter((e) => e.roomId === roomId)
|
||||||
className={styles.event}
|
.map((event, idx) => (
|
||||||
key={idx}
|
<div
|
||||||
onClick={() => onSelectEvent(event)}
|
className={styles.event}
|
||||||
>
|
key={idx}
|
||||||
<span className={styles.eventType}>{event.type}</span>
|
onClick={() => onSelectEvent(event)}
|
||||||
{event.callId && (
|
>
|
||||||
<CallId className={styles.eventDetails} callId={event.callId} />
|
<span className={styles.eventType}>{event.type}</span>
|
||||||
)}
|
{event.callId && (
|
||||||
{event.newCallId && (
|
<CallId className={styles.eventDetails} callId={event.callId} />
|
||||||
<>
|
)}
|
||||||
<span className={styles.eventDetails}>{"->"}</span>
|
{event.newCallId && (
|
||||||
<CallId
|
<>
|
||||||
className={styles.eventDetails}
|
<span className={styles.eventDetails}>{"->"}</span>
|
||||||
callId={event.newCallId}
|
<CallId
|
||||||
/>
|
className={styles.eventDetails}
|
||||||
</>
|
callId={event.newCallId}
|
||||||
)}
|
/>
|
||||||
{event.to && (
|
</>
|
||||||
<UserId className={styles.eventDetails} userId={event.to} />
|
)}
|
||||||
)}
|
{event.to && (
|
||||||
{event.reason && (
|
<UserId className={styles.eventDetails} userId={event.to} />
|
||||||
<span className={styles.eventDetails}>{event.reason}</span>
|
)}
|
||||||
)}
|
{event.reason && (
|
||||||
</div>
|
<span className={styles.eventDetails}>{event.reason}</span>
|
||||||
))}
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue