2022-02-16 21:31:02 +05:30
|
|
|
/*
|
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-04-13 00:50:24 +05:30
|
|
|
import {Track, Stream} from "./MediaDevices";
|
2022-02-25 21:24:00 +05:30
|
|
|
import {SDPStreamMetadataPurpose} from "../../matrix/calls/callEventTypes";
|
2022-02-16 21:31:02 +05:30
|
|
|
|
|
|
|
export interface WebRTC {
|
2022-04-13 22:04:01 +05:30
|
|
|
createPeerConnection(handler: PeerConnectionHandler, forceTURN: boolean, turnServers: RTCIceServer[], iceCandidatePoolSize: number): PeerConnection;
|
2022-02-16 21:31:02 +05:30
|
|
|
}
|
|
|
|
|
2022-04-13 00:50:24 +05:30
|
|
|
export interface StreamSender {
|
|
|
|
get stream(): Stream;
|
|
|
|
get audioSender(): TrackSender | undefined;
|
|
|
|
get videoSender(): TrackSender | undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface StreamReceiver {
|
|
|
|
get stream(): Stream;
|
|
|
|
get audioReceiver(): TrackReceiver | undefined;
|
|
|
|
get videoReceiver(): TrackReceiver | undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TrackReceiver {
|
|
|
|
get track(): Track;
|
|
|
|
get enabled(): boolean;
|
|
|
|
enable(enabled: boolean); // this modifies the transceiver direction
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TrackSender extends TrackReceiver {
|
|
|
|
/** replaces the track if possible without renegotiation. Can throw. */
|
2022-04-13 22:04:01 +05:30
|
|
|
replaceTrack(track: Track | undefined): Promise<void>;
|
2022-04-13 00:50:24 +05:30
|
|
|
/** make any needed adjustments to the sender or transceiver settings
|
|
|
|
* depending on the purpose, after adding the track to the connection */
|
|
|
|
prepareForPurpose(purpose: SDPStreamMetadataPurpose): void;
|
|
|
|
}
|
|
|
|
|
2022-02-16 21:31:02 +05:30
|
|
|
export interface PeerConnectionHandler {
|
|
|
|
onIceConnectionStateChange(state: RTCIceConnectionState);
|
|
|
|
onLocalIceCandidate(candidate: RTCIceCandidate);
|
|
|
|
onIceGatheringStateChange(state: RTCIceGatheringState);
|
2022-04-13 00:50:24 +05:30
|
|
|
onRemoteStreamRemoved(stream: Stream);
|
|
|
|
onRemoteTracksAdded(receiver: TrackReceiver);
|
2022-04-11 19:23:34 +05:30
|
|
|
onRemoteDataChannel(dataChannel: any | undefined);
|
2022-02-16 21:31:02 +05:30
|
|
|
onNegotiationNeeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface PeerConnection {
|
2022-02-25 21:24:00 +05:30
|
|
|
get iceGatheringState(): RTCIceGatheringState;
|
2022-03-02 18:23:22 +05:30
|
|
|
get signalingState(): RTCSignalingState;
|
2022-02-25 21:24:00 +05:30
|
|
|
get localDescription(): RTCSessionDescription | undefined;
|
2022-04-13 22:04:01 +05:30
|
|
|
get localStreams(): ReadonlyMap<string, StreamSender>;
|
|
|
|
get remoteStreams(): ReadonlyMap<string, StreamReceiver>;
|
2022-02-16 21:31:02 +05:30
|
|
|
createOffer(): Promise<RTCSessionDescriptionInit>;
|
|
|
|
createAnswer(): Promise<RTCSessionDescriptionInit>;
|
2022-02-18 21:08:10 +05:30
|
|
|
setLocalDescription(description?: RTCSessionDescriptionInit): Promise<void>;
|
2022-02-17 21:28:44 +05:30
|
|
|
setRemoteDescription(description: RTCSessionDescriptionInit): Promise<void>;
|
|
|
|
addIceCandidate(candidate: RTCIceCandidate): Promise<void>;
|
2022-04-13 00:50:24 +05:30
|
|
|
addTrack(track: Track): TrackSender | undefined;
|
|
|
|
removeTrack(track: TrackSender): void;
|
2022-04-11 19:23:34 +05:30
|
|
|
createDataChannel(options: RTCDataChannelInit): any;
|
2022-02-18 21:08:10 +05:30
|
|
|
dispose(): void;
|
2022-03-02 18:23:22 +05:30
|
|
|
close(): void;
|
2022-02-16 21:31:02 +05:30
|
|
|
}
|