@ethora/chat-component-rn 26.10.4 → 26.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/VideoCalls/ActiveCallBar.js +61 -16
- package/lib/commonjs/components/VideoCalls/ActiveCallBar.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/CallIcons.js +41 -16
- package/lib/commonjs/components/VideoCalls/CallIcons.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/VideoCallOverlay.js +183 -9
- package/lib/commonjs/components/VideoCalls/VideoCallOverlay.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/VideoCallSession.js +40 -15
- package/lib/commonjs/components/VideoCalls/VideoCallSession.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/callSessionController.js +49 -26
- package/lib/commonjs/components/VideoCalls/callSessionController.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/callUiStore.js +33 -4
- package/lib/commonjs/components/VideoCalls/callUiStore.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/livekitRuntime.js +9 -1
- package/lib/commonjs/components/VideoCalls/livekitRuntime.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/useCallKeep.js +197 -28
- package/lib/commonjs/components/VideoCalls/useCallKeep.js.map +1 -1
- package/lib/commonjs/components/VideoCalls/useOngoingCallNotification.js +88 -0
- package/lib/commonjs/components/VideoCalls/useOngoingCallNotification.js.map +1 -0
- package/lib/commonjs/components/VideoCalls/usePipTile.js +232 -0
- package/lib/commonjs/components/VideoCalls/usePipTile.js.map +1 -0
- package/lib/commonjs/helpers/updateMessagesTillLast.js +3 -1
- package/lib/commonjs/helpers/updateMessagesTillLast.js.map +1 -1
- package/lib/commonjs/i18n/strings.js +48 -0
- package/lib/commonjs/i18n/strings.js.map +1 -1
- package/lib/commonjs/main.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/components/VideoCalls/ActiveCallBar.js +63 -18
- package/lib/module/components/VideoCalls/ActiveCallBar.js.map +1 -1
- package/lib/module/components/VideoCalls/CallIcons.js +38 -15
- package/lib/module/components/VideoCalls/CallIcons.js.map +1 -1
- package/lib/module/components/VideoCalls/VideoCallOverlay.js +185 -11
- package/lib/module/components/VideoCalls/VideoCallOverlay.js.map +1 -1
- package/lib/module/components/VideoCalls/VideoCallSession.js +41 -16
- package/lib/module/components/VideoCalls/VideoCallSession.js.map +1 -1
- package/lib/module/components/VideoCalls/callSessionController.js +46 -24
- package/lib/module/components/VideoCalls/callSessionController.js.map +1 -1
- package/lib/module/components/VideoCalls/callUiStore.js +30 -3
- package/lib/module/components/VideoCalls/callUiStore.js.map +1 -1
- package/lib/module/components/VideoCalls/livekitRuntime.js +9 -1
- package/lib/module/components/VideoCalls/livekitRuntime.js.map +1 -1
- package/lib/module/components/VideoCalls/useCallKeep.js +198 -29
- package/lib/module/components/VideoCalls/useCallKeep.js.map +1 -1
- package/lib/module/components/VideoCalls/useOngoingCallNotification.js +84 -0
- package/lib/module/components/VideoCalls/useOngoingCallNotification.js.map +1 -0
- package/lib/module/components/VideoCalls/usePipTile.js +228 -0
- package/lib/module/components/VideoCalls/usePipTile.js.map +1 -0
- package/lib/module/helpers/updateMessagesTillLast.js +3 -1
- package/lib/module/helpers/updateMessagesTillLast.js.map +1 -1
- package/lib/module/i18n/strings.js +48 -0
- package/lib/module/i18n/strings.js.map +1 -1
- package/lib/module/main.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/components/VideoCalls/ActiveCallBar.d.ts +9 -3
- package/lib/typescript/components/VideoCalls/ActiveCallBar.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/CallIcons.d.ts +9 -0
- package/lib/typescript/components/VideoCalls/CallIcons.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/VideoCallOverlay.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/VideoCallSession.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/callSessionController.d.ts +7 -0
- package/lib/typescript/components/VideoCalls/callSessionController.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/callUiStore.d.ts +13 -0
- package/lib/typescript/components/VideoCalls/callUiStore.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/livekitRuntime.d.ts +5 -0
- package/lib/typescript/components/VideoCalls/livekitRuntime.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/useCallKeep.d.ts +12 -0
- package/lib/typescript/components/VideoCalls/useCallKeep.d.ts.map +1 -1
- package/lib/typescript/components/VideoCalls/useOngoingCallNotification.d.ts +10 -0
- package/lib/typescript/components/VideoCalls/useOngoingCallNotification.d.ts.map +1 -0
- package/lib/typescript/components/VideoCalls/usePipTile.d.ts +46 -0
- package/lib/typescript/components/VideoCalls/usePipTile.d.ts.map +1 -0
- package/lib/typescript/helpers/updateMessagesTillLast.d.ts.map +1 -1
- package/lib/typescript/i18n/strings.d.ts.map +1 -1
- package/lib/typescript/main.d.ts +1 -1
- package/lib/typescript/main.d.ts.map +1 -1
- package/lib/typescript/types/types.d.ts +40 -0
- package/lib/typescript/types/types.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/VideoCalls/ActiveCallBar.tsx +56 -10
- package/src/components/VideoCalls/CallIcons.tsx +36 -12
- package/src/components/VideoCalls/VideoCallOverlay.tsx +205 -8
- package/src/components/VideoCalls/VideoCallSession.tsx +45 -13
- package/src/components/VideoCalls/callSessionController.ts +51 -20
- package/src/components/VideoCalls/callUiStore.ts +33 -3
- package/src/components/VideoCalls/livekitRuntime.ts +13 -0
- package/src/components/VideoCalls/useCallKeep.ts +204 -33
- package/src/components/VideoCalls/useOngoingCallNotification.ts +113 -0
- package/src/components/VideoCalls/usePipTile.ts +214 -0
- package/src/helpers/updateMessagesTillLast.tsx +2 -1
- package/src/i18n/strings.ts +48 -0
- package/src/main.ts +3 -0
- package/src/types/types.ts +48 -0
- package/src/version.ts +1 -1
- package/lib/commonjs/components/VideoCalls/useDraggable.js +0 -59
- package/lib/commonjs/components/VideoCalls/useDraggable.js.map +0 -1
- package/lib/module/components/VideoCalls/useDraggable.js +0 -55
- package/lib/module/components/VideoCalls/useDraggable.js.map +0 -1
- package/lib/typescript/components/VideoCalls/useDraggable.d.ts +0 -19
- package/lib/typescript/components/VideoCalls/useDraggable.d.ts.map +0 -1
- package/src/components/VideoCalls/useDraggable.ts +0 -46
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { Platform } from 'react-native';
|
|
3
3
|
import { useDispatch, useSelector } from 'react-redux';
|
|
4
4
|
import { RootState, store } from '../../roomStore';
|
|
5
5
|
import { acceptIncomingCall, declineIncomingCall } from '../../roomStore/callSlice';
|
|
6
6
|
import { sendCallStateSignal } from '../../networking/callTokenStanza';
|
|
7
|
+
import { terminateActiveCall } from './callActions';
|
|
8
|
+
import { setCallMicEnabled, useCallSession } from './callSessionController';
|
|
9
|
+
import { loadLiveKit } from './livekitRuntime';
|
|
10
|
+
import { setCallSystemRinging } from './callUiStore';
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
13
|
* Native incoming-call UI (Android ConnectionService / iOS CallKit) via
|
|
@@ -14,6 +18,12 @@ import { sendCallStateSignal } from '../../networking/callTokenStanza';
|
|
|
14
18
|
* loaded lazily exactly like the LiveKit packages, so hosts that don't
|
|
15
19
|
* install it get the plain in-app ring screen and nothing breaks.
|
|
16
20
|
*
|
|
21
|
+
* On iOS every call, incoming or outgoing, is also reported to CallKit for
|
|
22
|
+
* as long as it lasts. That is what puts it in the Dynamic Island / the
|
|
23
|
+
* green status-bar pill when the app is in the background, with the
|
|
24
|
+
* system's own mute and end buttons, and what keeps the call's audio
|
|
25
|
+
* running in the background.
|
|
26
|
+
*
|
|
17
27
|
* Platform reality, stated plainly:
|
|
18
28
|
* - Android: full value. A ConnectionService call shows the system
|
|
19
29
|
* incoming-call screen over the lock screen.
|
|
@@ -35,6 +45,18 @@ interface CallKeepModule {
|
|
|
35
45
|
) => void;
|
|
36
46
|
endCall: (uuid: string) => void;
|
|
37
47
|
endAllCalls: () => void;
|
|
48
|
+
startCall?: (
|
|
49
|
+
uuid: string,
|
|
50
|
+
handle: string,
|
|
51
|
+
contactIdentifier?: string,
|
|
52
|
+
handleType?: string,
|
|
53
|
+
hasVideo?: boolean
|
|
54
|
+
) => void;
|
|
55
|
+
answerIncomingCall?: (uuid: string) => void;
|
|
56
|
+
reportConnectingOutgoingCallWithUUID?: (uuid: string) => void;
|
|
57
|
+
reportConnectedOutgoingCallWithUUID?: (uuid: string) => void;
|
|
58
|
+
reportEndCallWithUUID?: (uuid: string, reason: number) => void;
|
|
59
|
+
setMutedCall?: (uuid: string, muted: boolean) => void;
|
|
38
60
|
addEventListener: (event: string, handler: (payload: any) => void) => void;
|
|
39
61
|
removeEventListener: (event: string) => void;
|
|
40
62
|
setAvailable?: (available: boolean) => void;
|
|
@@ -95,16 +117,32 @@ const toUuid = (seed: string): string => {
|
|
|
95
117
|
].join('-');
|
|
96
118
|
};
|
|
97
119
|
|
|
120
|
+
const trace = (...args: unknown[]) => {
|
|
121
|
+
if (__DEV__) {console.log('[calls] CallKit:', ...args);}
|
|
122
|
+
};
|
|
123
|
+
|
|
98
124
|
export const useCallKeep = (): void => {
|
|
99
125
|
const dispatch = useDispatch();
|
|
100
126
|
const call = useSelector((state: RootState) => state.call);
|
|
127
|
+
const session = useCallSession();
|
|
101
128
|
const callKeep = useMemo(() => loadCallKeep(), []);
|
|
129
|
+
const [ready, setReady] = useState(false);
|
|
102
130
|
const activeUuidRef = useRef<string | null>(null);
|
|
103
|
-
|
|
131
|
+
// The CallKit call has been answered (from the system screen or in-app).
|
|
132
|
+
const answeredRef = useRef(false);
|
|
133
|
+
const outgoingReportedRef = useRef<'none' | 'connecting' | 'connected'>('none');
|
|
134
|
+
const isIOS = Platform.OS === 'ios';
|
|
104
135
|
|
|
105
136
|
// One-time native setup.
|
|
106
137
|
useEffect(() => {
|
|
107
|
-
if (!callKeep) {
|
|
138
|
+
if (!callKeep) {
|
|
139
|
+
if (isIOS) {
|
|
140
|
+
// The usual reason for "no Dynamic Island": the JS package is there
|
|
141
|
+
// but the binary was built without the RNCallKeep pod.
|
|
142
|
+
trace('unavailable (react-native-callkeep is not linked in this build)');
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
108
146
|
let cancelled = false;
|
|
109
147
|
|
|
110
148
|
(async () => {
|
|
@@ -113,6 +151,11 @@ export const useCallKeep = (): void => {
|
|
|
113
151
|
ios: {
|
|
114
152
|
appName: 'Ethora',
|
|
115
153
|
supportsVideo: true,
|
|
154
|
+
maximumCallGroups: '1',
|
|
155
|
+
maximumCallsPerCallGroup: '1',
|
|
156
|
+
// Our calls are not phone calls: keep them out of the Phone
|
|
157
|
+
// app's Recents, whose entries would dial back into nowhere.
|
|
158
|
+
includesCallsInRecents: false,
|
|
116
159
|
},
|
|
117
160
|
android: {
|
|
118
161
|
alertTitle: 'Permissions required',
|
|
@@ -130,28 +173,35 @@ export const useCallKeep = (): void => {
|
|
|
130
173
|
});
|
|
131
174
|
if (cancelled) {return;}
|
|
132
175
|
callKeep.setAvailable?.(true);
|
|
133
|
-
|
|
134
|
-
|
|
176
|
+
trace('ready');
|
|
177
|
+
setReady(true);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
trace('setup failed', error);
|
|
135
180
|
// Host didn't grant phone-account permission, or the module isn't
|
|
136
181
|
// linked. The in-app ring screen still works, so stay quiet.
|
|
137
|
-
|
|
182
|
+
setReady(false);
|
|
138
183
|
}
|
|
139
184
|
})();
|
|
140
185
|
|
|
141
186
|
return () => {
|
|
142
187
|
cancelled = true;
|
|
143
188
|
};
|
|
144
|
-
}, [callKeep]);
|
|
189
|
+
}, [callKeep, isIOS]);
|
|
145
190
|
|
|
146
|
-
// Bridge native
|
|
191
|
+
// Bridge native actions back into the call.
|
|
147
192
|
useEffect(() => {
|
|
148
193
|
if (!callKeep) {return;}
|
|
149
194
|
|
|
150
195
|
const onAnswer = () => {
|
|
196
|
+
answeredRef.current = true;
|
|
151
197
|
// The user answered from the system screen, which on Android may
|
|
152
198
|
// mean the app was not even in the foreground.
|
|
153
199
|
callKeep.backToForeground?.();
|
|
154
|
-
|
|
200
|
+
// Only from the ring: CallKit also reports the answer we make on its
|
|
201
|
+
// behalf after an in-app accept, and re-accepting then would drop an
|
|
202
|
+
// in-progress call back to 'connecting'.
|
|
203
|
+
const current = store.getState().call;
|
|
204
|
+
if (current.direction === 'incoming' && current.phase === 'ringing-incoming') {
|
|
155
205
|
dispatch(acceptIncomingCall());
|
|
156
206
|
}
|
|
157
207
|
};
|
|
@@ -165,73 +215,198 @@ export const useCallKeep = (): void => {
|
|
|
165
215
|
) {
|
|
166
216
|
sendCallStateSignal('declined');
|
|
167
217
|
dispatch(declineIncomingCall());
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
// Ended from the Dynamic Island, the lock screen or a headset.
|
|
221
|
+
if (snapshot.phase === 'error') {return;}
|
|
222
|
+
terminateActiveCall(snapshot.phase === 'requesting' ? 'cancelled' : 'ended');
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
// The system mute button (Dynamic Island, lock screen, CarPlay).
|
|
226
|
+
const onMuted = ({ muted }: { muted: boolean }) => {
|
|
227
|
+
void setCallMicEnabled(!muted);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// Another call (e.g. a phone call) put ours on hold: stop sending audio.
|
|
231
|
+
const onHold = ({ hold }: { hold: boolean }) => {
|
|
232
|
+
if (hold) {void setCallMicEnabled(false);}
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
// CallKit owns the iOS audio session: WebRTC may only start its audio
|
|
236
|
+
// unit once CallKit has activated the session.
|
|
237
|
+
const onAudioActivated = () => {
|
|
238
|
+
try {
|
|
239
|
+
loadLiveKit()?.RTCAudioSession?.audioSessionDidActivate?.();
|
|
240
|
+
} catch {
|
|
241
|
+
// Older webrtc builds manage the session on their own.
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
const onAudioDeactivated = () => {
|
|
245
|
+
try {
|
|
246
|
+
loadLiveKit()?.RTCAudioSession?.audioSessionDidDeactivate?.();
|
|
247
|
+
} catch {
|
|
248
|
+
// noop
|
|
168
249
|
}
|
|
169
250
|
};
|
|
170
251
|
|
|
171
252
|
callKeep.addEventListener('answerCall', onAnswer);
|
|
172
253
|
callKeep.addEventListener('endCall', onEnd);
|
|
254
|
+
callKeep.addEventListener('didPerformSetMutedCallAction', onMuted);
|
|
255
|
+
callKeep.addEventListener('didToggleHoldCallAction', onHold);
|
|
256
|
+
callKeep.addEventListener('didActivateAudioSession', onAudioActivated);
|
|
257
|
+
// CallKit rejected or dropped our calls (e.g. a build without the voip
|
|
258
|
+
// background mode): there is nothing to end any more.
|
|
259
|
+
const onReset = () => {
|
|
260
|
+
trace('provider reset');
|
|
261
|
+
};
|
|
262
|
+
callKeep.addEventListener('didResetProvider', onReset);
|
|
263
|
+
// The system's verdict on displayIncomingCall ("Unentitled" means the
|
|
264
|
+
// app lacks the voip background mode).
|
|
265
|
+
const onDisplayed = ({ error, errorCode }: { error?: string; errorCode?: string }) => {
|
|
266
|
+
trace('incoming call shown', error ? `failed: ${errorCode || ''} ${error}` : 'ok');
|
|
267
|
+
// CallKit refused it (Do Not Disturb, unentitled...): bring the
|
|
268
|
+
// in-app ring card back so the call can still be answered.
|
|
269
|
+
if (error) {setCallSystemRinging(false);}
|
|
270
|
+
};
|
|
271
|
+
callKeep.addEventListener('didDisplayIncomingCall', onDisplayed);
|
|
272
|
+
callKeep.addEventListener('didDeactivateAudioSession', onAudioDeactivated);
|
|
173
273
|
|
|
174
274
|
return () => {
|
|
175
275
|
callKeep.removeEventListener('answerCall');
|
|
176
276
|
callKeep.removeEventListener('endCall');
|
|
277
|
+
callKeep.removeEventListener('didPerformSetMutedCallAction');
|
|
278
|
+
callKeep.removeEventListener('didToggleHoldCallAction');
|
|
279
|
+
callKeep.removeEventListener('didActivateAudioSession');
|
|
280
|
+
callKeep.removeEventListener('didDeactivateAudioSession');
|
|
281
|
+
callKeep.removeEventListener('didResetProvider');
|
|
282
|
+
callKeep.removeEventListener('didDisplayIncomingCall');
|
|
177
283
|
};
|
|
178
284
|
}, [callKeep, dispatch]);
|
|
179
285
|
|
|
180
|
-
|
|
286
|
+
const displayName = call.roomName || 'Ethora';
|
|
287
|
+
const isRinging =
|
|
288
|
+
call.direction === 'incoming' && call.phase === 'ringing-incoming';
|
|
289
|
+
const isLive = call.phase === 'connecting' || call.phase === 'in-call';
|
|
290
|
+
const isOutgoing = call.direction === 'outgoing';
|
|
291
|
+
const peerConnected = session.anchorAt !== null;
|
|
292
|
+
|
|
293
|
+
// Report the call to the system as its state changes.
|
|
181
294
|
useEffect(() => {
|
|
182
|
-
if (!callKeep || !
|
|
295
|
+
if (!callKeep || !ready) {return;}
|
|
183
296
|
|
|
184
|
-
const
|
|
185
|
-
|
|
297
|
+
const release = () => {
|
|
298
|
+
if (!activeUuidRef.current) {return;}
|
|
299
|
+
try {
|
|
300
|
+
callKeep.endCall(activeUuidRef.current);
|
|
301
|
+
} catch {
|
|
302
|
+
// Screen already gone.
|
|
303
|
+
}
|
|
304
|
+
activeUuidRef.current = null;
|
|
305
|
+
answeredRef.current = false;
|
|
306
|
+
outgoingReportedRef.current = 'none';
|
|
307
|
+
};
|
|
186
308
|
|
|
187
|
-
if (
|
|
309
|
+
if (call.phase === 'idle' || call.phase === 'error') {
|
|
310
|
+
release();
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (isRinging) {
|
|
315
|
+
if (activeUuidRef.current) {return;}
|
|
188
316
|
const uuid = toUuid(call.callId || call.roomJid || String(Date.now()));
|
|
189
317
|
activeUuidRef.current = uuid;
|
|
318
|
+
answeredRef.current = false;
|
|
319
|
+
// iOS: the system banner is the ring UI (Telegram-style); the in-app
|
|
320
|
+
// card would only cover the screen under it.
|
|
321
|
+
if (isIOS) {setCallSystemRinging(true);}
|
|
190
322
|
try {
|
|
191
323
|
callKeep.displayIncomingCall(
|
|
192
324
|
uuid,
|
|
193
|
-
|
|
194
|
-
|
|
325
|
+
displayName,
|
|
326
|
+
displayName,
|
|
195
327
|
'generic',
|
|
196
328
|
call.kind === 'video'
|
|
197
329
|
);
|
|
198
330
|
} catch {
|
|
199
331
|
activeUuidRef.current = null;
|
|
332
|
+
setCallSystemRinging(false);
|
|
200
333
|
}
|
|
201
334
|
return;
|
|
202
335
|
}
|
|
203
336
|
|
|
204
|
-
//
|
|
205
|
-
//
|
|
206
|
-
if (
|
|
337
|
+
// iOS: an outgoing call is a CallKit call from the first ring, so it
|
|
338
|
+
// shows in the Dynamic Island even before the peer answers.
|
|
339
|
+
if (isIOS && isOutgoing && !activeUuidRef.current && callKeep.startCall) {
|
|
340
|
+
// Unique per call: CallKit refuses a UUID it has seen before, and
|
|
341
|
+
// the callId only arrives with the token.
|
|
342
|
+
const uuid = toUuid(`${call.roomJid || ''}|${call.startedAt || Date.now()}`);
|
|
343
|
+
activeUuidRef.current = uuid;
|
|
344
|
+
outgoingReportedRef.current = 'none';
|
|
345
|
+
trace('startCall', uuid);
|
|
207
346
|
try {
|
|
208
|
-
callKeep.
|
|
347
|
+
callKeep.startCall(uuid, displayName, displayName, 'generic', call.kind === 'video');
|
|
209
348
|
} catch {
|
|
210
|
-
|
|
349
|
+
activeUuidRef.current = null;
|
|
211
350
|
}
|
|
212
|
-
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const uuid = activeUuidRef.current;
|
|
355
|
+
if (!uuid) {return;}
|
|
356
|
+
|
|
357
|
+
if (isIOS && isOutgoing) {
|
|
358
|
+
if (peerConnected && outgoingReportedRef.current !== 'connected') {
|
|
359
|
+
outgoingReportedRef.current = 'connected';
|
|
360
|
+
callKeep.reportConnectedOutgoingCallWithUUID?.(uuid);
|
|
361
|
+
} else if (
|
|
362
|
+
isLive &&
|
|
363
|
+
!peerConnected &&
|
|
364
|
+
outgoingReportedRef.current === 'none'
|
|
365
|
+
) {
|
|
366
|
+
outgoingReportedRef.current = 'connecting';
|
|
367
|
+
callKeep.reportConnectingOutgoingCallWithUUID?.(uuid);
|
|
368
|
+
}
|
|
369
|
+
return;
|
|
213
370
|
}
|
|
214
371
|
|
|
215
|
-
|
|
372
|
+
// Incoming, accepted with the in-app button: tell CallKit, or its
|
|
373
|
+
// screen keeps ringing on top of the call.
|
|
374
|
+
if (isIOS && isLive && !answeredRef.current) {
|
|
375
|
+
answeredRef.current = true;
|
|
216
376
|
try {
|
|
217
|
-
callKeep.
|
|
377
|
+
callKeep.answerIncomingCall?.(uuid);
|
|
218
378
|
} catch {
|
|
219
379
|
// noop
|
|
220
380
|
}
|
|
221
|
-
activeUuidRef.current = null;
|
|
222
381
|
}
|
|
223
382
|
}, [
|
|
224
383
|
callKeep,
|
|
225
|
-
|
|
384
|
+
ready,
|
|
385
|
+
isIOS,
|
|
386
|
+
isRinging,
|
|
387
|
+
isLive,
|
|
388
|
+
isOutgoing,
|
|
389
|
+
peerConnected,
|
|
390
|
+
displayName,
|
|
226
391
|
call.phase,
|
|
227
392
|
call.callId,
|
|
228
393
|
call.roomJid,
|
|
229
|
-
call.
|
|
230
|
-
call.peerXmppUsername,
|
|
394
|
+
call.startedAt,
|
|
231
395
|
call.kind,
|
|
232
396
|
]);
|
|
233
397
|
|
|
234
|
-
//
|
|
398
|
+
// Keep the system mute button in step with ours.
|
|
399
|
+
useEffect(() => {
|
|
400
|
+
const uuid = activeUuidRef.current;
|
|
401
|
+
if (!callKeep || !ready || !isIOS || !uuid || !isLive) {return;}
|
|
402
|
+
try {
|
|
403
|
+
callKeep.setMutedCall?.(uuid, !session.micOn);
|
|
404
|
+
} catch {
|
|
405
|
+
// noop
|
|
406
|
+
}
|
|
407
|
+
}, [callKeep, ready, isIOS, isLive, session.micOn]);
|
|
408
|
+
|
|
409
|
+
// Nothing to clean up on unmount beyond the active call: this hook
|
|
235
410
|
// lives for the lifetime of the provider.
|
|
236
411
|
useEffect(
|
|
237
412
|
() => () => {
|
|
@@ -245,8 +420,4 @@ export const useCallKeep = (): void => {
|
|
|
245
420
|
},
|
|
246
421
|
[callKeep]
|
|
247
422
|
);
|
|
248
|
-
|
|
249
|
-
// iOS-only note kept as a runtime no-op so the import isn't unused when
|
|
250
|
-
// the platform check is tree-shaken in release builds.
|
|
251
|
-
void Platform.OS;
|
|
252
423
|
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { useSelector } from 'react-redux';
|
|
3
|
+
import { RootState } from '../../roomStore';
|
|
4
|
+
import { useT } from '../../i18n/useT';
|
|
5
|
+
import type {
|
|
6
|
+
OngoingCallNotification,
|
|
7
|
+
OngoingCallNotificationAction,
|
|
8
|
+
} from '../../types/types';
|
|
9
|
+
import { terminateActiveCall } from './callActions';
|
|
10
|
+
import { toggleCallCamera, toggleCallMic, useCallSession } from './callSessionController';
|
|
11
|
+
import { setCallMinimized } from './callUiStore';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Drives the host's ongoing-call notification (`videoCalls.
|
|
15
|
+
* ongoingCallNotification`, an Android foreground-service notification in
|
|
16
|
+
* the Ethora app): shown while a call is connecting or connected, updated
|
|
17
|
+
* when the mic, camera or timer anchor change, and its buttons act on the
|
|
18
|
+
* call like the in-app ones.
|
|
19
|
+
*/
|
|
20
|
+
export const useOngoingCallNotification = (
|
|
21
|
+
adapter: OngoingCallNotification | undefined
|
|
22
|
+
): void => {
|
|
23
|
+
const t = useT();
|
|
24
|
+
const call = useSelector((state: RootState) => state.call);
|
|
25
|
+
const session = useCallSession();
|
|
26
|
+
const shownRef = useRef(false);
|
|
27
|
+
|
|
28
|
+
const live =
|
|
29
|
+
!!call.token && (call.phase === 'connecting' || call.phase === 'in-call');
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!adapter) {return;}
|
|
33
|
+
return adapter.addActionListener((action: OngoingCallNotificationAction) => {
|
|
34
|
+
switch (action) {
|
|
35
|
+
case 'hangUp':
|
|
36
|
+
terminateActiveCall('ended');
|
|
37
|
+
break;
|
|
38
|
+
case 'toggleMic':
|
|
39
|
+
void toggleCallMic();
|
|
40
|
+
break;
|
|
41
|
+
case 'toggleCamera':
|
|
42
|
+
void toggleCallCamera();
|
|
43
|
+
break;
|
|
44
|
+
case 'open':
|
|
45
|
+
// Back from the notification: show the call, not the strip.
|
|
46
|
+
setCallMinimized(false);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}, [adapter]);
|
|
51
|
+
|
|
52
|
+
const isVideo = call.kind === 'video';
|
|
53
|
+
const connectedAt = session.anchorAt;
|
|
54
|
+
const text =
|
|
55
|
+
connectedAt !== null
|
|
56
|
+
? isVideo
|
|
57
|
+
? t('call.notification.ongoingVideo')
|
|
58
|
+
: t('call.notification.ongoing')
|
|
59
|
+
: !session.connected
|
|
60
|
+
? t('call.status.connecting')
|
|
61
|
+
: t('call.status.waitingForPeer');
|
|
62
|
+
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
if (!adapter) {return;}
|
|
65
|
+
if (!live) {
|
|
66
|
+
if (shownRef.current) {
|
|
67
|
+
shownRef.current = false;
|
|
68
|
+
adapter.hide();
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
shownRef.current = true;
|
|
73
|
+
adapter.show({
|
|
74
|
+
callId: call.callId || call.roomJid || 'call',
|
|
75
|
+
title: call.roomName || t('call.unknownCaller'),
|
|
76
|
+
text,
|
|
77
|
+
kind: call.kind,
|
|
78
|
+
connectedAt,
|
|
79
|
+
micOn: session.micOn,
|
|
80
|
+
cameraOn: isVideo && session.cameraOn,
|
|
81
|
+
labels: {
|
|
82
|
+
hangUp: t('call.action.hangUp'),
|
|
83
|
+
mute: t('call.notification.mute'),
|
|
84
|
+
unmute: t('call.notification.unmute'),
|
|
85
|
+
cameraOn: t('call.notification.cameraOn'),
|
|
86
|
+
cameraOff: t('call.notification.cameraOff'),
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}, [
|
|
90
|
+
adapter,
|
|
91
|
+
live,
|
|
92
|
+
t,
|
|
93
|
+
text,
|
|
94
|
+
connectedAt,
|
|
95
|
+
isVideo,
|
|
96
|
+
call.callId,
|
|
97
|
+
call.roomJid,
|
|
98
|
+
call.roomName,
|
|
99
|
+
call.kind,
|
|
100
|
+
session.micOn,
|
|
101
|
+
session.cameraOn,
|
|
102
|
+
]);
|
|
103
|
+
|
|
104
|
+
useEffect(
|
|
105
|
+
() => () => {
|
|
106
|
+
if (adapter && shownRef.current) {
|
|
107
|
+
shownRef.current = false;
|
|
108
|
+
adapter.hide();
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
[adapter]
|
|
112
|
+
);
|
|
113
|
+
};
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { Animated, LayoutChangeEvent, PanResponder } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The small video tile of a call, Telegram-style: drag it anywhere and it
|
|
6
|
+
* snaps to the nearest corner when released (a flick carries it towards
|
|
7
|
+
* the flick), pinch it to switch between a small and a large size.
|
|
8
|
+
*
|
|
9
|
+
* Positions are kept per corner rather than per pixel, so the tile stays
|
|
10
|
+
* glued to its corner when the stage changes size (rotation, iPad split
|
|
11
|
+
* view) or the tile itself changes size.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type PipTileSize = 'small' | 'large';
|
|
15
|
+
|
|
16
|
+
export const PIP_TILE_SIZES: Record<PipTileSize, { width: number; height: number }> = {
|
|
17
|
+
small: { width: 104, height: 148 },
|
|
18
|
+
large: { width: 156, height: 222 },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const MARGIN = 12;
|
|
22
|
+
// How far a flick carries the tile before picking a corner, in ms of velocity.
|
|
23
|
+
const FLICK_PROJECTION_MS = 160;
|
|
24
|
+
// Pinch past these ratios to change size; in between keeps the current one.
|
|
25
|
+
const GROW_RATIO = 1.12;
|
|
26
|
+
const SHRINK_RATIO = 0.9;
|
|
27
|
+
|
|
28
|
+
interface Corner {
|
|
29
|
+
right: boolean;
|
|
30
|
+
bottom: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface Stage {
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const SPRING = { useNativeDriver: false, damping: 20, stiffness: 220, mass: 0.8 };
|
|
39
|
+
|
|
40
|
+
const touchDistance = (touches: ReadonlyArray<{ pageX: number; pageY: number }>) => {
|
|
41
|
+
const [a, b] = touches;
|
|
42
|
+
return Math.hypot(a.pageX - b.pageX, a.pageY - b.pageY);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const usePipTile = ({ topInset = 0 }: { topInset?: number } = {}) => {
|
|
46
|
+
const [stage, setStage] = useState<Stage | null>(null);
|
|
47
|
+
const [size, setSize] = useState<PipTileSize>('small');
|
|
48
|
+
const stageRef = useRef<Stage | null>(null);
|
|
49
|
+
const sizeRef = useRef<PipTileSize>('small');
|
|
50
|
+
const cornerRef = useRef<Corner>({ right: true, bottom: false });
|
|
51
|
+
const topInsetRef = useRef(topInset);
|
|
52
|
+
topInsetRef.current = topInset;
|
|
53
|
+
|
|
54
|
+
const position = useRef(new Animated.ValueXY({ x: 0, y: 0 })).current;
|
|
55
|
+
const width = useRef(new Animated.Value(PIP_TILE_SIZES.small.width)).current;
|
|
56
|
+
const height = useRef(new Animated.Value(PIP_TILE_SIZES.small.height)).current;
|
|
57
|
+
const pinchScale = useRef(new Animated.Value(1)).current;
|
|
58
|
+
// Where the tile rests, i.e. where a drag starts from.
|
|
59
|
+
const restRef = useRef({ x: 0, y: 0 });
|
|
60
|
+
const gestureRef = useRef({ pinching: false, startDistance: 0, scale: 1 });
|
|
61
|
+
|
|
62
|
+
const cornerPoint = useCallback((corner: Corner, tileSize: PipTileSize) => {
|
|
63
|
+
const area = stageRef.current;
|
|
64
|
+
if (!area) {return { x: 0, y: 0 };}
|
|
65
|
+
const tile = PIP_TILE_SIZES[tileSize];
|
|
66
|
+
const top = MARGIN + topInsetRef.current;
|
|
67
|
+
return {
|
|
68
|
+
x: corner.right ? Math.max(MARGIN, area.width - tile.width - MARGIN) : MARGIN,
|
|
69
|
+
y: corner.bottom ? Math.max(top, area.height - tile.height - MARGIN) : top,
|
|
70
|
+
};
|
|
71
|
+
}, []);
|
|
72
|
+
|
|
73
|
+
const settle = useCallback(
|
|
74
|
+
(animated: boolean) => {
|
|
75
|
+
const tileSize = sizeRef.current;
|
|
76
|
+
const target = cornerPoint(cornerRef.current, tileSize);
|
|
77
|
+
const tile = PIP_TILE_SIZES[tileSize];
|
|
78
|
+
restRef.current = target;
|
|
79
|
+
if (!animated) {
|
|
80
|
+
position.setValue(target);
|
|
81
|
+
width.setValue(tile.width);
|
|
82
|
+
height.setValue(tile.height);
|
|
83
|
+
pinchScale.setValue(1);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
Animated.parallel([
|
|
87
|
+
Animated.spring(position, { ...SPRING, toValue: target }),
|
|
88
|
+
Animated.spring(width, { ...SPRING, toValue: tile.width }),
|
|
89
|
+
Animated.spring(height, { ...SPRING, toValue: tile.height }),
|
|
90
|
+
Animated.spring(pinchScale, { ...SPRING, toValue: 1 }),
|
|
91
|
+
]).start();
|
|
92
|
+
},
|
|
93
|
+
[cornerPoint, position, width, height, pinchScale]
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const onStageLayout = useCallback(
|
|
97
|
+
(event: LayoutChangeEvent) => {
|
|
98
|
+
const { width: w, height: h } = event.nativeEvent.layout;
|
|
99
|
+
const prev = stageRef.current;
|
|
100
|
+
if (prev && prev.width === w && prev.height === h) {return;}
|
|
101
|
+
stageRef.current = { width: w, height: h };
|
|
102
|
+
setStage(stageRef.current);
|
|
103
|
+
settle(false);
|
|
104
|
+
},
|
|
105
|
+
[settle]
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// The safe-area inset arrives after the first layout on some devices.
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
if (stageRef.current) {settle(false);}
|
|
111
|
+
}, [topInset, settle]);
|
|
112
|
+
|
|
113
|
+
const panHandlers = useMemo(
|
|
114
|
+
() =>
|
|
115
|
+
PanResponder.create({
|
|
116
|
+
// Two fingers are always ours (pinch); one finger only once it
|
|
117
|
+
// moves, so a tap still reaches the tile's onPress (swap videos).
|
|
118
|
+
onStartShouldSetPanResponderCapture: (event) =>
|
|
119
|
+
event.nativeEvent.touches.length >= 2,
|
|
120
|
+
// Own the touch from the start when the tile has no tap target
|
|
121
|
+
// (nothing to swap): an ancestor outside the call Modal would take
|
|
122
|
+
// it otherwise, and the move-capture below would never be asked.
|
|
123
|
+
onStartShouldSetPanResponder: () => true,
|
|
124
|
+
onMoveShouldSetPanResponderCapture: (event, gesture) =>
|
|
125
|
+
event.nativeEvent.touches.length >= 2 ||
|
|
126
|
+
Math.abs(gesture.dx) > 4 ||
|
|
127
|
+
Math.abs(gesture.dy) > 4,
|
|
128
|
+
// Never hand the tile over to the swipe-to-minimize of the screen.
|
|
129
|
+
onPanResponderTerminationRequest: () => false,
|
|
130
|
+
onPanResponderGrant: () => {
|
|
131
|
+
position.stopAnimation();
|
|
132
|
+
width.stopAnimation();
|
|
133
|
+
height.stopAnimation();
|
|
134
|
+
pinchScale.stopAnimation();
|
|
135
|
+
gestureRef.current = { pinching: false, startDistance: 0, scale: 1 };
|
|
136
|
+
},
|
|
137
|
+
onPanResponderMove: (event, gesture) => {
|
|
138
|
+
const touches = event.nativeEvent.touches;
|
|
139
|
+
const state = gestureRef.current;
|
|
140
|
+
if (touches.length >= 2) {
|
|
141
|
+
const distance = touchDistance(touches);
|
|
142
|
+
if (!state.pinching || state.startDistance <= 0) {
|
|
143
|
+
state.pinching = true;
|
|
144
|
+
state.startDistance = distance;
|
|
145
|
+
} else {
|
|
146
|
+
state.scale = Math.min(1.8, Math.max(0.6, distance / state.startDistance));
|
|
147
|
+
pinchScale.setValue(state.scale);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
position.setValue({
|
|
151
|
+
x: restRef.current.x + gesture.dx,
|
|
152
|
+
y: restRef.current.y + gesture.dy,
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
onPanResponderRelease: (_event, gesture) => {
|
|
156
|
+
const area = stageRef.current;
|
|
157
|
+
const state = gestureRef.current;
|
|
158
|
+
if (state.pinching) {
|
|
159
|
+
const next: PipTileSize =
|
|
160
|
+
state.scale >= GROW_RATIO
|
|
161
|
+
? 'large'
|
|
162
|
+
: state.scale <= SHRINK_RATIO
|
|
163
|
+
? 'small'
|
|
164
|
+
: sizeRef.current;
|
|
165
|
+
if (next !== sizeRef.current) {
|
|
166
|
+
// Keep the size the finger left it at, then let the spring
|
|
167
|
+
// carry it to the new one, so the tile doesn't jump.
|
|
168
|
+
const from = PIP_TILE_SIZES[sizeRef.current];
|
|
169
|
+
width.setValue(from.width * state.scale);
|
|
170
|
+
height.setValue(from.height * state.scale);
|
|
171
|
+
pinchScale.setValue(1);
|
|
172
|
+
sizeRef.current = next;
|
|
173
|
+
setSize(next);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (area) {
|
|
177
|
+
const tile = PIP_TILE_SIZES[sizeRef.current];
|
|
178
|
+
const centerX =
|
|
179
|
+
restRef.current.x + gesture.dx + gesture.vx * FLICK_PROJECTION_MS + tile.width / 2;
|
|
180
|
+
const centerY =
|
|
181
|
+
restRef.current.y + gesture.dy + gesture.vy * FLICK_PROJECTION_MS + tile.height / 2;
|
|
182
|
+
cornerRef.current = {
|
|
183
|
+
right: centerX > area.width / 2,
|
|
184
|
+
bottom: centerY > area.height / 2,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
settle(true);
|
|
188
|
+
},
|
|
189
|
+
onPanResponderTerminate: () => settle(true),
|
|
190
|
+
}).panHandlers,
|
|
191
|
+
[position, width, height, pinchScale, settle]
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
/** Put on the area the tile moves within. */
|
|
196
|
+
onStageLayout,
|
|
197
|
+
panHandlers,
|
|
198
|
+
size,
|
|
199
|
+
/** Hidden until the stage is measured, so it never flashes at 0,0. */
|
|
200
|
+
style: {
|
|
201
|
+
position: 'absolute' as const,
|
|
202
|
+
left: 0,
|
|
203
|
+
top: 0,
|
|
204
|
+
width,
|
|
205
|
+
height,
|
|
206
|
+
opacity: stage ? 1 : 0,
|
|
207
|
+
transform: [
|
|
208
|
+
{ translateX: position.x },
|
|
209
|
+
{ translateY: position.y },
|
|
210
|
+
{ scale: pinchScale },
|
|
211
|
+
],
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
};
|