Skip to content

Commit

Permalink
[mirotalk] - improve test iceServers
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Jul 23, 2022
1 parent c40f5a9 commit ac3886f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
20 changes: 15 additions & 5 deletions app/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ const turnUrls = process.env.TURN_URLS;
const turnUsername = process.env.TURN_USERNAME;
const turnCredential = process.env.TURN_PASSWORD;

// Test Stun and Turn connection URL
const testStunTurn = host + '/test';

// Sentry config
const Sentry = require('@sentry/node');
const { CaptureConsole } = require('@sentry/integrations');
Expand Down Expand Up @@ -210,8 +207,17 @@ app.get(['/privacy'], (req, res) => {
res.sendFile(views.privacy);
});

// test Stun Turn connections
// test Stun and Turn connections
app.get(['/test'], (req, res) => {
if (Object.keys(req.query).length > 0) {
log.debug('Request Query', req.query);
}
/*
http://localhost:3000/test?iceServers=[{"urls":"stun:stun.l.google.com:19302"},{"urls":"turn:numb.viagenie.ca","username":"miroslav.pejic.85@gmail.com","credential":"mirotalkp2p"}]
https://p2p.mirotalk.com//test?iceServers=[{"urls":"stun:stun.l.google.com:19302"},{"urls":"turn:numb.viagenie.ca","username":"miroslav.pejic.85@gmail.com","credential":"mirotalkp2p"}]
https://mirotalk.up.railway.app/test?iceServers=[{"urls":"stun:stun.l.google.com:19302"},{"urls":"turn:numb.viagenie.ca","username":"miroslav.pejic.85@gmail.com","credential":"mirotalkp2p"}]
https://mirotalk.herokuapp.com/test?iceServers=[{"urls":"stun:stun.l.google.com:19302"},{"urls":"turn:numb.viagenie.ca","username":"miroslav.pejic.85@gmail.com","credential":"mirotalkp2p"}]
*/
res.sendFile(views.stunTurn);
});

Expand All @@ -221,6 +227,7 @@ app.get('/join/', (req, res) => {
log.debug('Request Query', req.query);
/*
http://localhost:3000/join?room=test&name=mirotalk&audio=1&video=1&screen=1&notify=1
https://p2p.mirotalk.com/join?room=test&name=mirotalk&audio=1&video=1&screen=1&notify=1
https://mirotalk.up.railway.app/join?room=test&name=mirotalk&audio=1&video=1&screen=1&notify=1
https://mirotalk.herokuapp.com/join?room=test&name=mirotalk&audio=1&video=1&screen=1&notify=1
*/
Expand Down Expand Up @@ -353,6 +360,9 @@ if (turnEnabled == 'true') {
});
}

// Test Stun and Turn connection with query params
const testStunTurn = host + '/test?iceServers=' + JSON.stringify(iceServers);

/**
* Expose server to external with https tunnel using ngrok
* https://ngrok.com
Expand All @@ -375,7 +385,7 @@ async function ngrokStart() {
},
server: host,
server_tunnel: tunnelHttps,
stun_turn_test: testStunTurn,
testIceServers: testStunTurn,
api_docs: api_docs,
api_key_secret: api_key_secret,
sentry_enabled: sentryEnabled,
Expand Down
50 changes: 34 additions & 16 deletions public/views/testStunTurn.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,55 @@ <h1>Test Stun/Turn Servers</h1>

<hr />

<pre id="ice" style="background: #000000; color: lime; overflow: auto"></pre>

<hr />

<p id="ip"></p>
<p id="stun">馃敶 The STUN server is NOT reachable!</p>
<p id="turn">馃敶 The TURN server is NOT reachable!</p>
<p id="err"></p>

<hr />

<a href="https://github.com/miroslavpejic85/mirotalk/issues/108#issuecomment-1193087636" target="_blank"
>Check out also</a
<a href="https://github.com/miroslavpejic85/mirotalk/issues/108#issuecomment-1193087636" target="_blank">
Check this out too</a
>

<script>
const Ice = document.getElementById('ice');
const IP = document.getElementById('ip');
const Stun = document.getElementById('stun');
const Turn = document.getElementById('turn');
const Err = document.getElementById('err');

// MiroTalk P2P default STUN/TURN if not set

const iceServers = [
// Test some STUN server
{
urls: 'stun:stun.l.google.com:19302',
},
// Test some TURN server
{
urls: 'turn:numb.viagenie.ca',
username: 'miroslav.pejic.85@gmail.com',
credential: 'mirotalkp2p',
},
];
const qs = new URLSearchParams(window.location.search);

let iceServers = qs.get('iceServers');

if (iceServers) {
iceServers = JSON.parse(iceServers);
// http://localhost:3000/test?iceServers=[{"urls":"stun:stun.l.google.com:19302"},{"urls":"turn:numb.viagenie.ca","username":"miroslav.pejic.85@gmail.com","credential":"mirotalkp2p"}]
} else {
// http://localhost:3000/test
iceServers = [
// Test some STUN server
{
urls: 'stun:stun.l.google.com:19302',
},
// Test some TURN server
{
urls: 'turn:numb.viagenie.ca',
username: 'miroslav.pejic.85@gmail.com',
credential: 'mirotalkp2p',
},
];
}

console.log('Check Ice Servers', iceServers);

// Print iceServers config
Ice.innerHTML = JSON.stringify(iceServers, null, 4);

// Test the connections
const pc = new RTCPeerConnection({
Expand Down

0 comments on commit ac3886f

Please sign in to comment.