Skip to content

Commit 715309c

Browse files
build janus.js
1 parent f2b92dc commit 715309c

10 files changed

+3216
-720
lines changed

build_janus.sh

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/bin/bash
22
mkdir js
3-
git submodule init
4-
git submodule update
5-
cd janus-gateway/npm
3+
cd janus-gateway
4+
git pull origin master
5+
cd npm
66
npm install
77
npm run rollup -- --o ./janus.js --f es
88
cd ..
9-
cp -r npm/* ../js/
10-
git clean -fxd
9+
cp -r npm/* ../js/

janus-gateway

js/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Janus WebRTC Server (janus.js)
2+
==============================
3+
4+
This is the npm version of `janus.js`, a JavaScript library to talk to the [Janus WebRTC Server](https://github.com/meetecho/janus-gateway). This is the only authorized version of `janus.js` on npm:
5+
6+
https://www.npmjs.com/package/janus-gateway
7+
8+
If you encounter other versions, they were not made nor uploaded by [Meetecho](https://www.meetecho.com), and so should be considered not trusted.
9+
10+
For information on how to use the library, please refer to the [official documentation](https://janus.conf.meetecho.com/docs/JS), which includes information on how to use `janus.js` as a module.
11+
12+
> **Note well**: please notice that `janus.js` is mostly meant as a convenience library for use in our Janus demos, and is not necessarily suited for production usages. For a more modern JavaScript and Node.js SDK to use with Janus, please refer to [Janode](https://www.npmjs.com/package/janode) instead.

js/janus.d.ts

+164-20
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,78 @@
1+
declare global {
2+
const jQuery: any
3+
}
4+
15
declare namespace JanusJS {
26
interface Dependencies {
37
adapter: any;
48
WebSocket: (server: string, protocol: string) => WebSocket;
59
isArray: (array: any) => array is Array<any>;
6-
extension: () => boolean;
7-
httpAPICall: (url: string, options: any) => void;
10+
extension: ChromeExtension;
11+
httpAPICall: (url: string, options: HttpApiCallOption) => void;
12+
}
13+
14+
interface DefaultDependencies extends Dependencies {
15+
fetch: typeof fetch;
16+
Promise: PromiseConstructorLike;
17+
}
18+
19+
interface OldDependencies extends Dependencies {
20+
jQuery: typeof jQuery;
821
}
922

1023
interface DependenciesResult {
1124
adapter: any;
1225
newWebSocket: (server: string, protocol: string) => WebSocket;
1326
isArray: (array: any) => array is Array<any>;
14-
extension: () => boolean;
15-
httpAPICall: (url: string, options: any) => void;
27+
extension: ChromeExtension;
28+
httpAPICall: (url: string, options: HttpApiCallOption) => void;
29+
}
30+
31+
type ChromeExtension = {
32+
cache?: { [key in string]: GetScreenCallback },
33+
extensionId: string;
34+
isInstalled: () => boolean;
35+
getScreen: (callback: GetScreenCallback) => void;
36+
init: () => void;
37+
}
38+
39+
type GetScreenCallback = (error?, sourceId?) => void
40+
41+
type HttpApiCallOption = {
42+
async: boolean,
43+
verb: string,
44+
body: JanusRequest,
45+
timeout: number,
46+
withCredentials: boolean,
47+
success: (result: unknown) => void,
48+
error: (error: string, reason?: unknown) => void,
49+
}
50+
51+
type JanusRequest = {
52+
plugin?: string,
53+
token?: string,
54+
apisecret?: string,
55+
session_id?: number,
56+
handle_id?: number,
57+
opaque_id?: string,
58+
loop_index?: number,
59+
janus: string,
60+
transaction: string,
61+
body?: any,
62+
jsep?: JSEP,
1663
}
1764

1865
enum DebugLevel {
1966
Trace = 'trace',
67+
vDebug = 'vdebug',
2068
Debug = 'debug',
2169
Log = 'log',
2270
Warning = 'warn',
23-
Error = 'error'
71+
Error = 'error',
2472
}
2573

2674
interface JSEP {
27-
ee2e?: boolean;
75+
e2ee?: boolean;
2876
sdp?: string;
2977
type?: string;
3078
rid_order?: "hml" | "lmh";
@@ -49,6 +97,10 @@ declare namespace JanusJS {
4997
success?: Function;
5098
error?: (error: any) => void;
5199
destroyed?: Function;
100+
iceTransportPolicy?: RTCIceTransportPolicy;
101+
bundlePolicy?: RTCBundlePolicy;
102+
keepAlivePeriod?: number;
103+
longPollTimeout?: number;
52104
}
53105

54106
interface ReconnectOptions {
@@ -110,9 +162,19 @@ declare namespace JanusJS {
110162
interface PluginOptions extends PluginCallbacks {
111163
plugin: string;
112164
opaqueId?: string;
165+
token?: string;
166+
loopIndex?: number;
113167
}
114168

115169
interface OfferParams {
170+
tracks?: TrackOption[];
171+
trickle?: boolean;
172+
iceRestart?: boolean;
173+
success?: (jsep: JSEP) => void;
174+
error?: (error: Error) => void;
175+
customizeSdp?: (jsep: JSEP) => void;
176+
177+
/** @deprecated use tracks instead */
116178
media?: {
117179
audioSend?: boolean;
118180
audioRecv?: boolean;
@@ -133,10 +195,6 @@ declare namespace JanusJS {
133195
failIfNoVideo?: boolean;
134196
screenshareFrameRate?: number;
135197
};
136-
trickle?: boolean;
137-
stream?: MediaStream;
138-
success: Function;
139-
error: (error: any) => void;
140198
}
141199

142200
interface PluginMessage {
@@ -158,10 +216,10 @@ declare namespace JanusJS {
158216
tsnow: string | null;
159217
value: string | null;
160218
};
161-
dataChannel: Array<RTCDataChannel>;
219+
dataChannel: { [key in string]: RTCDataChannel };
162220
dataChannelOptions: RTCDataChannelInit;
163221

164-
dtmfSender: string | null;
222+
dtmfSender: RTCDTMFSender
165223
iceDone: boolean;
166224
mediaConstraints: any;
167225
mySdp: {
@@ -187,12 +245,91 @@ declare namespace JanusJS {
187245
value: number;
188246
timer: number;
189247
};
248+
249+
sdpSent: boolean,
250+
insertableStreams?: any,
251+
candidates: RTCIceCandidateInit[],
252+
}
253+
254+
type PluginCreateAnswerParam = {
255+
jsep: JSEP;
256+
tracks?: TrackOption[];
257+
258+
/** @deprecated use tracks instead */
259+
media?: { audioSend: any, videoSend: any };
260+
success?: (data: JSEP) => void;
261+
error?: (error: string) => void;
262+
}
263+
264+
type PluginHandleRemoteJsepParam = {
265+
jsep: JSEP;
266+
success?: (data: JSEP) => void;
267+
error?: (error: string) => void;
268+
}
269+
270+
type PluginReplaceTracksParam = {
271+
tracks: TrackOption[];
272+
success?: (data: unknown) => void;
273+
error?: (error: string) => void;
274+
}
275+
276+
type TrackOption = {
277+
add?: boolean;
278+
replace?: boolean;
279+
remove?: boolean;
280+
type: 'video' | 'screen' | 'audio' | 'data';
281+
mid?: string;
282+
capture: boolean | MediaStreamTrack;
283+
recv?: boolean;
284+
group?: 'default' | string;
285+
gumGroup?: TrackOption['group'];
286+
simulcast?: boolean;
287+
svc?: string;
288+
simulcastMaxBitrates?: {
289+
low: number;
290+
medium: number;
291+
high: number;
292+
};
293+
sendEncodings?: RTCRtpEncodingParameters;
294+
framerate?: number;
295+
bitrate?: number;
296+
dontStop?: boolean;
297+
transforms?: {
298+
sender: ReadableWritablePair;
299+
receiver: ReadableWritablePair;
300+
};
301+
}
302+
303+
type PluginDtmfParam = {
304+
dtmf: Dtmf;
305+
success?: (data: unknown) => void;
306+
error?: (error: string) => void;
307+
}
308+
309+
type Dtmf = {
310+
tones: string;
311+
duration: number;
312+
gap: number;
313+
}
314+
315+
type PluginDataParam = {
316+
success?: (data: unknown) => void;
317+
error?: (error: string) => void;
318+
}
319+
320+
type TrackDesc = {
321+
mid?: string
322+
type?: string
323+
id?: string
324+
label?: string
190325
}
326+
191327
interface DetachOptions {
192328
success?: () => void;
193329
error?: (error: string) => void;
194330
noRequest?: boolean;
195331
}
332+
196333
interface PluginHandle {
197334
plugin: string;
198335
id: string;
@@ -201,28 +338,35 @@ declare namespace JanusJS {
201338
webrtcStuff: WebRTCInfo;
202339
getId(): string;
203340
getPlugin(): string;
204-
send(message: PluginMessage): void;
205-
createOffer(params: OfferParams): void;
206-
createAnswer(params: any): void;
207-
handleRemoteJsep(params: { jsep: JSEP }): void;
208-
dtmf(params: any): void;
209-
data(params: any): void;
341+
getVolume(mid: string, callback: (result: number) => void): void;
342+
getRemoteVolume(mid: string, callback: (result: number) => void): void;
343+
getLocalVolume(mid: string, callback: (result: number) => void): void;
210344
isAudioMuted(): boolean;
211345
muteAudio(): void;
212346
unmuteAudio(): void;
213347
isVideoMuted(): boolean;
214348
muteVideo(): void;
215349
unmuteVideo(): void;
216350
getBitrate(): string;
351+
setMaxBitrate(bitrate: number): void;
352+
send(message: PluginMessage): void;
353+
data(params: PluginDataParam): void;
354+
dtmf(params: PluginDtmfParam): void;
355+
createOffer(params: OfferParams): void;
356+
createAnswer(params: PluginCreateAnswerParam): void;
357+
handleRemoteJsep(params: PluginHandleRemoteJsepParam): void;
358+
replaceTracks(params: PluginReplaceTracksParam): void;
359+
getLocalTracks(): TrackDesc[];
360+
getRemoteTracks(): TrackDesc[];
217361
hangup(sendRequest?: boolean): void;
218362
detach(params?: DetachOptions): void;
219363
}
220364

221365
class Janus {
222366
static webRTCAdapter: any;
223367
static safariVp8: boolean;
224-
static useDefaultDependencies(deps: Partial<Dependencies>): DependenciesResult;
225-
static useOldDependencies(deps: Partial<Dependencies>): DependenciesResult;
368+
static useDefaultDependencies(deps?: Partial<DefaultDependencies>): DependenciesResult;
369+
static useOldDependencies(deps?: Partial<OldDependencies>): DependenciesResult;
226370
static init(options: InitOptions): void;
227371
static isWebrtcSupported(): boolean;
228372
static debug(...args: any[]): void;

0 commit comments

Comments
 (0)