2 * Copyright 2012 The Closure Compiler Authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @fileoverview Definitions for components of the WebRTC browser API.
19 * @see http://dev.w3.org/2011/webrtc/editor/webrtc.html
20 * @see http://tools.ietf.org/html/draft-ietf-rtcweb-jsep-01
21 * @see http://www.w3.org/TR/mediacapture-streams/
24 * @author bemasc@google.com (Benjamin M. Schwartz)
29 * @see {http://dev.w3.org/2011/webrtc/editor/getusermedia.html
30 * #idl-def-MediaStreamTrackState}
31 * In WebIDL this is an enum with values 'live', 'mute', and 'ended',
32 * but there is no mechanism in Closure for describing a specialization of
35 var MediaStreamTrackState;
40 function SourceInfo() {}
42 /** @const {string} */
43 SourceInfo.prototype.kind;
45 /** @const {string} */
46 SourceInfo.prototype.id;
48 /** @const {?string} */
49 SourceInfo.prototype.label;
51 /** @const {boolean} */
52 SourceInfo.prototype.facing;
56 * @see http://www.w3.org/TR/mediacapture-streams/#mediastreamtrack
58 function MediaStreamTrack() {}
61 * @param {!function(!Array.<!SourceInfo>)} callback
63 MediaStreamTrack.getSources = function(callback) {};
69 MediaStreamTrack.prototype.kind;
75 MediaStreamTrack.prototype.id;
81 MediaStreamTrack.prototype.label;
86 MediaStreamTrack.prototype.enabled;
89 * @type {MediaStreamTrackState}
92 MediaStreamTrack.prototype.readyState;
95 * @type {?function(!Event)}
97 MediaStreamTrack.prototype.onmute;
100 * @type {?function(!Event)}
102 MediaStreamTrack.prototype.onunmute;
105 * @type {?function(!Event)}
107 MediaStreamTrack.prototype.onended;
110 * @return {!MediaStreamTrack}
112 MediaStreamTrack.prototype.clone = function() {};
114 /** @return {void} */
115 MediaStreamTrack.prototype.stop = function() {};
121 * @see http://dev.w3.org/2011/webrtc/editor/
122 * webrtc-20120720.html#mediastreamtrackevent
123 * TODO(bemasc): Update this link to the final definition once one exists
124 * (https://www.w3.org/Bugs/Public/show_bug.cgi?id=19568)
126 function MediaStreamTrackEvent() {}
129 * @type {!MediaStreamTrack}
132 MediaStreamTrackEvent.prototype.track;
135 * @param {!MediaStream|!Array.<!MediaStreamTrack>=} streamOrTracks
137 * @implements {EventTarget}
138 * @see http://www.w3.org/TR/mediacapture-streams/#mediastream
140 function MediaStream(streamOrTracks) {}
143 * @param {boolean=} opt_useCapture
146 MediaStream.prototype.addEventListener = function(type, listener,
150 * @param {boolean=} opt_useCapture
153 MediaStream.prototype.removeEventListener = function(type, listener,
157 MediaStream.prototype.dispatchEvent = function(evt) {};
160 * TODO(bemasc): Remove this property.
165 MediaStream.prototype.label;
171 MediaStream.prototype.id;
174 * @return {!Array.<!MediaStreamTrack>}
176 MediaStream.prototype.getAudioTracks = function() {};
179 * @return {!Array.<!MediaStreamTrack>}
181 MediaStream.prototype.getVideoTracks = function() {};
184 * @param {string} trackId
185 * @return {MediaStreamTrack}
187 MediaStream.prototype.getTrackById = function(trackId) {};
190 * @param {!MediaStreamTrack} track
192 MediaStream.prototype.addTrack = function(track) {};
195 * @param {!MediaStreamTrack} track
197 MediaStream.prototype.removeTrack = function(track) {};
202 MediaStream.prototype.ended;
205 * @type {?function(!Event)}
207 MediaStream.prototype.onended;
210 * @type {?function(!MediaStreamTrackEvent)}
212 MediaStream.prototype.onaddtrack;
215 * @type {?function(!MediaStreamTrackEvent)}
217 MediaStream.prototype.onremovetrack;
221 * TODO(bemasc): Remove this method once browsers have updated to
222 * MediaStreamTrack.stop().
224 MediaStream.prototype.stop = function() {};
227 * @type {function(new: MediaStream,
228 * (!MediaStream|!Array.<!MediaStreamTrack>)=)}
230 var webkitMediaStream;
233 * This interface defines the available constraint attributes. These are the
234 * attributes defined in
235 * {@see http://tools.ietf.org/html/draft-alvestrand-constraints-resolution-01}.
236 * Note that although that draft refers to "Media Constraints", the W3C uses
237 * the terms "Media[Stream|Track]Constraints" for this type, and
238 * defines a different type (for RTCPeerConnection) called "MediaConstraints".
240 * This interface type is not part of any standard, so it is marked as private.
241 * It is defined here in order to reserve the property names, which would
242 * otherwise be rewritten when the compiler processes an object literal.
243 * Several subsequent interfaces are defined in the same pattern.
245 * Note that although this list includes all the properties supported by
246 * libjingle (and hence by Chromium), browsers are permitted to offer other
247 * properties as well ({
248 * @see http://tools.ietf.org/html/draft-burnett-rtcweb-constraints-registry-02
249 * }), and browsers are expected to silently ignore unknown properties. This
250 * creates the potential for a very confusing situation in which properties
251 * not listed here are renamed by the compiler and then ignored by the browser.
256 function MediaTrackConstraintSetInterface_() {}
261 MediaTrackConstraintSetInterface_.prototype.minWidth;
266 MediaTrackConstraintSetInterface_.prototype.maxWidth;
271 MediaTrackConstraintSetInterface_.prototype.minHeight;
276 MediaTrackConstraintSetInterface_.prototype.maxHeight;
281 MediaTrackConstraintSetInterface_.prototype.minAspectRatio;
286 MediaTrackConstraintSetInterface_.prototype.maxAspectRatio;
289 * Due to a typo, this is called "minFramerate" in the -01 draft.
292 MediaTrackConstraintSetInterface_.prototype.minFrameRate;
297 MediaTrackConstraintSetInterface_.prototype.maxFrameRate;
300 * This type and two more below are defined as unions with Object because they
301 * are normally used as record types by constructing an Object literal, but all
302 * of their properties are optional.
303 * @typedef {Object|MediaTrackConstraintSetInterface_}
305 var MediaTrackConstraintSet;
311 function MediaTrackConstraintsInterface_() {}
314 * @type {?MediaTrackConstraintSet}
316 MediaTrackConstraintsInterface_.prototype.mandatory;
319 * @type {?Array.<!MediaTrackConstraintSet>}
321 MediaTrackConstraintsInterface_.prototype.optional;
324 * @typedef {Object|MediaTrackConstraintsInterface_}
326 var MediaTrackConstraints;
332 function MediaStreamConstraintsInterface_() {}
335 * @type {boolean|MediaTrackConstraints}
337 MediaStreamConstraintsInterface_.prototype.audio;
340 * @type {boolean|MediaTrackConstraints}
342 MediaStreamConstraintsInterface_.prototype.video;
345 * @typedef {Object|MediaStreamConstraintsInterface_}
347 var MediaStreamConstraints;
350 * @see {http://dev.w3.org/2011/webrtc/editor/getusermedia.html#
351 * navigatorusermediaerror-and-navigatorusermediaerrorcallback}
354 function NavigatorUserMediaError() {}
358 * @deprecated Removed from the standard and some browsers.
361 NavigatorUserMediaError.prototype.PERMISSION_DENIED; /** 1 */
365 * @deprecated Removed from the standard and some browsers.
368 NavigatorUserMediaError.prototype.code;
374 NavigatorUserMediaError.prototype.name;
380 NavigatorUserMediaError.prototype.message;
386 NavigatorUserMediaError.prototype.constraintName;
389 * @param {MediaStreamConstraints} constraints A MediaStreamConstraints object.
390 * @param {function(!MediaStream)} successCallback
391 * A NavigatorUserMediaSuccessCallback function.
392 * @param {function(!NavigatorUserMediaError)=} errorCallback A
393 * NavigatorUserMediaErrorCallback function.
394 * @see http://dev.w3.org/2011/webrtc/editor/getusermedia.html
395 * @see http://www.w3.org/TR/mediacapture-streams/
397 Navigator.prototype.webkitGetUserMedia =
398 function(constraints, successCallback, errorCallback) {};
401 * @param {string} type
402 * @param {!Object} eventInitDict
405 function MediaStreamEvent(type, eventInitDict) {}
408 * @type {?MediaStream}
411 MediaStreamEvent.prototype.stream;
415 * @see http://www.w3.org/TR/webrtc/#rtcsdptype
416 * In WebIDL this is an enum with values 'offer', 'pranswer', and 'answer',
417 * but there is no mechanism in Closure for describing a specialization of
423 * @param {!Object=} descriptionInitDict The RTCSessionDescriptionInit
424 * dictionary. This optional argument may have type
425 * {type:RTCSdpType, sdp:string}, but neither of these keys are required to be
426 * present, and other keys are ignored, so the closest Closure type is Object.
428 * @see http://dev.w3.org/2011/webrtc/editor/webrtc.html#rtcsessiondescription-class
430 function RTCSessionDescription(descriptionInitDict) {}
433 * @type {?RTCSdpType}
434 * @see http://www.w3.org/TR/webrtc/#widl-RTCSessionDescription-type
436 RTCSessionDescription.prototype.type;
440 * @see http://www.w3.org/TR/webrtc/#widl-RTCSessionDescription-sdp
442 RTCSessionDescription.prototype.sdp;
445 * TODO(bemasc): Remove this definition once it is removed from the browser.
446 * @param {string} label The label index (audio/video/data -> 0,1,2)
447 * @param {string} sdp The ICE candidate in SDP text form
450 function IceCandidate(label, sdp) {}
455 IceCandidate.prototype.toSdp = function() {};
460 IceCandidate.prototype.label;
463 * @param {!Object=} candidateInitDict The RTCIceCandidateInit dictionary.
464 * This optional argument may have type
465 * {candidate: string, sdpMid: string, sdpMLineIndex:number}, but none of
466 * these keys are required to be present, and other keys are ignored, so the
467 * closest Closure type is Object.
469 * @see http://www.w3.org/TR/webrtc/#rtcicecandidate-type
471 function RTCIceCandidate(candidateInitDict) {}
476 RTCIceCandidate.prototype.candidate;
481 RTCIceCandidate.prototype.sdpMid;
486 RTCIceCandidate.prototype.sdpMLineIndex;
489 * @typedef {{url: string}}
491 * @see http://www.w3.org/TR/webrtc/#rtciceserver-type
492 * This dictionary type also has an optional key {credential: ?string}.
494 var RTCIceServerRecord_;
500 function RTCIceServerInterface_() {}
505 RTCIceServerInterface_.prototype.url;
510 RTCIceServerInterface_.prototype.credential;
513 * This type, and several below it, are constructed as unions between records
515 * @typedef {RTCIceServerRecord_|RTCIceServerInterface_}
521 * @typedef {{iceServers: !Array.<!RTCIceServer>}}
524 var RTCConfigurationRecord_;
530 function RTCConfigurationInterface_() {}
533 * @type {!Array.<!RTCIceServer>}
535 RTCConfigurationInterface_.prototype.iceServers;
538 * @typedef {RTCConfigurationRecord_|RTCConfigurationInterface_}
540 var RTCConfiguration;
543 * @typedef {function(!RTCSessionDescription)}
545 var RTCSessionDescriptionCallback;
548 * @typedef {function(string)}
550 var RTCPeerConnectionErrorCallback;
553 * @typedef {function()}
560 var RTCSignalingState;
565 var RTCIceConnectionState;
570 var RTCIceGatheringState;
573 * @param {string} type
574 * @param {!Object} eventInitDict
577 function RTCPeerConnectionIceEvent(type, eventInitDict) {}
580 * @type {RTCIceCandidate}
583 RTCPeerConnectionIceEvent.prototype.candidate;
585 // Note: The specification of RTCStats types is still under development.
586 // Declarations here will be updated and removed to follow the development of
587 // modern browsers, breaking compatibility with older versions as they become
592 function RTCStatsReport() {}
598 RTCStatsReport.prototype.timestamp;
601 * @return {!Array.<!string>}
603 RTCStatsReport.prototype.names = function() {};
606 * @param {string} name
609 RTCStatsReport.prototype.stat = function(name) {};
613 * @type {RTCStatsReport}
616 RTCStatsReport.prototype.local;
620 * @type {RTCStatsReport}
623 RTCStatsReport.prototype.remote;
629 RTCStatsReport.prototype.type;
635 RTCStatsReport.prototype.id;
638 * TODO(bemasc): Remove this type once it is no longer in use. It has already
639 * been removed from the specification.
640 * @typedef {RTCStatsReport}
648 function RTCStatsResponse() {}
651 * @return {!Array.<!RTCStatsReport>}
653 RTCStatsResponse.prototype.result = function() {};
656 * @typedef {function(!RTCStatsResponse, MediaStreamTrack=)}
658 var RTCStatsCallback;
661 * This type is not yet standardized, so the properties here only represent
662 * the current capabilities of libjingle (and hence Chromium).
663 * TODO(bemasc): Add a link to the relevant standard once MediaConstraint has a
664 * standard definition.
669 function MediaConstraintSetInterface_() {}
674 MediaConstraintSetInterface_.prototype.OfferToReceiveAudio;
679 MediaConstraintSetInterface_.prototype.OfferToReceiveVideo;
684 MediaConstraintSetInterface_.prototype.DtlsSrtpKeyAgreement;
689 MediaConstraintSetInterface_.prototype.RtpDataChannels;
692 * TODO(bemasc): Make this type public once it is defined in a standard.
694 * @typedef {Object|MediaConstraintSetInterface_}
697 var MediaConstraintSet_;
703 function MediaConstraintsInterface_() {}
706 * @type {?MediaConstraintSet_}
708 MediaConstraintsInterface_.prototype.mandatory;
711 * @type {?Array.<!MediaConstraintSet_>}
713 MediaConstraintsInterface_.prototype.optional;
716 * This type is used extensively in
717 * {@see http://dev.w3.org/2011/webrtc/editor/webrtc.html} but is not yet
720 * @typedef {Object|MediaConstraintsInterface_}
722 var MediaConstraints;
727 function RTCDataChannel() {}
733 RTCDataChannel.prototype.label;
739 RTCDataChannel.prototype.reliable;
742 * An enumerated string type (RTCDataChannelState) with values:
743 * "connecting", "open", "closing", and "closed".
747 RTCDataChannel.prototype.readyState;
753 RTCDataChannel.prototype.bufferedAmount;
756 * @type {?function(!Event)}
758 RTCDataChannel.prototype.onopen;
761 * @type {?function(!Event)}
763 RTCDataChannel.prototype.onerror;
766 * @type {?function(!Event)}
768 RTCDataChannel.prototype.onclose;
770 RTCDataChannel.prototype.close = function() {};
773 * @type {?function(!MessageEvent.<*>)}
775 RTCDataChannel.prototype.onmessage;
780 RTCDataChannel.prototype.binaryType;
783 * @param {string|!Blob|!ArrayBuffer|!ArrayBufferView} data
785 RTCDataChannel.prototype.send = function(data) {};
792 function RTCDataChannelEvent() {}
795 * @type {!RTCDataChannel}
798 RTCDataChannelEvent.prototype.channel;
801 * @typedef {{reliable: boolean}}
803 var RTCDataChannelInitRecord_;
809 function RTCDataChannelInitInterface_() {}
814 RTCDataChannelInitInterface_.prototype.reliable;
817 * @typedef {RTCDataChannelInitInterface_|RTCDataChannelInitRecord_}
819 var RTCDataChannelInit;
822 * @param {RTCConfiguration} configuration
823 * @param {!MediaConstraints=} constraints
825 * @implements {EventTarget}
827 function RTCPeerConnection(configuration, constraints) {}
830 * @param {boolean=} opt_useCapture
833 RTCPeerConnection.prototype.addEventListener = function(
834 type, listener, opt_useCapture) {};
837 * @param {boolean=} opt_useCapture
840 RTCPeerConnection.prototype.removeEventListener = function(
841 type, listener, opt_useCapture) {};
844 RTCPeerConnection.prototype.dispatchEvent = function(evt) {};
847 * @param {!RTCSessionDescriptionCallback} successCallback
848 * @param {!RTCPeerConnectionErrorCallback=} failureCallback
849 * @param {!MediaConstraints=} constraints
851 RTCPeerConnection.prototype.createOffer = function(successCallback,
852 failureCallback, constraints) {};
855 * @param {RTCSessionDescriptionCallback} successCallback
856 * @param {?RTCPeerConnectionErrorCallback=} failureCallback
857 * @param {!MediaConstraints=} constraints
859 RTCPeerConnection.prototype.createAnswer = function(successCallback,
860 failureCallback, constraints) {};
863 * @param {!RTCSessionDescription} description
864 * @param {!RTCVoidCallback=} successCallback
865 * @param {!RTCPeerConnectionErrorCallback=} failureCallback
867 RTCPeerConnection.prototype.setLocalDescription = function(description,
868 successCallback, failureCallback) {};
871 * @param {!RTCSessionDescription} description
872 * @param {!RTCVoidCallback=} successCallback
873 * @param {!RTCPeerConnectionErrorCallback=} failureCallback
875 RTCPeerConnection.prototype.setRemoteDescription = function(description,
876 successCallback, failureCallback) {};
879 * @type {?RTCSessionDescription}
882 RTCPeerConnection.prototype.localDescription;
885 * @type {?RTCSessionDescription}
888 RTCPeerConnection.prototype.remoteDescription;
891 * @type {RTCSignalingState}
894 RTCPeerConnection.prototype.signalingState;
897 * @param {?RTCConfiguration=} configuration
898 * @param {?MediaConstraints=} constraints
900 RTCPeerConnection.prototype.updateIce = function(configuration, constraints) {};
903 * @param {!RTCIceCandidate} candidate
905 RTCPeerConnection.prototype.addIceCandidate = function(candidate) {};
908 * @type {!RTCIceGatheringState}
911 RTCPeerConnection.prototype.iceGatheringState;
914 * @type {!RTCIceConnectionState}
917 RTCPeerConnection.prototype.iceConnectionState;
920 * @return {!Array.<!MediaStream>}
922 RTCPeerConnection.prototype.getLocalStreams = function() {};
925 * @return {!Array.<!MediaStream>}
927 RTCPeerConnection.prototype.getRemoteStreams = function() {};
930 * @param {string} streamId
931 * @return {MediaStream}
933 RTCPeerConnection.prototype.getStreamById = function(streamId) {};
936 * @param {?string} label
937 * @param {RTCDataChannelInit=} dataChannelDict
938 * @return {!RTCDataChannel}
940 RTCPeerConnection.prototype.createDataChannel =
941 function(label, dataChannelDict) {};
943 * @param {!MediaStream} stream
944 * @param {!MediaConstraints=} constraints
946 RTCPeerConnection.prototype.addStream = function(stream, constraints) {};
949 * @param {!MediaStream} stream
951 RTCPeerConnection.prototype.removeStream = function(stream) {};
953 // TODO(bemasc): Add identity provider stuff once implementations exist
956 * @param {!RTCStatsCallback} successCallback
957 * @param {MediaStreamTrack=} selector
959 RTCPeerConnection.prototype.getStats = function(successCallback, selector) {};
961 RTCPeerConnection.prototype.close = function() {};
964 * @type {?function(!Event)}
966 RTCPeerConnection.prototype.onnegotiationneeded;
969 * @type {?function(!RTCPeerConnectionIceEvent)}
971 RTCPeerConnection.prototype.onicecandidate;
974 * @type {?function(!Event)}
976 RTCPeerConnection.prototype.onsignalingstatechange;
979 * @type {?function(!MediaStreamEvent)}
981 RTCPeerConnection.prototype.onaddstream;
984 * @type {?function(!MediaStreamEvent)}
986 RTCPeerConnection.prototype.onremovestream;
989 * @type {?function(!Event)}
991 RTCPeerConnection.prototype.oniceconnectionstatechange;
994 * @type {?function(!RTCDataChannelEvent)}
996 RTCPeerConnection.prototype.ondatachannel;
999 * @type {function(new: RTCPeerConnection, RTCConfiguration,
1000 * !MediaConstraints=)}
1002 var webkitRTCPeerConnection;