Skip to content

Commit

Permalink
feat(Testing) Add testing options to force a P2P to be initiator/resp…
Browse files Browse the repository at this point in the history
…onder
  • Loading branch information
jallamsetty1 committed Jan 9, 2025
1 parent dc8b557 commit 7de7d9a
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions JitsiConference.js
Original file line number Diff line number Diff line change
Expand Up @@ -3379,40 +3379,41 @@ JitsiConference.prototype._maybeStartOrStopP2P = function(userLeftEvent) {
// Start peer to peer session
if (!this.p2pJingleSession && shouldBeInP2P) {
const peer = peerCount && peers[0];


const myId = this.myUserId();
const peersId = peer.getId();
const jid = peer.getJid();

if (myId > peersId) {
logger.debug(
'I\'m the bigger peersId - '
+ 'the other peer should start P2P', myId, peersId);

return;
} else if (myId === peersId) {
logger.error('The same IDs ? ', myId, peersId);
// Force initiator or responder mode for testing if option is passed to config.
if (this.options.config.testing?.forceInitiator) {
logger.debug(`Forcing P2P initiator, will start P2P with: ${jid}`);
this._startP2PSession(jid);
} else if (this.options.config.testing?.forceResponder) {
logger.debug(`Forcing P2P responder, will wait for the other peer ${jid} to start P2P`);
} else {
if (myId > peersId) {
logger.debug('I\'m the bigger peersId - the other peer should start P2P', myId, peersId);

return;
}
return;
} else if (myId === peersId) {
logger.error('The same IDs ? ', myId, peersId);

const jid = peer.getJid();
return;
}

if (userLeftEvent) {
if (this.deferredStartP2PTask) {
logger.error('Deferred start P2P task\'s been set already!');
if (userLeftEvent) {
if (this.deferredStartP2PTask) {
logger.error('Deferred start P2P task\'s been set already!');

return;
return;
}
logger.info(`Will start P2P with: ${jid} after ${this.backToP2PDelay} seconds...`);
this.deferredStartP2PTask = setTimeout(
this._startP2PSession.bind(this, jid),
this.backToP2PDelay * 1000);
} else {
logger.info(`Will start P2P with: ${jid}`);
this._startP2PSession(jid);
}
logger.info(
`Will start P2P with: ${jid} after ${
this.backToP2PDelay} seconds...`);
this.deferredStartP2PTask = setTimeout(
this._startP2PSession.bind(this, jid),
this.backToP2PDelay * 1000);
} else {
logger.info(`Will start P2P with: ${jid}`);
this._startP2PSession(jid);
}
} else if (this.p2pJingleSession && !shouldBeInP2P) {
logger.info(`Will stop P2P with: ${this.p2pJingleSession.remoteJid}`);
Expand Down

0 comments on commit 7de7d9a

Please sign in to comment.