For a TURN server that supports STUN, do I need to list both STUN and TURN urls in the client? - webrtc

If I have a TURN server that can also act as a STUN, should my urls in my client looks like this?
myPeerConnection = new RTCPeerConnection({
iceServers: [
{
urls: "turn:example.org"
}
]
});
or like this?
myPeerConnection = new RTCPeerConnection({
iceServers: [
{
urls: "stun:example.org"
},
{
urls: "turn:example.org"
}
]
});
I only want the TURN functionality used if necessary, not for every connection.
Thanks!

You can write it like the second option. It will try to connect with the stun server and fallback to the turn server when the stun method doesn't work.

Related

Simple peer different network calling Issue

I am using simple peer for my video call web application. when I call people in the same network video call is working perfectly. But in the different networks, it is not working. I also added ICE servers(stun/turn) to simple peer. Still, the same issue is happening can anyone please help me out. I am getting this issue in the console
Error: Connection failed. at h (index.js:17)at f.value (index.js:654) at RTCPeerConnection.t._pc.onconnectionstatechange (index.js:119)
const peer = new Peer({
initiator: true,
trickle: false,
stream,
config: {
iceServers: [
{
urls: "stun:numb.viagenie.ca",
username: "************",
credential: "************"
},
{
urls: "turn:numb.viagenie.ca",
username: "************",
credential: "************"
}
]
}
});
I had facing through the same issue.
I'm not sure if that has to do with those specific iceServers but I replace them with this ones on it works
iceServers: [
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: 'stun:stun1.l.google.com:19302' },
{ urls: 'stun:stun2.l.google.com:19302' },
{ urls: 'stun:stun3.l.google.com:19302' },
{ urls: 'stun:stun4.l.google.com:19302' },
{
url: 'turn:turn.bistri.com:80',
credential: 'homeo',
username: 'homeo',
},
{
url: 'turn:turn.anyfirewall.com:443?transport=tcp',
credential: 'webrtc',
username: 'webrtc',
},
Everything is working good but now my problem is that safari is not working just chrome with iOS
If someone knows how to handle this compatibility please contact me! :D
my issue here was with the stun/turn server.we can check the status of servers using
https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/
If you test a STUN server, it works if you can gather a candidate with type "srflx". If you test a TURN server, it works if you can gather a candidate with type "relay".
check you are getting this

Running multiple apps in a server hiding ports

Im developing two different chatbots and I have them on a Google Platform VM. I want to know how to access to them like this:
-> https://example.com/chatbot1
-> https://example.com/chatbot2
Instead of having:
-> https://example.com:5001
-> https://example.com:5002
I want to do that so I can run multiple chatbots on the same VM and I dont expose the ports. After doing this the idea is to insert the chatbot on a 3rd user web like this:
<script>
WebChat.default.init({
selector: "#webchat",
initPayload: "XXX",
interval: 1000,
customData: {"userId": "123"},
socketUrl: "http://example.com/chatbot1",
socketPath: "/socket.io/",
title: "XXX",
subtitle: "XXX",
inputTextFieldHint: "XXX",
connectingText: "XXX",
hideWhenNotConnected: true,
fullScreenMode: false,
showFullScreenButton: false,
profileAvatar: "xxx.jpg",
params: {
images: {
dims: {
width: 250,
height: 200,
}
},
storage: "XXX",
},
})
</script>
Both need to run through HTTPS. Do I need Apache or something similar? If this is the case, how can I configure it? I dont know if it is relevant but I only have access to the VM through SSH.
It sounds like you might want to use Apache's name-based virtual hosts (see the example under Running different sites on different ports).

pouchdb - secure replication with remote LevelDB

I am keen on using PouchDB in browser memory for an Angular application. This PouchDB will replicate from a remote LevelDB database that is fed key-value pairs from an algorithm. So, on the remote end, I would install PouchDB-Server. On the local end, I would do the following (as described here) on a node prompt.
var localDB = new PouchDB('mylocaldb')
var remoteDB = new PouchDB('https://remote-ip-address:5984/myremotedb')
localDB.sync(remoteDB, {
live: true
}).on('change', function (change) {
// yo, something changed!
}).on('error', function (err) {
// yo, we got an error! (maybe the user went offline?)
});
How do we start a PouchDB instance that supports TLS for live replication as described in the snippet above?
How do I start a PouchDB instance that supports TLS for live replication?
So after some more searching, it is clear from this topic, HTTPS is not supported for PocuhDB-Server.
Sorry, I misunderstood your question. I thought you intend to connect to a CouchDB server with PouchDB through HTTPS. Therefore, the following answer actually doesn't answer your question.
I created a server.js file like below to communicate with my CouchDB through HTTPS. Please note that the SSL certificate is (in my case) self-signed, and also CouchDB listens by default on port 6984 in the case of TLS:
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; // Ignore rejection, becasue CouchDB SSL certificate is self-signed
//import PouchDB from 'pouchdb'
const PouchDB = require('pouchdb')
const db = new PouchDB('https://admin:****#192.168.1.106:6984/reproduce')
db.allDocs({
include_docs: true,
attachments: false
}).then(function (result) {
// handle result
console.log(result)
}).catch(function (err) {
console.log(err);
});
I'm running the above file with $ node server.js and I'm getting the expected results:
$ node server.js
{ total_rows: 3,
offset: 0,
rows:
[ { id: '5d6590d3-41c7-4011-be5d-b21f80079ae5',
key: '5d6590d3-41c7-4011-be5d-b21f80079ae5',
value: [Object],
doc: [Object] },
{ id: 'ec6a36d1-952e-4d86-9865-3587c6079fb5',
key: 'ec6a36d1-952e-4d86-9865-3587c6079fb5',
value: [Object],
doc: [Object] },
{ id: 'f508e7aa-b4dc-42fc-96be-b7c1ffa54172',
key: 'f508e7aa-b4dc-42fc-96be-b7c1ffa54172',
value: [Object],
doc: [Object] } ] }
I created the above code with NodeJS on server-side. However, if you want to communicate with CouchDB through HTTPS inside the browser, i.e. on client-side, you have to enable CORS on CouchDB.

How to ask to the service worker to ignore requests matching a specific URL pattern in Polymer?

My application is built on Polymer v2 and uses the Firebase Auth service for authentication. Actually, I use the login-fire element. For a better experience on mobile devices, I choose to sign-in with redirect.
In the "network" tab of the DevTool (in Chrome) I see that a request containing the /__/auth/handler? pattern is sent for requesting Google authentication (for example, if the provider used is Google).
With the service workers enabled, this request is caught and the response is the login page of my application. No login attempted, the response comes from the service worker and I get a Network Error from Firebase API because of a timeout.
When I deploy the app without service workers the authentication process is working and I can reach the app.
I tried many ways to config the service workers to ignore all requests to a URL with the /auth/ pattern but I failed.
See the last version of my config file bellow.
sw-precache-config.js
module.exports = {
globPatterns: ['**\/*.{html,js,css,ico}'],
staticFileGlobs: [
'bower_components/webcomponentsjs/webcomponents-loader.js',
'images/*',
'manifest.json',
],
clientsClaim: true,
skipWaiting: true,
navigateFallback: 'index.html',
runtimeCaching: [
{
urlPattern: /\/auth\//,
handler: 'networkOnly',
},
{
urlPattern: /\/bower_components\/webcomponentsjs\/.*.js/,
handler: 'fastest',
options: {
cache: {
name: 'webcomponentsjs-polyfills-cache',
},
},
},
{
urlPattern: /\/images\//,
handler: 'cacheFirst',
options: {
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
};
Do you have a better solution? Do you notice what I missed?
Thank you for your help.
You can add this to your sw-precache-config.js file
navigateFallbackWhitelist: [/^(?!\/auth\/)/],
You should only whitelist the paths of your application. This should be known to you.
So everything you do not whitelist, will not be served from the serviceworker.
navigateFallbackWhitelist: [/^\/news\//,/^\/msg\//, /^\/settings\//],
With this example, only news/*, msg/*,settings/* will be delivered.
/auth/*,/api/*,... will not be caught.

WebRTC TURN Server - I set it up, but it's not working

I've set up a text chat service using the PeerJS implementation of WebRTC's data channel. PeerJS provides a basic signalling server for this purpose, but I have tried to replace that with STUN and TURN servers set up through XirSys (recommended by SimpleWebRTC, another WebRTC library). I haven't deployed to the web yet.
Using Node to serve my static files locally, it will work on a local network (when I am sitting next to the person and they navigate to my ip/port in the browser), but will not work when connecting through different access points on the same network (i.e. at work, on opposite ends of the building).
My hypothesis is that it's hitting a firewall, but still directing traffic to PeerJS' signalling server without falling back to the XirSys STUN and TURN servers I've tried to set up. Here's the code I'm working with:
var stun = {};
var turn1 = {};
var turn2 = {};
$.ajax({
type: "POST",
dataType: "json",
url: "https://api.xirsys.com/getIceServers",
data: {
ident: "myusername",
secret: "long-alphanumeric-secret-key",
domain: "www.adomain.com",
application: "anapp",
room: "aroom",
secure: 1
},
success: function (data, status) {
console.log(data);
stun = data.d.iceServers[0];
turn1 = data.d.iceServers[1];
turn2 = data.d.iceServers[2];
},
async: false
});
var conn;
// Connect to PeerJS, have server assign an ID instead of providing one
var peerID = prompt('What would you like your screen name to be?');
var peer = new Peer(
peerID,
{key: 'mypeerjsserverkey', debug: true},
{
config: {'iceServers': [
{url: stun.url},
{url: turn1.url, credential: turn1.credential, username: turn1.username},
{url: turn2.url, credential: turn2.credential, username: turn2.username}
]
}
});
NOTE: My ident, secret, domain, etc. obviously aren't accurately represented here. I don't think that's where my problem is.
Any thoughts?
If you email us a wireshark capture of your STUN/TURN traffic, we should be able to outline where your problem is. Messages sent over signalling are separate but parallel to WebRTC messages. Therefore, if the app is working but the messages are being sent over signalling, then it's possible the configuration of the application isn't correct.
XirSys provides TURN via UDP over TCP through port 80/443, so if the signalling is connecting and flowing, so should the TURN.
Also, looking at your code, if you pass data.d from your getIceServers success handler to the PeerJS config, that should reduce your code quite a bit :-) The ICE string you're reconstructing doesn't need to be broken down.
Regards,
Lee
XirSys CTO