forked from t-mullen/video-stream-merger
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
117 lines (102 loc) · 3.32 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
export as namespace VideoStreamMerger;
export = VideoStreamMerger;
/**
* Merges the video of multiple MediaStreams. Also merges the audio via the WebAudio API.
*
* - Send multiple videos over a single WebRTC MediaConnection
* - Hotswap streams without worrying about renegotation or delays
* - Crop, scale, and rotate live video
* - Add crazy effects through the canvas API
*/
declare class VideoStreamMerger {
/**
* Create a new VideoStreamMerger
*/
constructor(options?: Partial<VideoStreamMerger.ConstructorOptions>);
/**
* The resulting merged MediaStream. Only available after calling merger.start()
* Never has more than one Audio and one Video track.
*/
result: MediaStream;
/**
* Add a MediaStream to be merged. Use an id string if you only want to provide an effect.
* The order that streams are added matters. Streams placed earlier will be behind later streams (use the index option to change this behaviour.)
*/
addStream(
stream: MediaStream | string,
options?: Partial<VideoStreamMerger.AddStreamOptions>
): void;
/**
* A convenience function to merge a HTML5 MediaElement instead of a MediaStream.
*
* id is a string used to remove or update the index of the stream later.
* mediaElement is a playing HTML5 Audio or Video element.
* options are identical to the opts for addStream.
* Streams from MediaElements can be removed via merger.removeStream(id).
*/
addMediaElement(
id: string,
mediaElement: HTMLMediaElement,
options?: Partial<VideoStreamMerger.AddStreamOptions>
): void;
/**
* Update the z-index (draw order) of an already added stream or data object. Identical to the index option.
* If you have added the same MediaStream multiple times, all instances will be updated.
*/
updateIndex(stream: MediaStream | string, newIndex: number): void;
/**
* Remove a MediaStream from the merging. You may also use the ID of the stream.
* If you have added the same MediaStream multiple times, all instances will be removed.
*/
removeStream(stream: MediaStream | string): void;
/**
* Start the merging and create merger.result.
* You can call this any time, but you only need to call it once.
* You will still be able to add/remove streams and the result stream will automatically update.
*/
start(): void;
/**
* Clean up everything and destroy the result stream.
*/
destroy(): void;
/**
* Get the WebAudio AudioContext being used by the merger.
*/
getAudioContext(): AudioContext;
/**
* Get the MediaStreamDestination node that is used by the merger.
*/
getAudioDestination(): MediaStreamAudioDestinationNode;
}
declare namespace VideoStreamMerger {
export interface DrawFunction {
(
context: CanvasRenderingContext2D,
frame: CanvasImageSource,
done: () => void
): void;
}
export interface AudioEffect {
(
sourceNode: AudioNode,
destinationNode: MediaStreamAudioDestinationNode
): void;
}
export interface ConstructorOptions {
width: number;
height: number;
fps: number;
clearRect: boolean;
audioContext: AudioContext;
}
export interface AddStreamOptions {
x: number;
y: number;
width: number;
height: number;
index: number;
mute: boolean;
draw: DrawFunction;
audioEffect: AudioEffect;
}
}