-
Notifications
You must be signed in to change notification settings - Fork 0
/
servertest.js
73 lines (69 loc) · 2.8 KB
/
servertest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//turn server test-----------------------------------------------
function checkTURNServer(turnConfig, timeout){
return new Promise(function(resolve, reject){
setTimeout(function(){
if(promiseResolved) return;
resolve(false);
promiseResolved = true;
}, timeout || 5000);
var promiseResolved = false
, myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection //compatibility for firefox and chrome
, pc = new myPeerConnection({iceServers:[turnConfig]})
, noop = function(){};
pc.createDataChannel(""); //create a bogus data channel
pc.createOffer(function(sdp){
if(sdp.sdp.indexOf('typ relay') > -1){ // sometimes sdp contains the ice candidates...
promiseResolved = true;
resolve(true);
}
pc.setLocalDescription(sdp, noop, noop);
}, noop); // create offer and set local description
pc.onicecandidate = function(ice){ //listen for candidate events
if(promiseResolved || !ice || !ice.candidate || !ice.candidate.candidate || !(ice.candidate.candidate.indexOf('typ relay')>-1)) return;
promiseResolved = true;
resolve(true);
};
});
}
function m1(){
checkTURNServer({
urls: ['turn:118.25.102.41:3478?transport=tcp', 'turn:118.25.102.41:3478?transport=udp',
'turn:118.25.102.41:5349?transport=tcp', 'turn:118.25.102.41:5349?transport=udp'],
username: 'team2',
credential: 'team2018'
}).then(function(bool){
console.log('is my TURN server active? ', bool? 'yes':'no');
}).catch(console.error.bind(console));
}
function m2(){
checkTURNServer({
urls: 'turn:118.25.102.41:3478?transport=tcp',
username: 'team2',
credential: 'team2018'
}).then(function(bool){
console.log('is my TURN server active? 3478tcp', bool? 'yes':'no');
}).catch(console.error.bind(console));
checkTURNServer({
urls: 'turn:118.25.102.41:3478?transport=udp',
username: 'team2',
credential: 'team2018'
}).then(function(bool){
console.log('is my TURN server active? 3478udp', bool? 'yes':'no');
}).catch(console.error.bind(console));
checkTURNServer({
urls: 'turn:118.25.102.41:5349?transport=tcp',
username: 'team2',
credential: 'team2018'
}).then(function(bool){
console.log('is my TURN server active? 5349tcp', bool? 'yes':'no');
}).catch(console.error.bind(console));
checkTURNServer({
urls: 'turn:118.25.102.41:5349?transport=udp',
username: 'team2',
credential: 'team2018'
}).then(function(bool){
console.log('is my TURN server active? 5349udp', bool? 'yes':'no');
}).catch(console.error.bind(console));
}
//m1();
//m2();