mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-28 16:45:10 +08:00
webrtc: Require typescript@2.3 and rely on lib.dom.d.ts types (#20242)
This commit is contained in:
1
types/peerjs/index.d.ts
vendored
1
types/peerjs/index.d.ts
vendored
@@ -2,6 +2,7 @@
|
||||
// Project: http://peerjs.com/
|
||||
// Definitions by: Toshiya Nakakura <https://github.com/nakakura>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="webrtc" />
|
||||
|
||||
|
||||
1
types/skyway/index.d.ts
vendored
1
types/skyway/index.d.ts
vendored
@@ -2,6 +2,7 @@
|
||||
// Project: http://nttcom.github.io/skyway/
|
||||
// Definitions by: Toshiya Nakakura <https://github.com/nakakura>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="webrtc" />
|
||||
|
||||
|
||||
5
types/webrtc/MediaStream.d.ts
vendored
5
types/webrtc/MediaStream.d.ts
vendored
@@ -101,11 +101,6 @@ interface MediaStreamTrackEvent extends Event {
|
||||
//track: MediaStreamTrack;
|
||||
}
|
||||
|
||||
declare enum MediaStreamTrackState {
|
||||
"live",
|
||||
"ended"
|
||||
}
|
||||
|
||||
interface MediaStreamTrack extends EventTarget {
|
||||
//id: string;
|
||||
//kind: string;
|
||||
|
||||
132
types/webrtc/RTCPeerConnection.d.ts
vendored
132
types/webrtc/RTCPeerConnection.d.ts
vendored
@@ -27,74 +27,6 @@ interface RTCOfferOptions extends RTCOfferAnswerOptions {
|
||||
interface RTCAnswerOptions extends RTCOfferAnswerOptions {
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcsdptype
|
||||
type RTCSdpType = 'offer' | 'pranswer' | 'answer' | 'rollback';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcsessiondescriptioninit
|
||||
interface RTCSessionDescriptionInit {
|
||||
type: RTCSdpType;
|
||||
sdp?: string; // If type is 'rollback', this member can be left undefined.
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcsessiondescription
|
||||
interface RTCSessionDescription {
|
||||
readonly type: RTCSdpType;
|
||||
readonly sdp: string;
|
||||
}
|
||||
interface RTCSessionDescriptionStatic {
|
||||
new(descriptionInitDict: RTCSessionDescriptionInit): RTCSessionDescription; // Deprecated
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#dom-rtciceprotocol
|
||||
type RTCIceProtocol = 'udp' | 'tcp';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#dom-rtcicecandidatetype
|
||||
type RTCIceCandidateType = 'host' | 'srflx' | 'prflx' | 'relay';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#dom-rtcicetcpcandidatetype
|
||||
type RTCIceTcpCandidateType = 'active' | 'passive' | 'so';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcicecandidateinit
|
||||
interface RTCIceCandidateInit {
|
||||
candidate: string;
|
||||
sdpMid?: string; // default = null
|
||||
sdpMLineIndex?: number; // default = null
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcicecandidate
|
||||
interface RTCIceCandidate {
|
||||
readonly candidate: string;
|
||||
readonly sdpMid?: string;
|
||||
readonly sdpMLineIndex?: number;
|
||||
//readonly foundation: string;
|
||||
//readonly priority: number;
|
||||
//readonly ip: string;
|
||||
//readonly protocol: RTCIceProtocol;
|
||||
//readonly port: number;
|
||||
//readonly type: RTCIceCandidateType;
|
||||
//readonly tcpType?: RTCIceTcpCandidateType;
|
||||
//readonly relatedAddress?: string;
|
||||
//readonly relatedPort?: number;
|
||||
}
|
||||
interface RTCIceCandidateStatic {
|
||||
new(candidateInitDict: RTCIceCandidateInit): RTCIceCandidate;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcicecandidatepair
|
||||
interface RTCIceCandidatePair {
|
||||
//local: RTCIceCandidate;
|
||||
//remote: RTCIceCandidate;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcsignalingstate
|
||||
type RTCSignalingState = 'stable' | 'have-local-offer' | 'have-remote-offer' | 'have-local-pranswer' | 'have-remote-pranswer';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcicegatheringstate
|
||||
type RTCIceGatheringState = 'new' | 'gathering' | 'complete';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtciceconnectionstate
|
||||
type RTCIceConnectionState = 'new' | 'checking' | 'connected' | 'completed' | 'failed' | 'disconnected' | 'closed';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcpeerconnectionstate
|
||||
type RTCPeerConnectionState = 'new' | 'connecting' | 'connected' | 'disconnected' | 'failed' | 'closed';
|
||||
|
||||
@@ -104,29 +36,12 @@ type RTCIceCredentialType = 'password' | 'token';
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtciceserver
|
||||
interface RTCIceServer {
|
||||
//urls: string | string[];
|
||||
username?: string;
|
||||
credential?: string;
|
||||
credentialType?: RTCIceCredentialType; // default = 'password'
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcicetransportpolicy
|
||||
type RTCIceTransportPolicy = 'relay' | 'all';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcbundlepolicy
|
||||
type RTCBundlePolicy = 'balanced' | 'max-compat' | 'max-bundle';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcrtcpmuxpolicy
|
||||
type RTCRtcpMuxPolicy = 'negotiate' | 'require';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcicerole
|
||||
type RTCIceRole = 'controlling' | 'controlled';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcicecomponent
|
||||
type RTCIceComponent = 'RTP' | 'RTCP';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcicetransportstate
|
||||
type RTCIceTransportState = 'new' | 'checking' | 'connected' | 'completed' | 'failed' | 'disconnected' | 'closed';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtciceparameters
|
||||
interface RTCIceParameters {
|
||||
//usernameFragment: string;
|
||||
@@ -149,9 +64,6 @@ interface RTCIceTransport {
|
||||
onselectedcandidatepairchange: EventHandler;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcdtlstransportstate
|
||||
type RTCDtlsTransportState = 'new' | 'connecting' | 'connected' | 'closed' | 'failed';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcdtlstransport
|
||||
interface RTCDtlsTransport {
|
||||
readonly transport: RTCIceTransport;
|
||||
@@ -201,7 +113,6 @@ interface RTCRtpEncodingParameters {
|
||||
//active: boolean;
|
||||
//priority: RTCPriorityType;
|
||||
//maxBitrate: number;
|
||||
maxFramerate: number;
|
||||
rid: string;
|
||||
scaleResolutionDownBy?: number; // default = 1
|
||||
}
|
||||
@@ -228,8 +139,6 @@ interface RTCRtpCodecParameters {
|
||||
sdpFmtpLine: string;
|
||||
}
|
||||
|
||||
type RTCDegradationPreference = 'maintain-framerate' | 'maintain-resolution' | 'balanced';
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcrtpparameters
|
||||
interface RTCRtpParameters {
|
||||
transactionId: string;
|
||||
@@ -263,10 +172,6 @@ interface RTCRtpSender {
|
||||
getParameters(): RTCRtpParameters;
|
||||
replaceTrack(withTrack: MediaStreamTrack): Promise<void>;
|
||||
}
|
||||
interface RTCRtpSenderStatic {
|
||||
new(): RTCRtpSender;
|
||||
getCapabilities(kind: string): RTCRtpCapabilities;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcrtpreceiver
|
||||
interface RTCRtpReceiver {
|
||||
@@ -276,10 +181,6 @@ interface RTCRtpReceiver {
|
||||
getParameters(): RTCRtpParameters;
|
||||
getContributingSources(): RTCRtpContributingSource[];
|
||||
}
|
||||
interface RTCRtpReceiverStatic {
|
||||
new(): RTCRtpReceiver;
|
||||
getCapabilities(kind: string): RTCRtcCapabilities;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcrtptransceiverdirection
|
||||
type RTCRtpTransceiverDirection = 'sendrecv' | 'sendonly' | 'recvonly' | 'inactive';
|
||||
@@ -379,7 +280,6 @@ interface RTCTrackEvent extends Event {
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#h-rtcpeerconnectioniceevent
|
||||
interface RTCPeerConnectionIceEvent extends Event {
|
||||
readonly candidate: RTCIceCandidate | null;
|
||||
readonly url: string;
|
||||
}
|
||||
|
||||
@@ -396,18 +296,6 @@ interface RTCDataChannelEvent {
|
||||
readonly channel: RTCDataChannel;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcsessiondescriptioncallback
|
||||
// Deprecated!
|
||||
type RTCSessionDescriptionCallback = (sdp: RTCSessionDescription) => void;
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcpeerconnectionerrorcallback
|
||||
// Deprecated!
|
||||
type RTCPeerConnectionErrorCallback = (error: DOMException) => void;
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcstatscallback
|
||||
// Deprecated!
|
||||
type RTCStatsCallback = (report: RTCStatsReport) => void;
|
||||
|
||||
// https://www.w3.org/TR/webrtc/#idl-def-rtcpeerconnection
|
||||
interface RTCPeerConnection extends EventTarget {
|
||||
createOffer(options?: RTCOfferOptions): Promise<RTCSessionDescriptionInit>;
|
||||
@@ -426,21 +314,12 @@ interface RTCPeerConnection extends EventTarget {
|
||||
addIceCandidate(candidate?: RTCIceCandidateInit | RTCIceCandidate): Promise<void>;
|
||||
|
||||
readonly signalingState: RTCSignalingState;
|
||||
readonly iceGatheringState: RTCIceGatheringState;
|
||||
readonly iceConnectionState: RTCIceConnectionState;
|
||||
readonly connectionState: RTCPeerConnectionState;
|
||||
readonly canTrickleIceCandidates?: boolean | null;
|
||||
|
||||
getConfiguration(): RTCConfiguration;
|
||||
setConfiguration(configuration: RTCConfiguration): void;
|
||||
close(): void;
|
||||
|
||||
onnegotiationneeded: EventHandler;
|
||||
onicecandidate: (event: RTCPeerConnectionIceEvent) => void;
|
||||
onicecandidateerror: (event: RTCPeerConnectionIceErrorEvent) => void;
|
||||
onsignalingstatechange: EventHandler;
|
||||
oniceconnectionstatechange: EventHandler;
|
||||
onicegatheringstatechange: EventHandler;
|
||||
onconnectionstatechange: EventHandler;
|
||||
|
||||
// Extension: https://www.w3.org/TR/webrtc/#h-rtcpeerconnection-interface-extensions
|
||||
@@ -455,7 +334,7 @@ interface RTCPeerConnection extends EventTarget {
|
||||
// Extension: https://www.w3.org/TR/webrtc/#h-rtcpeerconnection-interface-extensions-1
|
||||
readonly sctp: RTCSctpTransport | null;
|
||||
createDataChannel(label: string | null, dataChannelDict?: RTCDataChannelInit): RTCDataChannel;
|
||||
ondatachannel: (event: RTCDataChannelEvent) => void;
|
||||
ondatachannel: (event: RTCDataChannelEvent) => void;
|
||||
|
||||
// Extension: https://www.w3.org/TR/webrtc/#h-rtcpeerconnection-interface-extensions-2
|
||||
getStats(selector?: MediaStreamTrack | null): Promise<RTCStatsReport>;
|
||||
@@ -488,15 +367,6 @@ interface RTCPeerConnectionStatic {
|
||||
generateCertificate(keygenAlgorithm: string): Promise<RTCCertificate>;
|
||||
}
|
||||
|
||||
declare var RTCPeerConnection: RTCPeerConnectionStatic;
|
||||
declare var RTCSessionDescription: RTCSessionDescriptionStatic;
|
||||
declare var RTCIceCandidate: RTCIceCandidateStatic;
|
||||
//declare var RTCRtpSender: RTCRtpSenderStatic;
|
||||
//declare var RTCRtpReceiver: RTCRtpReceiverStatic;
|
||||
interface Window {
|
||||
RTCPeerConnection: RTCPeerConnectionStatic;
|
||||
RTCSessionDescription: RTCSessionDescriptionStatic;
|
||||
RTCIceCandidate: RTCIceCandidateStatic;
|
||||
RTCRtpSender: RTCRtpSenderStatic;
|
||||
RTCRtpReceiver: RTCRtpReceiverStatic;
|
||||
}
|
||||
|
||||
1
types/webrtc/index.d.ts
vendored
1
types/webrtc/index.d.ts
vendored
@@ -2,6 +2,7 @@
|
||||
// Project: https://webrtc.org/
|
||||
// Definitions by: Toshiya Nakakura <https://github.com/nakakura>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference path="RTCPeerConnection.d.ts" />
|
||||
/// <reference path="MediaStream.d.ts" />
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
var mediaStreamConstraints: MediaStreamConstraints = { audio: true, video: true };
|
||||
const mediaStreamConstraints: MediaStreamConstraints = { audio: true, video: true };
|
||||
|
||||
var mediaTrackConstraintSet: MediaTrackConstraintSet = {};
|
||||
var mediaTrackConstraintArray: MediaTrackConstraintSet[] = [];
|
||||
var mediaTrackConstraints: MediaTrackConstraints = mediaTrackConstraintSet;
|
||||
var mediaTrackConstraints2: MediaTrackConstraints = { advanced: mediaTrackConstraintArray };
|
||||
const mediaTrackConstraintSet: MediaTrackConstraintSet = {};
|
||||
const mediaTrackConstraintArray: MediaTrackConstraintSet[] = [];
|
||||
const mediaTrackConstraints: MediaTrackConstraints = mediaTrackConstraintSet;
|
||||
const mediaTrackConstraints2: MediaTrackConstraints = { advanced: mediaTrackConstraintArray };
|
||||
|
||||
navigator.getUserMedia(mediaStreamConstraints,
|
||||
stream => {
|
||||
var track: MediaStreamTrack = stream.getTracks()[0];
|
||||
const track: MediaStreamTrack = stream.getTracks()[0];
|
||||
console.log('label:' + track.label);
|
||||
console.log('ended:' + track.readyState);
|
||||
track.onended = (event:Event) => console.log('Track ended');
|
||||
var objectUrl = URL.createObjectURL(stream);
|
||||
track.onended = (event: Event) => console.log('Track ended');
|
||||
const objectUrl = URL.createObjectURL(stream);
|
||||
},
|
||||
error => {
|
||||
console.log('Error message: ' + error.message);
|
||||
@@ -20,25 +20,24 @@ navigator.getUserMedia(mediaStreamConstraints,
|
||||
|
||||
navigator.webkitGetUserMedia(mediaStreamConstraints,
|
||||
stream => {
|
||||
var track: MediaStreamTrack = stream.getTracks()[0];
|
||||
const track: MediaStreamTrack = stream.getTracks()[0];
|
||||
console.log('label:' + track.label);
|
||||
console.log('ended:' + track.readyState);
|
||||
track.onended = (event:Event) => console.log('Track ended');
|
||||
var objectUrl = URL.createObjectURL(stream);
|
||||
track.onended = (event: Event) => console.log('Track ended');
|
||||
const objectUrl = URL.createObjectURL(stream);
|
||||
},
|
||||
error => {
|
||||
console.log('Error message: ' + error.message);
|
||||
console.log('Error name: ' + error.name);
|
||||
});
|
||||
|
||||
|
||||
navigator.mozGetUserMedia(mediaStreamConstraints,
|
||||
stream => {
|
||||
var track: MediaStreamTrack = stream.getTracks()[0];
|
||||
const track: MediaStreamTrack = stream.getTracks()[0];
|
||||
console.log('label:' + track.label);
|
||||
console.log('ended:' + track.readyState);
|
||||
track.onended = (event:Event) => console.log('Track ended');
|
||||
var objectUrl = URL.createObjectURL(stream);
|
||||
track.onended = (event: Event) => console.log('Track ended');
|
||||
const objectUrl = URL.createObjectURL(stream);
|
||||
},
|
||||
error => {
|
||||
console.log('Error message: ' + error.message);
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
let defaultIceServers: RTCIceServer[] = RTCPeerConnection.defaultIceServers;
|
||||
let defaultIceServers: RTCIceServer[] = window.RTCPeerConnection.defaultIceServers;
|
||||
if (defaultIceServers.length > 0) {
|
||||
let urls = defaultIceServers[0].urls;
|
||||
const urls = defaultIceServers[0].urls;
|
||||
}
|
||||
|
||||
// Create a peer connection
|
||||
let ice1: RTCIceServer = {
|
||||
'urls': 'stun:stun.l.google.com:19302',
|
||||
'username': 'john',
|
||||
'credential': '1234',
|
||||
'credentialType': 'password',
|
||||
urls: 'stun:stun.l.google.com:19302',
|
||||
username: 'john',
|
||||
credential: '1234',
|
||||
credentialType: 'password',
|
||||
};
|
||||
let ice2: RTCIceServer = {'urls': ['stun:stunserver.org', 'stun:stun.example.com']};
|
||||
let pc: RTCPeerConnection = new RTCPeerConnection();
|
||||
let ice2: RTCIceServer = { urls: ['stun:stunserver.org', 'stun:stun.example.com'] };
|
||||
let pc: RTCPeerConnection = new RTCPeerConnection({});
|
||||
let pc2: RTCPeerConnection = new RTCPeerConnection({
|
||||
iceServers: [ice1, ice2],
|
||||
});
|
||||
RTCPeerConnection.generateCertificate("sha-256").then((cert: RTCCertificate) => {
|
||||
window.RTCPeerConnection.generateCertificate("sha-256").then((cert: RTCCertificate) => {
|
||||
new RTCPeerConnection({
|
||||
iceServers: [ice1],
|
||||
iceTransportPolicy: 'relay',
|
||||
@@ -35,15 +35,15 @@ pc.setConfiguration(conf);
|
||||
pc2.close();
|
||||
|
||||
// Offer/answer flow
|
||||
let offer: RTCSessionDescriptionInit;
|
||||
let answer: RTCSessionDescriptionInit;
|
||||
pc.createOffer({iceRestart: true})
|
||||
.then((_offer: RTCSessionDescriptionInit) => offer = _offer);
|
||||
pc.setLocalDescription(offer);
|
||||
pc2.setRemoteDescription(offer);
|
||||
pc2.createAnswer().then((_answer: RTCSessionDescriptionInit) => answer = _answer);
|
||||
pc2.setLocalDescription(answer);
|
||||
pc.setRemoteDescription(answer);
|
||||
.then((offer: RTCSessionDescriptionInit) => {
|
||||
pc.setLocalDescription(offer);
|
||||
pc2.setRemoteDescription(offer);
|
||||
pc2.createAnswer().then((answer: RTCSessionDescriptionInit) => {
|
||||
pc2.setLocalDescription(answer);
|
||||
pc.setRemoteDescription(answer);
|
||||
});
|
||||
});
|
||||
|
||||
// Event handlers
|
||||
pc.onnegotiationneeded = ev => console.log(ev.type);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
@@ -18,6 +18,8 @@
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"MediaStream.d.ts",
|
||||
"RTCPeerConnection.d.ts",
|
||||
"test/MediaStream.ts",
|
||||
"test/RTCPeerConnection.ts"
|
||||
]
|
||||
|
||||
13
types/webrtc/tslint.json
Normal file
13
types/webrtc/tslint.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
// TODOs
|
||||
"adjacent-overload-signatures": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"no-empty-interface": false,
|
||||
"no-useless-files": false,
|
||||
"prefer-method-signature": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user