Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/lib/services/voip/MediaSessionInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { mediaSessionStore } from './MediaSessionStore';
import { useCallStore } from './useCallStore';
import { store } from '../../store/auxStore';
import sdk from '../sdk';
import { mediaCallsStateSignals } from '../restApi';
import Navigation from '../../navigation/appNavigation';
import { parseStringToIceServers } from './parseStringToIceServers';
import type { IceServer } from '../../../definitions/Voip';
Expand All @@ -24,7 +25,6 @@ import type { ISubscription, TSubscriptionModel } from '../../../definitions';
import { getDMSubscriptionByUsername } from '../../database/services/Subscription';
import { getUidDirectMessage } from '../../methods/helpers/helpers';
import { requestPhoneStatePermission } from '../../methods/voipPhoneStatePermission';
import { mediaCallsStateSignals } from '../restApi';

class MediaSessionInstance {
private iceServers: IceServer[] = [];
Expand Down Expand Up @@ -80,6 +80,7 @@ class MediaSessionInstance {
iceGatheringTimeout: this.iceGatheringTimeout
})
);
// TESTING: DDP signal transport — offer/answer/ICE stay on DDP
mediaSessionStore.setSendSignalFn((signal: ClientMediaSignal) => {
sdk.methodCall('stream-notify-user', `${userId}/media-calls`, JSON.stringify(signal));
});
Expand All @@ -95,6 +96,7 @@ class MediaSessionInstance {
this.instance = mediaSessionStore.getInstance(userId);
});

// TESTING: DDP real-time signal subscription — stays for offer/answer/ICE/notifications
this.mediaSignalListener = sdk.onStreamData('stream-notify-user', (ddpMessage: IDDPMessage) => {
if (!this.instance) {
return;
Expand Down
50 changes: 42 additions & 8 deletions app/sagas/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import { showActionSheetRef } from '../containers/ActionSheet';
import { SupportedVersionsWarning } from '../containers/SupportedVersions';
import { mediaSessionInstance } from '../lib/services/voip/MediaSessionInstance';
import { hasPermission } from '../lib/methods/helpers/helpers';
import { mediaSessionStore } from '../lib/services/voip/MediaSessionStore';
import { store as reduxStore } from '../lib/store/auxStore';

const getServer = state => state.server.server;
const loginWithPasswordCall = args => loginWithPassword(args);
Expand Down Expand Up @@ -242,23 +244,53 @@ const checkBackgroundAndSetAway = function* checkBackgroundAndSetAway() {
}
};

const startVoipFork = function* startVoipFork() {
const checkVoipPermission = async () => {
try {
const allowInternalVoiceCallRoles = yield select(state => state.permissions['allow-internal-voice-calls']);
const allowExternalVoiceCallRoles = yield select(state => state.permissions['allow-external-voice-calls']);
const state = reduxStore.getState();
const userId = state.login.user?.id;
if (!userId) {
return;
}

const hasPermissions = yield hasPermission([allowInternalVoiceCallRoles, allowExternalVoiceCallRoles]);
if (isVoipModuleAvailable() && (hasPermissions[0] || hasPermissions[1])) {
const userId = yield select(state => state.login.user.id);
mediaSessionInstance.init(userId);
} else {
const hasPermissions = await hasPermission([
state.permissions['allow-internal-voice-calls'],
state.permissions['allow-external-voice-calls']
]);
const canUseVoip = isVoipModuleAvailable() && (hasPermissions[0] || hasPermissions[1]);

if (!canUseVoip) {
mediaSessionInstance.reset();
return;
}
if (!mediaSessionStore.getCurrentInstance()) {
mediaSessionInstance.init(userId);
}
} catch (e) {
log(e);
}
};

let voipPermissionListener;

const stopVoipPermissionListener = () => {
if (voipPermissionListener) {
voipPermissionListener.stop();
voipPermissionListener = null;
}
};
Comment thread
diegolmello marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

const startVoipFork = function* startVoipFork() {
yield call(checkVoipPermission);

stopVoipPermissionListener();
voipPermissionListener = sdk.current.onStreamData('stream-notify-logged', async ddpMessage => {
const { eventName } = ddpMessage.fields || {};
if (/permissions-changed/.test(eventName)) {
await checkVoipPermission();
}
});
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

const handleLoginSuccess = function* handleLoginSuccess({ user }) {
try {
yield put(setUser(user));
Expand Down Expand Up @@ -331,6 +363,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {
};

const handleLogout = function* handleLogout({ forcedByServer, message }) {
stopVoipPermissionListener();
yield put(encryptionStop());
yield put(appStart({ root: RootEnum.ROOT_LOADING, text: I18n.t('Logging_out') }));
const server = yield select(getServer);
Expand Down Expand Up @@ -407,6 +440,7 @@ const handleSetUser = function* handleSetUser({ user }) {
};

const handleDeleteAccount = function* handleDeleteAccount() {
stopVoipPermissionListener();
yield put(encryptionStop());
yield put(appStart({ root: RootEnum.ROOT_LOADING, text: I18n.t('Deleting_account') }));
const server = yield select(getServer);
Expand Down
Loading