* Added TODOs for things that can be done when/if typescript is improved with links in case people want typescript to be better and want to vote on the issue.

* Removed unused IceState
* Added moz specific prefixes
* Fixed broken use of enum for things that are actually strings and added a TypeScript issue for the fix
* Added comments with WebIDL spec for enums
* Added RTCMessageEvent for data channels
* Support send with ArrayBufferView
This commit is contained in:
Lucas Dixon
2014-06-29 22:53:17 -04:00
parent f57d1bfc3a
commit ec15376306
+105 -50
View File
@@ -2,11 +2,27 @@
// Project: http://dev.w3.org/2011/webrtc/
// Definitions by: Ken Smith <https://github.com/smithkl42/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
//
// Definitions taken from http://dev.w3.org/2011/webrtc/editor/webrtc.html
//
// For example code see:
// https://code.google.com/p/webrtc/source/browse/stable/samples/js/apprtc/js/main.js
//
// For a generic implementation see that deals with browser differences, see:
// https://code.google.com/p/webrtc/source/browse/stable/samples/js/base/adapter.js
/// <reference path="MediaStream.d.ts" />
// TODO(1): Get Typescript to have string-enum types as WebRtc is full of string
// enums.
// https://typescript.codeplex.com/discussions/549207
// TODO(2): get Typescript to have union types as WebRtc uses them.
// https://typescript.codeplex.com/workitem/1364
// TODO(3): Typescript type-abbreviations fail to be structural.
// https://typescript.codeplex.com/workitem/2587
interface RTCConfiguration {
iceServers: RTCIceServer[];
}
@@ -24,6 +40,14 @@ declare var RTCIceServer: {
new (): RTCIceServer;
}
// moz (Firefox) specific prefixes.
interface mozRTCPeerConnection extends RTCPeerConnection {
}
declare var mozRTCPeerConnection: {
prototype: mozRTCPeerConnection;
new (settings: RTCPeerConnectionConfig, constraints?:MediaConstraints): mozRTCPeerConnection;
}
// webkit (Chrome) specific prefixes.
interface webkitRTCPeerConnection extends RTCPeerConnection {
}
declare var webkitRTCPeerConnection: {
@@ -31,13 +55,6 @@ declare var webkitRTCPeerConnection: {
new (settings: RTCPeerConnectionConfig, constraints?:MediaConstraints): webkitRTCPeerConnection;
}
interface IceState {
}
declare var IceState: {
prototype: IceState;
new (): IceState;
}
// For Chrome, look at the code here: https://code.google.com/p/chromium/codesearch#chromium/src/third_party/libjingle/source/talk/app/webrtc/webrtcsession.cc&sq=package:chromium&dr=C&l=63
interface OptionalMediaConstraint {
// When true, will use DTLS/SCTP data channels
@@ -59,7 +76,7 @@ interface MediaOfferConstraints {
}
interface RTCSessionDescription {
type?: RTCSdpType;
type?: string; // RTCSdpType; See TODO(3)
sdp?: string;
}
declare var RTCSessionDescription: {
@@ -68,7 +85,7 @@ declare var RTCSessionDescription: {
}
interface RTCSessionDescriptionInit {
type: RTCSdpType;
type: string; // RTCSdpType; See TODO(3)
sdp: string;
}
declare var RTCSessionDescriptionInit: {
@@ -76,42 +93,57 @@ declare var RTCSessionDescriptionInit: {
new (): RTCSessionDescriptionInit;
}
interface SdpType {
}
interface RTCPeerState {
}
interface RTCDataChannelInit {
reliable: boolean;
ordered ?: boolean; // messages must be sent in-order.
maxPacketLifeTime ?: number; // unsigned short
maxRetransmits ?: number; // unsigned short
protocol ?: string; // default = ''
negotiated ?: boolean; // default = false;
id ?: number; // unsigned short
}
declare enum RTCSdpType {
offer,
pranswer,
answer
interface RTCSdpType {
// http://dev.w3.org/2011/webrtc/editor/webrtc.html#rtcsdptype
// enum RTCSdpType {
// "offer",
// "pranswer",
// "answer"
// };
string;
}
declare enum RTCDataChannelState {
connecting,
open,
closing,
closed
interface RTCMessageEvent {
// http://dev.w3.org/2011/webrtc/editor/webrtc.html#event-datachannel-message
// At present, this can be an: ArrayBuffer, a string, or a Blob.
// See TODO(2)
data: any;
}
interface RTCDataChannelState {
// http://dev.w3.org/2011/webrtc/editor/webrtc.html#idl-def-RTCDataChannelState
// enum RTCDataChannelState {
// "connecting",
// "open",
// "closing",
// "closed"
// };
string;
}
interface RTCDataChannel extends EventTarget {
label: string;
reliable: boolean;
readyState: RTCDataChannelState;
readyState: string; // RTCDataChannelState; see TODO(3)
bufferedAmount: number;
onopen: (event: Event)=> void;
onerror: (event: Event)=> void;
onclose: (event: Event)=> void;
onopen: (event: Event) => void;
onerror: (event: Event) => void;
onclose: (event: Event) => void;
close(): void;
onmessage: (event: Event)=> void;
onmessage: (event: RTCMessageEvent) => void;
binaryType: string;
send(data: string);
send(data: ArrayBuffer);
send(data: ArrayBufferView);
send(data: Blob);
}
declare var RTCDataChannel: {
@@ -128,7 +160,7 @@ declare var RTCDataChannelEvent: {
new (eventInitDict: RTCDataChannelEventInit);
}
interface RTCIceCandidateEvent extends Event{
interface RTCIceCandidateEvent extends Event {
candidate: RTCIceCandidate;
}
@@ -150,21 +182,43 @@ interface RTCSessionDescriptionCallback {
(sdp: RTCSessionDescription): void;
}
interface RTCPeerConnectionErrorCallback {
(errorInformation: string): void;
(errorInformation: DOMError): void;
}
/** This should be an enum */
interface RTCIceGatheringState {
// http://dev.w3.org/2011/webrtc/editor/webrtc.html#rtcicegatheringstate-enum
// enum RTCIceGatheringState {
// "new",
// "gathering",
// "complete"
// };
string;
}
/** This should be an enum */
interface RTCIceConnectionState {
// http://dev.w3.org/2011/webrtc/editor/webrtc.html#idl-def-RTCIceConnectionState
// enum RTCIceConnectionState {
// "new",
// "checking",
// "connected",
// "completed",
// "failed",
// "disconnected",
// "closed"
// };
string;
}
/** This should be an enum */
interface RTCSignalingState{
interface RTCSignalingState {
// http://dev.w3.org/2011/webrtc/editor/webrtc.html#idl-def-RTCSignalingState
// enum RTCSignalingState {
// "stable",
// "have-local-offer",
// "have-remote-offer",
// "have-local-pranswer",
// "have-remote-pranswer",
// "closed"
// };
string;
}
@@ -175,27 +229,28 @@ interface RTCPeerConnection {
localDescription: RTCSessionDescription;
setRemoteDescription(description: RTCSessionDescription, successCallback?: RTCVoidCallback, failureCallback?: RTCPeerConnectionErrorCallback): void;
remoteDescription: RTCSessionDescription;
signalingState: RTCSignalingState;
signalingState: string; // RTCSignalingState; see TODO(3)
updateIce(configuration?: RTCConfiguration, constraints?: MediaConstraints): void;
addIceCandidate(candidate: RTCIceCandidate): void;
iceGatheringState: RTCIceGatheringState;
iceConnectionState: RTCIceConnectionState;
iceGatheringState: string; // RTCIceGatheringState; see TODO(3)
iceConnectionState: string; // RTCIceConnectionState; see TODO(3)
getLocalStreams(): MediaStream[];
getRemoteStreams(): MediaStream[];
createDataChannel(label?: string, dataChannelDict?: RTCDataChannelInit): RTCDataChannel;
ondatachannel: (event: Event)=> void;
ondatachannel: (event: Event) => void;
addStream(stream: MediaStream, constraints?: MediaConstraints): void;
removeStream(stream: MediaStream): void;
close(): void;
onnegotiationneeded: (event: Event)=> void;
onconnecting: (event: Event)=> void;
onopen: (event: Event)=> void;
onaddstream: (event: RTCMediaStreamEvent)=> void;
onremovestream: (event: RTCMediaStreamEvent)=> void;
onstatechange: (event: Event)=> void;
onicechange: (event: Event)=> void;
onicecandidate: (event: RTCIceCandidateEvent)=> void;
onidentityresult: (event: Event)=> void;
onnegotiationneeded: (event: Event) => void;
onconnecting: (event: Event) => void;
onopen: (event: Event) => void;
onaddstream: (event: RTCMediaStreamEvent) => void;
onremovestream: (event: RTCMediaStreamEvent) => void;
onstatechange: (event: Event) => void;
onicechange: (event: Event) => void;
onicecandidate: (event: RTCIceCandidateEvent) => void;
onidentityresult: (event: Event) => void;
onsignalingstatechange: (event: Event) => void;
}
declare var RTCPeerConnection: {
prototype: RTCPeerConnection;