Add opponentMember hack and better debugging logs

This commit is contained in:
Robert Long 2021-07-23 16:11:42 -07:00
parent 53e86f9282
commit b527670c17

View file

@ -26,6 +26,11 @@ export class ConferenceCall extends EventEmitter {
} }
join() { join() {
console.debug(
"join",
`Local user ${this.client.getUserId()} joining room ${this.roomId}`
);
this.joined = true; this.joined = true;
const activeConf = this.room.currentState const activeConf = this.room.currentState
@ -67,71 +72,96 @@ export class ConferenceCall extends EventEmitter {
}; };
_onMemberChanged = (_event, _state, member) => { _onMemberChanged = (_event, _state, member) => {
if (!this.joined) {
console.debug("_onMemberChanged", member, "not joined");
return;
}
this._processMember(member.userId); this._processMember(member.userId);
}; };
_processMember(userId) { _processMember(userId) {
const localUserId = this.client.getUserId(); const localUserId = this.client.getUserId();
if (userId === localUserId || userId < localUserId) { if (userId === localUserId) {
return;
}
// Don't process members until we've joined
if (!this.joined) {
console.debug(
"_processMember",
`Ignored ${userId}. Local user has not joined conference yet.`
);
return;
}
// Only initiate a call with a user who has a userId that is lexicographically
// less than your own. Otherwise, that user will call you.
if (userId < localUserId) {
console.debug(
"_processMember",
`Ignored ${userId}. Local user will answer call instead.`
);
return; return;
} }
const participant = this.participants.find((p) => p.userId === userId); const participant = this.participants.find((p) => p.userId === userId);
if (participant) {
// Member has already been processed
return;
}
const memberStateEvent = this.room.currentState.getStateEvents( const memberStateEvent = this.room.currentState.getStateEvents(
"m.room.member", "m.room.member",
userId userId
); );
const participantTimeout = memberStateEvent.getContent()[CONF_PARTICIPANT]; const participantTimeout = memberStateEvent.getContent()[CONF_PARTICIPANT];
console.debug(
"_processMember",
new Date().getTime() - participantTimeout > PARTICIPANT_TIMEOUT
);
if ( if (
typeof participantTimeout === "number" && typeof participantTimeout === "number" &&
new Date().getTime() - participantTimeout > PARTICIPANT_TIMEOUT new Date().getTime() - participantTimeout > PARTICIPANT_TIMEOUT
) { ) {
// if (participant && participant.call) { // Member is inactive so don't call them.
// participant.call.hangup("user_hangup"); console.debug(
// } "_processMember",
`Ignored ${userId}. User is not active in conference.`
);
return; return;
} }
if (!participant) { const call = this.client.createCall(this.roomId, userId);
this._callUser(userId); this._addCall(call, userId);
} console.debug(
"_processMember",
`Placing video call ${call.callId} to ${userId}.`
);
call.placeVideoCall();
} }
_onIncomingCall = (call) => { _onIncomingCall = (call) => {
if (!this.joined) { if (!this.joined) {
console.debug( console.debug(
"_onIncomingCall", "_onIncomingCall",
"Member hasn't joined yet. Not answering." "Local user hasn't joined yet. Not answering."
); );
//call.hangup();
return; return;
} }
console.debug("_onIncomingCall", call); // HACK: Horrible hack only necessary because Call.incoming sets opponentMember
this._addCall(call); // inside an async function.
call.answer(); const pollOpponentMember = () => {
}; if (call.opponentMember) {
const userId = call.opponentMember.userId;
this._addCall(call, userId);
console.debug(
"_onIncomingCall",
`Answering incoming call ${call.callId} from ${userId}`
);
call.answer();
return;
}
_callUser = (userId) => { setTimeout(pollOpponentMember, 100);
const call = this.client.createCall(this.roomId, userId); };
console.debug("_callUser", call, userId);
// TODO: Handle errors pollOpponentMember();
this._addCall(call, userId);
call.placeVideoCall();
}; };
_addCall(call, userId) { _addCall(call, userId) {
@ -140,7 +170,10 @@ export class ConferenceCall extends EventEmitter {
); );
if (existingCall) { if (existingCall) {
console.debug("found existing call"); console.debug(
"_addCall",
`Found existing call ${call.callId}. Ignoring.`
);
return; return;
} }
@ -151,6 +184,8 @@ export class ConferenceCall extends EventEmitter {
calls: [call], calls: [call],
}); });
console.debug("_addCall", `Added new participant ${userId}`);
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));
@ -166,7 +201,6 @@ export class ConferenceCall extends EventEmitter {
} }
_onCallFeedsChanged = (call) => { _onCallFeedsChanged = (call) => {
console.debug("_onCallFeedsChanged", call);
const localFeeds = call.getLocalFeeds(); const localFeeds = call.getLocalFeeds();
let participantsChanged = false; let participantsChanged = false;
@ -190,10 +224,9 @@ export class ConferenceCall extends EventEmitter {
}; };
_onCallHangup = (call) => { _onCallHangup = (call) => {
console.debug("_onCallHangup", call); console.debug("_onCallHangup", `Hangup reason ${call.hangupReason}`);
if (call.hangupReason === "replaced") { if (call.hangupReason === "replaced") {
console.debug("replaced");
return; return;
} }
@ -211,7 +244,10 @@ export class ConferenceCall extends EventEmitter {
}; };
_onCallReplaced = (call, newCall) => { _onCallReplaced = (call, newCall) => {
console.debug("_onCallReplaced", call, newCall); console.debug(
"_onCallReplaced",
`Call ${call.callId} replaced with ${newCall.callId}`
);
const remoteParticipant = this.participants.find((p) => p.call === call); const remoteParticipant = this.participants.find((p) => p.call === call);