Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(external-api) add function and event to check p2p status (#13406)

Mihaela Dumitrue95a31c1140a
diff --git a/modules/API/API.js b/modules/API/API.js
index 43117d78f8..3d51c4f368 100644
--- a/modules/API/API.js
+++ b/modules/API/API.js
@@ -22,7 +22,7 @@ import {
setPassword,
setSubject
} from '../../react/features/base/conference/actions';
-import { getCurrentConference } from '../../react/features/base/conference/functions';
+import { getCurrentConference, isP2pActive } from '../../react/features/base/conference/functions';
import { overwriteConfig } from '../../react/features/base/config/actions';
import { getWhitelistedJSON } from '../../react/features/base/config/functions.any';
import { toggleDialog } from '../../react/features/base/dialog/actions';
@@ -987,6 +987,10 @@ function initCommands() {
callback(getRoomsInfo(APP.store.getState()));
break;
}
+ case 'get-p2p-status': {
+ callback(isP2pActive(APP.store.getState()));
+ break;
+ }
default:
return false;
}
@@ -2029,6 +2033,19 @@ class API {
});
}
+ /**
+ * Notify the external application (if API is enabled) if the connection type changed.
+ *
+ * @param {boolean} isP2p - Whether the new connection is P2P.
+ * @returns {void}
+ */
+ notifyP2pStatusChanged(isP2p) {
+ this._sendEvent({
+ name: 'p2p-status-changed',
+ isP2p
+ });
+ }
+
/**
* Disposes the allocated resources.
*
diff --git a/modules/API/external/external_api.js b/modules/API/external/external_api.js
index 9b0b71a35e..9e6fcf85f2 100644
--- a/modules/API/external/external_api.js
+++ b/modules/API/external/external_api.js
@@ -130,6 +130,7 @@ const events = {
'mouse-move': 'mouseMove',
'notification-triggered': 'notificationTriggered',
'outgoing-message': 'outgoingMessage',
+ 'p2p-status-changed': 'p2pStatusChanged',
'participant-joined': 'participantJoined',
'participant-kicked-out': 'participantKickedOut',
'participant-left': 'participantLeft',
@@ -693,7 +694,6 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
this._numberOfParticipants = allParticipants;
}
-
/**
* Returns the rooms info in the conference.
*
@@ -705,6 +705,17 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
});
}
+ /**
+ * Returns whether the conference is P2P.
+ *
+ * @returns {Promise}
+ */
+ isP2pActive() {
+ return this._transport.sendRequest({
+ name: 'get-p2p-status'
+ });
+ }
+
/**
* Adds event listener to Meet Jitsi.
*
diff --git a/react/features/base/conference/functions.ts b/react/features/base/conference/functions.ts
index 9c9cacf87f..0b925b9ee3 100644
--- a/react/features/base/conference/functions.ts
+++ b/react/features/base/conference/functions.ts
@@ -388,6 +388,24 @@ export function getCurrentConference(stateful: IStateful): IJitsiConference | un
return joining || passwordRequired || membersOnly;
}
+/**
+ * Returns whether the current conference is a P2P connection.
+ * Will return `false` if it's a JVB one, and `null` if there is no conference.
+ *
+ * @param {IStateful} stateful - The redux store, state, or
+ * {@code getState} function.
+ * @returns {boolean|null}
+ */
+export function isP2pActive(stateful: IStateful): boolean | null {
+ const conference = getCurrentConference(toState(stateful));
+
+ if (!conference) {
+ return null;
+ }
+
+ return conference.isP2PActive();
+}
+
/**
* Returns the stored room name.
*
diff --git a/react/features/base/conference/middleware.any.ts b/react/features/base/conference/middleware.any.ts
index bfbb089ac4..3297283ced 100644
--- a/react/features/base/conference/middleware.any.ts
+++ b/react/features/base/conference/middleware.any.ts
@@ -37,6 +37,7 @@ import {
CONFERENCE_JOINED,
CONFERENCE_SUBJECT_CHANGED,
CONFERENCE_WILL_LEAVE,
+ P2P_STATUS_CHANGED,
SEND_TONES,
SET_PENDING_SUBJECT_CHANGE,
SET_ROOM
@@ -111,6 +112,9 @@ MiddlewareRegistry.register(store => next => action => {
case TRACK_ADDED:
case TRACK_REMOVED:
return _trackAddedOrRemoved(store, next, action);
+
+ case P2P_STATUS_CHANGED:
+ return _p2pStatusChanged(next, action);
}
return next(action);
@@ -665,3 +669,24 @@ function _updateLocalParticipantInConference({ dispatch, getState }: IStore, nex
return result;
}
+
+/**
+ * Notifies the external API that the action {@code P2P_STATUS_CHANGED}
+ * is being dispatched within a specific redux store.
+ *
+ * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
+ * specified {@code action} to the specified {@code store}.
+ * @param {Action} action - The redux action {@code P2P_STATUS_CHANGED}
+ * which is being dispatched in the specified {@code store}.
+ * @private
+ * @returns {Object} The value returned by {@code next(action)}.
+ */
+function _p2pStatusChanged(next: Function, action: AnyAction) {
+ const result = next(action);
+
+ if (typeof APP !== 'undefined') {
+ APP.API.notifyP2pStatusChanged(action.p2p);
+ }
+
+ return result;
+}
diff --git a/react/features/base/conference/reducer.ts b/react/features/base/conference/reducer.ts
index f71e257d9e..5f319e079b 100644
--- a/react/features/base/conference/reducer.ts
+++ b/react/features/base/conference/reducer.ts
@@ -75,6 +75,7 @@ export interface IJitsiConference {
isE2EESupported: Function;
isEndConferenceSupported: Function;
isLobbySupported: Function;
+ isP2PActive: Function;
isSIPCallingSupported: Function;
isStartAudioMuted: Function;
isStartVideoMuted: Function;