Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

peerconnection api tests #277

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions mediacapture-streams/peerconnection-api/api-present.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<html>
<head>
<title>RTCPeerconnection: test that RTCPeerConnection is present (with or without vendor prefix)</title>
<meta name='assert' content='Check that the RTCPeerConnection() method is present.'/>
<meta name='flags' content='vendor-prefix, dom'/>
<link rel='stylesheet' href='/resources/testharness.css' media='all'/>
</head>
<body>
<h1>Description</h1>
<p>This test checks for the presence of the <code>RTCPeerConnection</code> method, taking vendor prefixes into account.</p>
<div id='log'></div>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=../featuredetection.js></script>
<script>
test(function () {
assert_true(undefined !== BrowserHasFeature(window, "RTCPeerConnection"), "RTCPeerconnection exists");
}, "RTCPeerConnection() is present on window");
</script>
</body>
</html>
4 changes: 4 additions & 0 deletions mediacapture-streams/peerconnection-api/prefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var api = BrowserHasFeature(window, "RTCPeerConnection");
if (!window.RTCPeerConnection && undefined !== api) {
window.RTCPeerConnection = api;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!doctype html>
<html>
<head>
<title>On a peer connection</title>
<link rel='stylesheet' href='/resources/testharness.css' media='all'/>
</head>
<body>
<h1>Description</h1>
<p>This test checks that a new peer connection triggers the events as expected.</p>

<div id='log'></div>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=../featuredetection.js></script>
<script src=prefix.js></script>
<script>
var t = async_test("Tests that a new peer triggers events as expected.", {timeout: 20000});
t.step(function () {
var peer, connection, config;

peer = new window.RTCPeerConnection({"iceServers": [{"url": "stun:stun.l.google.com:19302"}]});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll probably not want to depend on an external service here; there isn't a good alternative at the moment, though, so it's probably fine to leave as is for now. See also http://lists.w3.org/Archives/Public/public-test-infra/2014JanMar/0026.html

peer.onicecandidate = onIceCandidate;
connection = new WebSocket('ws://127.0.0.1:8080/');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't used, nor needed


function onIceCandidate(event) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think icecandidate only gets dispatched once at least setLocalDescription has been called (?)

t.step(function () {
assert_own_property(event, "candidate", "a new candidate is created");
config = {
type: 'candidate',
label: event.candidate.sdpMLineIndex,
id: event.candidate.sdpMid,
candidate: event.candidate.candidate
};
connection.send(config);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed either

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it not neded to check if icecandidate gets invoked ? If check is needed i have to use a demo server right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only meant that "connection.send(config)" is not needed (since we don't need to have signaling at all to test ice events)

});
t.step(function () {
t.done();
});
}
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!doctype html>
<html>
<head>
<title>Mandatory constraint in RTCPeerConnection</title>
<link rel='stylesheet' href='/resources/testharness.css' media='all'/>
</head>
<body>
<h1>Description</h1>
<p>This test checks that setting a trivial mandatory constraint (iceServers) in RTCPeerConnection is required</p>

<div id='log'></div>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=../featuredetection.js></script>
<script src=prefix.js></script>
<script>
var t = async_test("", {timeout: 10000});
t.step(function () {
var peer1, peer2;

function anotherTry() {
t.step(function() {
try{
peer2 = new window.RTCPeerConnection();
} catch(e){
if(peer2 == undefined) {
t.done();
}
assert_unreached("peer can be created without STUN server");
t.done();
}
}, "ICE connection required");
}

peer1 = new window.RTCPeerConnection({"iceServers": [{"url": "stun:stun.l.google.com:19302"}]});
if(peer1.hasOwnProperty("iceConnectionState")) {
anotherTry();
}
});
</script>
</body>
</html>
67 changes: 67 additions & 0 deletions mediacapture-streams/peerconnection-api/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
var http = require('http');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't actually need a Web Sockets server, so this file can go.

(if we did, it would need to be integrated with our wptserve tool)


var server = http.createServer(function(request, response) {
response.writeHead(404);
response.end();
});

server.listen(8080, function() {
console.log((new Date()) + ' Server is listening on port 8080');
});

/**
* Import websocket module
* on the server HTTP
*/
var WebSocketServer = require('websocket').server;

/**
* Create the websocket server
*/
wsServer = new WebSocketServer({
httpServer: server,
autoAcceptConnections: false
});

/**
* Declare the variable connections for rooms and users
*/
var connections = new Array();

/**
* When a peer connects
*/
wsServer.on('request', function(request) {

/**
* Accept the connection
*/
var connection = request.accept(null, request.origin);
console.log((new Date()) + ' Connection accepted.');

/**
* When we receive signal message from the client
*/
connection.on('message', function(message) {
message = JSON.parse(message.utf8Data);
switch(message["type"]) {
/**
* When a peer send a SDP message broadcast it
*/
case "candidate" :
console.log(message);
//broadcast logic
break;
}
});


/**
* When the peer hang up
* broadcast bye signal
*/
connection.on('close', function(reasonCode, description) {
console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');
});

})