mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Added basic tests.
This commit is contained in:
parent
b2ec1c1c99
commit
4d98a4a4f1
32
webrtc/MediaStream-tests.ts
Normal file
32
webrtc/MediaStream-tests.ts
Normal file
@ -0,0 +1,32 @@
|
||||
///<reference path="MediaStream.d.ts" />
|
||||
var mediaStreamConstraints: MediaStreamConstraints = { audio: true, video: true };
|
||||
|
||||
var mediaTrackConstraintSet: MediaTrackConstraintSet = {};
|
||||
var mediaTrackConstraintArray: MediaTrackConstraint[] = [];
|
||||
var mediaTrackConstraints: MediaTrackConstraints = { mandatory: mediaTrackConstraintSet, optional: mediaTrackConstraintArray }
|
||||
|
||||
navigator.getUserMedia(mediaStreamConstraints,
|
||||
stream => {
|
||||
console.log('label:' + stream.label);
|
||||
console.log('ended:' + stream.ended);
|
||||
stream.onended = event => console.log('Stream ended');
|
||||
var objectUrl = URL.createObjectURL(stream);
|
||||
var wkObjectUrl = webkitURL.createObjectURL(stream);
|
||||
},
|
||||
error => {
|
||||
console.log('Error message: ' + error.message);
|
||||
console.log('Error name: ' + error.name);
|
||||
});
|
||||
|
||||
navigator.webkitGetUserMedia(mediaStreamConstraints,
|
||||
stream => {
|
||||
console.log('label:' + stream.label);
|
||||
console.log('ended:' + stream.ended);
|
||||
stream.onended = event => console.log('Stream ended');
|
||||
var objectUrl = URL.createObjectURL(stream);
|
||||
var wkObjectUrl = webkitURL.createObjectURL(stream);
|
||||
},
|
||||
error => {
|
||||
console.log('Error message: ' + error.message);
|
||||
console.log('Error name: ' + error.name);
|
||||
});
|
||||
4
webrtc/MediaStream.d.ts
vendored
4
webrtc/MediaStream.d.ts
vendored
@ -35,8 +35,8 @@ declare var MediaTrackConstraint: {
|
||||
}
|
||||
|
||||
interface Navigator {
|
||||
getUserMedia(constraints: MediaStreamConstraints, successCallback: (stream: any) => void , errorCallback: (error: Error) => void );
|
||||
webkitGetUserMedia(constraints: MediaStreamConstraints, successCallback: (stream: any) => void , errorCallback: (error: Error) => void );
|
||||
getUserMedia(constraints: MediaStreamConstraints, successCallback: (stream: LocalMediaStream) => void , errorCallback: (error: Error) => void );
|
||||
webkitGetUserMedia(constraints: MediaStreamConstraints, successCallback: (stream: LocalMediaStream) => void , errorCallback: (error: Error) => void );
|
||||
}
|
||||
|
||||
interface EventHandler { (event: Event): void; }
|
||||
|
||||
51
webrtc/RTCPeerConnection-tests.ts
Normal file
51
webrtc/RTCPeerConnection-tests.ts
Normal file
@ -0,0 +1,51 @@
|
||||
/// <reference path="MediaStream.d.ts" />
|
||||
/// <reference path="RTCPeerConnection.d.ts" />
|
||||
|
||||
var config: RTCConfiguration = { iceServers: [{ url: "stun.l.google.com:19302" }] };
|
||||
var constraints: MediaConstraints = { mandatory: { OfferToReceiveAudio: true, OfferToReceiveVideo: true } };
|
||||
|
||||
var peerConnection: RTCPeerConnection = new RTCPeerConnection(config, constraints);
|
||||
|
||||
navigator.getUserMedia({ audio: true, video: true },
|
||||
stream => {
|
||||
peerConnection.addStream(stream);
|
||||
},
|
||||
error => {
|
||||
console.log('Error message: ' + error.message);
|
||||
console.log('Error name: ' + error.name);
|
||||
});
|
||||
|
||||
peerConnection.onaddstream = ev => console.log(ev.type);
|
||||
peerConnection.ondatachannel = ev => console.log(ev.type);
|
||||
peerConnection.onicechange = ev => console.log(ev.type);
|
||||
peerConnection.onnegotiationneeded = ev => console.log(ev.type);
|
||||
peerConnection.onopen = ev => console.log(ev.type);
|
||||
peerConnection.onicecandidate = ev => console.log(ev.type);
|
||||
peerConnection.onremovestream = ev => console.log(ev.type);
|
||||
peerConnection.onstatechange = ev => console.log(ev.type);
|
||||
|
||||
peerConnection.createOffer(
|
||||
offer => {
|
||||
peerConnection.setLocalDescription(offer,
|
||||
() => console.log("set local description"),
|
||||
error => console.log("Error setting local description: " + error));
|
||||
},
|
||||
error => console.log("Error creating offer: " + error));
|
||||
|
||||
var type: RTCSdpType = RTCSdpType.offer;
|
||||
var offer: RTCSessionDescriptionInit = { type: type, sdp: "some sdp" };
|
||||
var sessionDescription = new RTCSessionDescription(offer);
|
||||
|
||||
peerConnection.setRemoteDescription(sessionDescription, () => {
|
||||
peerConnection.createAnswer(
|
||||
answer => {
|
||||
peerConnection.setLocalDescription(answer,
|
||||
() => console.log('Set local description'),
|
||||
error => console.log("Error setting local description from created answer: " + error + "; answer.sdp=" + answer.sdp));
|
||||
},
|
||||
error => console.log("Error creating answer: " + error));
|
||||
},
|
||||
error => console.log('Error setting remote description: ' + error + "; offer.sdp=" + offer.sdp));
|
||||
|
||||
var wkPeerConnection: webkitRTCPeerConnection = new webkitRTCPeerConnection(config, constraints);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user