@zapiack/react-native 0.0.0-stage → 0.2.0
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/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +171 -2
- package/android/build.gradle +48 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/zapiack/reactnative/ZapiackPushModule.kt +113 -0
- package/android/src/main/java/com/zapiack/reactnative/ZapiackPushPackage.kt +12 -0
- package/dist/calls.d.mts +198 -0
- package/dist/calls.d.ts +198 -0
- package/dist/calls.js +793 -0
- package/dist/calls.mjs +406 -0
- package/dist/chunk-CCLICX3L.mjs +371 -0
- package/dist/index.d.mts +61 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +490 -0
- package/dist/index.mjs +100 -0
- package/dist/realtime-BAcafCSr.d.mts +173 -0
- package/dist/realtime-BAcafCSr.d.ts +173 -0
- package/ios/Zapiack/Api.swift +134 -0
- package/ios/Zapiack/EventQueue.swift +95 -0
- package/ios/Zapiack/ImageFile.swift +22 -0
- package/ios/Zapiack/LayoutModel.swift +128 -0
- package/ios/Zapiack/LayoutView.swift +206 -0
- package/ios/Zapiack/Models.swift +151 -0
- package/ios/Zapiack/Processing.swift +59 -0
- package/ios/Zapiack/PushClient.swift +140 -0
- package/ios/Zapiack/Storage.swift +86 -0
- package/ios/Zapiack/ZapiackLiveActivityWidget.swift +170 -0
- package/ios/Zapiack/ZapiackLiveAttributes.swift +78 -0
- package/ios/Zapiack/ZapiackPush.swift +146 -0
- package/ios/ZapiackPushModule.m +19 -0
- package/ios/ZapiackPushModule.swift +126 -0
- package/package.json +97 -4
- package/zapiack-react-native.podspec +17 -0
package/dist/calls.d.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { Device } from 'mediasoup-client';
|
|
2
|
+
import { MediaStream, MediaStreamTrack } from 'react-native-webrtc';
|
|
3
|
+
import { ZapiackRealtime, RealtimeEnv, ZapiackRealtimeError } from './index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Zapiack Voice & Video for React Native: join a room and send and receive audio and video.
|
|
7
|
+
*
|
|
8
|
+
* Your server creates the room and mints a token for each person (`POST /v1/calls/rooms`, `POST /v1/calls/tokens`) and hands it to
|
|
9
|
+
* the app, so the API key never reaches the phone. The app joins with the token:
|
|
10
|
+
*
|
|
11
|
+
* const call = new ZapiackCall({ getToken: () => fetch('https://my-server/call-token').then((r) => r.text()) });
|
|
12
|
+
* call.on('track', ({ identity, source, stream }) => show(identity, source, stream.toURL())); // <RTCView streamURL=... />
|
|
13
|
+
* await call.join();
|
|
14
|
+
* await call.enableMicrophone();
|
|
15
|
+
* await call.enableCamera();
|
|
16
|
+
*
|
|
17
|
+
* What a person may send comes from their token: a listener can only receive. Needs `react-native-webrtc` and `mediasoup-client`
|
|
18
|
+
* (both peer dependencies of this entry only; push and messaging do not need them).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** Where sound plays. Wire it to `react-native-incall-manager` (see the README) so the earpiece, speaker and the phone's call mode work. */
|
|
22
|
+
interface AudioSession {
|
|
23
|
+
start(options: {
|
|
24
|
+
media: 'audio' | 'video';
|
|
25
|
+
}): void;
|
|
26
|
+
stop(): void;
|
|
27
|
+
setSpeaker(on: boolean): void;
|
|
28
|
+
}
|
|
29
|
+
type CallRole = 'host' | 'speaker' | 'listener';
|
|
30
|
+
/** What a track is: a microphone, a camera, or a shared screen. */
|
|
31
|
+
type TrackSource = 'audio' | 'video' | 'screen';
|
|
32
|
+
interface CallOptions {
|
|
33
|
+
/** Returns a call token from your server (`POST /v1/calls/tokens`). Called on every connect, so an expired one is replaced. */
|
|
34
|
+
getToken: () => Promise<string>;
|
|
35
|
+
/** Default `wss://rt.zapiack.com`. */
|
|
36
|
+
url?: string;
|
|
37
|
+
/** Send and receive over TCP only. For networks that block UDP. Default false. */
|
|
38
|
+
forceTcp?: boolean;
|
|
39
|
+
/** How often, in milliseconds, the client asks the server who is in the room and catches up on anything it missed. Default 30000. 0 turns it off. */
|
|
40
|
+
resyncMs?: number;
|
|
41
|
+
/** Sound routing and the phone's call mode. Started when the call is joined and stopped when it ends. */
|
|
42
|
+
audioSession?: AudioSession;
|
|
43
|
+
/** Which camera `enableCamera` opens first. Default `user` (the front one). */
|
|
44
|
+
camera?: 'user' | 'environment';
|
|
45
|
+
}
|
|
46
|
+
interface Peer {
|
|
47
|
+
identity: string;
|
|
48
|
+
role: CallRole;
|
|
49
|
+
}
|
|
50
|
+
/** Someone else's audio, video or screen. Give `stream.toURL()` to an `<RTCView streamURL={...} />`; audio plays by itself. */
|
|
51
|
+
interface RemoteTrack {
|
|
52
|
+
identity: string;
|
|
53
|
+
source: TrackSource;
|
|
54
|
+
track: MediaStreamTrack;
|
|
55
|
+
stream: MediaStream;
|
|
56
|
+
/** The sender's track id: the same one `trackEnded` and `paused` carry. */
|
|
57
|
+
producerId: string;
|
|
58
|
+
}
|
|
59
|
+
interface CallEvents {
|
|
60
|
+
/** Someone's track arrived. */
|
|
61
|
+
track: RemoteTrack;
|
|
62
|
+
/** Someone stopped sending a track, or left. */
|
|
63
|
+
trackEnded: {
|
|
64
|
+
identity: string;
|
|
65
|
+
source: TrackSource;
|
|
66
|
+
producerId: string;
|
|
67
|
+
};
|
|
68
|
+
/** Someone muted or unmuted a track. The track stays; what it carries is silence or a frozen picture. */
|
|
69
|
+
paused: {
|
|
70
|
+
identity: string;
|
|
71
|
+
source: TrackSource;
|
|
72
|
+
producerId: string;
|
|
73
|
+
paused: boolean;
|
|
74
|
+
};
|
|
75
|
+
peerJoined: Peer;
|
|
76
|
+
peerLeft: {
|
|
77
|
+
identity: string;
|
|
78
|
+
};
|
|
79
|
+
/** The room was ended by your server. The call is already closed when this fires. */
|
|
80
|
+
ended: {
|
|
81
|
+
reason: string;
|
|
82
|
+
};
|
|
83
|
+
/** A problem worth showing: a track that could not be played, or a refused request. */
|
|
84
|
+
error: ZapiackRealtimeError;
|
|
85
|
+
}
|
|
86
|
+
type CallState = 'idle' | 'joining' | 'joined' | 'reconnecting' | 'closed';
|
|
87
|
+
type Listener<K extends keyof CallEvents> = (e: CallEvents[K]) => void;
|
|
88
|
+
/** What can be swapped in a test. */
|
|
89
|
+
interface CallEnv {
|
|
90
|
+
realtime?: ZapiackRealtime;
|
|
91
|
+
realtimeEnv?: RealtimeEnv;
|
|
92
|
+
device?: () => Device;
|
|
93
|
+
getUserMedia?: (c: Record<string, unknown>) => Promise<MediaStream>;
|
|
94
|
+
getDisplayMedia?: () => Promise<MediaStream>;
|
|
95
|
+
newStream?: (tracks: MediaStreamTrack[]) => MediaStream;
|
|
96
|
+
setTimeout?: (fn: () => void, ms: number) => unknown;
|
|
97
|
+
clearTimeout?: (id: unknown) => void;
|
|
98
|
+
}
|
|
99
|
+
declare class ZapiackCall {
|
|
100
|
+
private readonly options;
|
|
101
|
+
private readonly env;
|
|
102
|
+
private readonly rt;
|
|
103
|
+
private readonly device;
|
|
104
|
+
private readonly listeners;
|
|
105
|
+
private sendT;
|
|
106
|
+
private recvT;
|
|
107
|
+
private readonly producers;
|
|
108
|
+
/** Everything being received, by the sender's track id. */
|
|
109
|
+
private readonly consumers;
|
|
110
|
+
private readonly peers;
|
|
111
|
+
private joinedReply;
|
|
112
|
+
private roomChannel;
|
|
113
|
+
private stopRoom;
|
|
114
|
+
private stopState;
|
|
115
|
+
private _state;
|
|
116
|
+
/** Tracks being fetched right now, so two events for the same track do not make two consumers. */
|
|
117
|
+
private readonly fetching;
|
|
118
|
+
private wasConnected;
|
|
119
|
+
private resyncing;
|
|
120
|
+
private resyncTimer;
|
|
121
|
+
private facing;
|
|
122
|
+
private speaker;
|
|
123
|
+
/** A transport that went `disconnected` gets a few seconds to recover by itself before its path is restarted. */
|
|
124
|
+
private readonly lapse;
|
|
125
|
+
constructor(options: CallOptions, env?: CallEnv);
|
|
126
|
+
get state(): CallState;
|
|
127
|
+
/** What this person may do in the room: `listener` can only receive. */
|
|
128
|
+
get role(): CallRole | null;
|
|
129
|
+
get roomId(): string | null;
|
|
130
|
+
/** Who else is in the room now. */
|
|
131
|
+
get members(): Peer[];
|
|
132
|
+
/** The tracks this person is sending now. */
|
|
133
|
+
get sending(): TrackSource[];
|
|
134
|
+
on<K extends keyof CallEvents>(event: K, fn: Listener<K>): () => void;
|
|
135
|
+
private emit;
|
|
136
|
+
/** Connects, joins the room the token is for, and starts receiving what the others are sending. */
|
|
137
|
+
join(): Promise<{
|
|
138
|
+
role: CallRole;
|
|
139
|
+
roomId: string;
|
|
140
|
+
members: Peer[];
|
|
141
|
+
}>;
|
|
142
|
+
/** Turns the microphone on and sends it. Pass your own track to send something else. */
|
|
143
|
+
enableMicrophone(track?: MediaStreamTrack): Promise<MediaStreamTrack>;
|
|
144
|
+
/** Turns the camera on and sends it. Opens the camera set by the `camera` option, front by default. */
|
|
145
|
+
enableCamera(track?: MediaStreamTrack): Promise<MediaStreamTrack>;
|
|
146
|
+
/**
|
|
147
|
+
* Shares the phone's screen. Android needs a foreground service for screen capture and iOS needs a broadcast extension: see
|
|
148
|
+
* react-native-webrtc's screen sharing guide. Stops by itself when the person stops sharing.
|
|
149
|
+
*/
|
|
150
|
+
shareScreen(track?: MediaStreamTrack): Promise<MediaStreamTrack>;
|
|
151
|
+
/** Mutes or unmutes what is being sent. Nothing is sent while muted, and the others are told. */
|
|
152
|
+
setMuted(source: TrackSource, muted: boolean): Promise<void>;
|
|
153
|
+
/** Flips between the front and back camera while the camera is on, without interrupting what is being sent. */
|
|
154
|
+
switchCamera(): void;
|
|
155
|
+
/** Plays sound through the loudspeaker (true) or the earpiece (false). Needs an `audioSession` option; remembered across a reconnect. */
|
|
156
|
+
setSpeaker(on: boolean): void;
|
|
157
|
+
isMuted(source: TrackSource): boolean;
|
|
158
|
+
/** Stops sending a track and lets go of the device (the camera light goes off). */
|
|
159
|
+
stop(source: TrackSource): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* What is arriving now, one entry per track being received: how many bytes and packets, how many were lost, and the jitter in
|
|
162
|
+
* seconds. For a quality indicator, or to see that media is really flowing.
|
|
163
|
+
*/
|
|
164
|
+
stats(): Promise<Array<{
|
|
165
|
+
identity: string;
|
|
166
|
+
source: TrackSource;
|
|
167
|
+
bytesReceived: number;
|
|
168
|
+
packetsReceived: number;
|
|
169
|
+
packetsLost: number;
|
|
170
|
+
jitter: number;
|
|
171
|
+
}>>;
|
|
172
|
+
/** Leaves the room and lets go of the camera, the microphone and the connection. */
|
|
173
|
+
leave(): Promise<void>;
|
|
174
|
+
private userMedia;
|
|
175
|
+
private displayMedia;
|
|
176
|
+
private transport;
|
|
177
|
+
private restartIce;
|
|
178
|
+
private send;
|
|
179
|
+
private reconcile;
|
|
180
|
+
private consume;
|
|
181
|
+
private endTrack;
|
|
182
|
+
private dropFrom;
|
|
183
|
+
private onRoomEvent;
|
|
184
|
+
/** Who this person is in the room, as the server knows them: events about this name are about us. */
|
|
185
|
+
private identity;
|
|
186
|
+
/**
|
|
187
|
+
* Room events travel over best-effort publish and subscribe, so a client does not rely on every one arriving: now and then it asks the
|
|
188
|
+
* server who is in the room and what they are sending, and catches up on anything it missed.
|
|
189
|
+
*/
|
|
190
|
+
private startResync;
|
|
191
|
+
private resync;
|
|
192
|
+
/** The socket dropped and came back: take the place in the room again and see what changed while away. */
|
|
193
|
+
private onLine;
|
|
194
|
+
private teardown;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export { ZapiackCall };
|
|
198
|
+
export type { AudioSession, CallEnv, CallEvents, CallOptions, CallRole, CallState, Peer, RemoteTrack, TrackSource };
|