ICE failed on firefox but peerJs's exemple work fine - webrtc

I try to make a simple chat with peerJs to learn how to use peer to peer
when I try to connect two clients, this error happens on both client
WebRTC: ICE failed, your TURN server appears to be broken, see about:webrtc for more details
PeerJS: iceConnectionState is failed, closing connections
the peerJs demo work fine on Firefox (even when i run it locally)
and my code seem to work correctly on edge
I try in private with disabled add-on
my media.peerconnection.ice.proxy_only is set to false.
Any setting related to ice or peer is set to default
My code
both client have the same code, they try to connect to the client in the url
exemple:
i open http://localhost:5173/room who get an peerId and rename itselfhttp://localhost:5173/room?roomId=198ec396-1691-48cf-b6ea-16d2102c4917 then i copy paste this link to another tab
<script lang="ts">
import { page } from '$app/stores';
import { Peer } from 'peerjs';
import { onMount } from 'svelte';
let peer: Peer;
onMount(() => {
const url = $page.url.searchParams;
peer = new Peer({ debug: 3 });
peer.on('open', function (id) {
console.log('open| id :', id);
if (url.has('roomId')) {
let conn = peer.connect(url.get('roomId')!, {
reliable: true
});
conn.on('open', function () {
console.log('test 1');
conn.send('test send 1');
});
}
// change url to be easily copied
window.history.replaceState({}, '', 'room?roomId=' + id);
});
peer.on('connection', function (connexion) {
console.log('test 2');
connexion.send('test send 2');
});
});
</script>
firefox log
edge log (seem to connect but test's send() not logged)

Related

Can only send data from the end which initiated the connection. How to send Data from other end (PeerJs)

I am using the peerjs module in my SvelteKit app to create a peer-to-peer file transfer app
Also the custom signaling server using peerjs --port 5000 command and it's connecting successfully
Here's my code typescript from the file sender's end:
import { FormatFileSize } from '../lib/utils/FormatFileSize'; // function to convert file size into a string of kb, MB, GB file sizes
import Peer from 'peerjs';
import type { DataConnection } from 'peerjs'; // had to import separately because no export of DataConnection was shown from the 'peerjs' module I don't know why
import { onMount } from 'svelte';
export let file: FileList; // the file which needs to be transfered
let senderPeerId: string = '';
onMount(() => {
let peer: Peer = new Peer({
host: '/',
port: 5000
});
peer.on('open', function (id) {
console.log('My peer ID is: ' + id);
senderPeerId = id;
});
peer.on('connection', (dataConnection: DataConnection) => {
console.log('connected', dataConnection);
dataConnection.send('Hello'); // trying to send this but it's not being recie
dataConnection.on('data', function (data) {
console.log('Received', data); // I am logging the data received from the other end
});
});
});
And here's my code typescript from the file receiver's end (But this end is initiating the peer connection):
import type { PageData } from './$types';
import Peer from 'peerjs';
import { onMount } from 'svelte';
export let data: PageData; // in the formate of { receiverId: string } because this page params contain the peer id of the sender.
let peer: Peer; // initiating here so that can use it elsewhere
onMount(() => {
peer = new Peer({
host: '/',
port: 5000
});
peer.on('open', function (id) {
console.log('My peer ID is: ' + id);
startPeerConnection();
});
});
function startPeerConnection() {
const dataConnection = peer.connect(data.receiverId);
console.log(dataConnection);
dataConnection.on('open', function () {
console.log('connection started');
dataConnection.on('data', function (data) {
console.log('Received', data); // logging the data, but no data is recieved
});
dataConnection.send('World'); // this data is sent successfully and logged in the console of the other side
});
}
What am I doing wrong here, or only the side which initiates the connection can send data?
I looked through the internet but couldn't find a similar problem and a solution to it, please help !!

Is there a way to multi browser communicate each other without peers?still able to communicate after lose peers connecting?

Is there a way to multi browser communicate each other without peers?or still able to communicate after lose peers connecting?
I created sample with gun.js like below:
server.js:
const express = require('express')
const Gun = require('gun')
const app = express()
const port = 8000
app.use(Gun.serve)
const server = app.listen(port, () => {
console.log("Listening at: http://localhost://" + port)
})
Gun({web: server})
test.ts on angular demo:
gun = GUN({
peers: ['http:localhost:8000/gun']
});
data: any;
initDate(): void {
this.gun.get('mark').put({
name: "Mark",
email: "mark#gun.eco",
});
}
listenDate(): void {
this.gun.get('mark').on((data, key) => {
console.log("realtime updates:", data);
this.data = data;
});
}
submit(): void {
this.gun.get('mark').get('live').put(Math.random());
}
I start server.js as a peer and start angular app,open two broswer with same url,the two broswer communicate well.
but after i stop server.js , the two broswer are unable to communicate each other.
Is there a way to the two browser communicate each other without server.js?or how still able to communicate after I stop server.js?

Redis issue on module-redis-fork

Issue
Hi everyone,
I have an issue while trying to interact with Redis in those conditions:
Redis instance with Redisearch module,
Create node-redis client before Redis module fork is ongoing,
Redis module fork is on-going
The behaviour that I get is that "send_command" stays idle until the fork stops.
When the fork ends I get this error:
debug mode ->
Redis connection is gone from end event
client error ->
AbortError: Redis connection lost and command aborted. It might have been processed.
After I get this error the commands from the same client (without creating a new client) come back to works fine.
On every fork, I got the same behaviour.
Additional Info:
keys: 37773168,
used_memory_human: '87.31G'
Code Example:
This is a simple express app,
'use strict';
const express = require('express');
const Redis = require('redis');
// Redis.debug_mode = true;
const router = express.Router();
let client = null;
router.get('/redisearch/connect', async (req, res, next) => {
const conf = {
'host': '127.0.0.1',
'port': 6379,
'db': 0,
};
try {
if (!client) client = Redis.createClient(conf.port, conf.host, { db: conf.db });
res.send('Connected');
} catch (err) {
res.send(err);
}
});
router.get('/redisearch/d', async (req, res, next) => {
const num = 10;
const dArgs = ['testIndexName', `#ic:[${num} ${num}]`, 'GROUPBY', 1, '#d'];
try {
client.send_command('FT.AGGREGATE', dArgs, (err, reply) => {
if (err) {
res.send({ err: err });
};
res.send({ d: reply });
});
} catch (err) {
res.send(err);
}
});
module.exports = router;
this is the simplest way I have to replicate the problem.
I don't know if there is a way to force redis to use the fork, in my case it appears following a massive search on index followed by delete and insert of records.
Redis however during these operations (insert/delete) works normally,
I can launch commands from the redis-cli;
By creating a new instance of the node-redis client while the fork is present everything works normally and when the fork goes away everything keep working.
Environment
Node.js Version: v14.15.1
Redis Version: 6.0.4
redisearch Version: 1.6.15
node-redis Version: 3.2
Platform: Server 128GB RAM, 8 Core, Debian

Chrome on Android not connecting to peer over WebRTC

I'm building a WebRTC app with a central electron app that browsers connect to. The scenario I'm testing is running the electron app on my computer (Ubuntu 16.04) and connecting from chrome (69) on Android (7.0). Following the debugging the offer, answer and candidate are passed, but fails on the last stop of generating the connection. The ice connection state switchs to "checking" then "failed". I'm able to load the browser app on my laptop and connect to an electron app on the same computer.
Should I be using a collection of ice servers? What do I need to make the WebRTC connection more robust? Should I not write my own signaling process and use something pre-made? Is their anyway to debug the reason why the connection failed? For debugging I've tried the webrtc debugging tab on chrome but all it says is connection failled at the bottom of the stack.
The configuration for my RTCPeerConnection is:
const configuration = {
"iceServers": [{ "urls": "stun:stun.1.google.com:19302" }]
};
This is the code I use to form iniate the connection to the electron app from the browser app (The function are attached to a ts class which are called in order: setupPeerConnection, setupDataChannel, makeOffer):
setupPeerConnection(gameID:string) {
this.gameID = gameID;
let configuration:RTCConfiguration = {
"iceServers": [{ "urls": "stun:stun.1.google.com:19302" }]
};
this.connection = new RTCPeerConnection(configuration);
const that:PeerConnection = this;
//Definition of the data channel
this.connection.ondatachannel = function(ev:RTCDataChannelEvent) {
};
//When we get our own ICE Candidate, we provide it to the other Peer.
this.connection.onicecandidate = function(event:RTCPeerConnectionIceEvent) {
if (event.candidate && that.connectedToGame) {
that.serverConnection.send({
type: "candidate",
candidate: event.candidate
});
}
};
this.connection.oniceconnectionstatechange = function(e:Event) {
let iceState:RTCIceConnectionState = this.iceConnectionState;
console.log("Changing connection state:", iceState)
if (iceState == "connected") {
console.log("Connection established with server");
} else if (iceState =="disconnected" || iceState == "closed") {
// We lost the user
that.connectedToGame = false;
that.onLeave();
}
};
}
setupDataChannel(onopen:(error:ErrorEvent)=>void, onmessage:(message:MessageEvent)=>void) {
let dataChannelOptions:RTCDataChannelInit = <RTCDataChannelInit>{
reliable: true
};
this.dataChannel = this.connection.createDataChannel(this.gameID + "-dataChannel", dataChannelOptions);
this.dataChannel.onerror = function (error:ErrorEvent) {
console.log("Error on data channel:", error);
};
this.dataChannel.onmessage = onmessage.bind(this);
this.dataChannel.onopen = onopen;
this.dataChannel.onclose = function() {
console.log("Channel closed.");
};
}
makeOffer() {
let that:PeerConnection = this;
this.connection.createOffer().then(function (offer:RTCSessionDescriptionInit) {
that.serverConnection.send({
gameID: that.gameID,
type: "offer",
offer: offer
});
that.connection.setLocalDescription(offer);
}, function (error) {
console.log("Error contacting remote peer: ", error);
});
}

ICE candidates gathered only from one network interface

Got very simple code:
<script type="text/javascript">
pc = new window.RTCPeerConnection();
pc.onicecandidate = function(event) {
console.log("onicecandidate\n", event);
}
pc.onicegatheringstatechange = function(event) {
console.log("onicegatheringstatechange\n", event);
}
dc = pc.createDataChannel("dataChannel");
errFunc = function(err) {
console.log("errFunc\n", err);
}
successCback = function() {
console.log("setLocalDescription is a success\n");
}
pc.createOffer()
.then(function(offer) { pc.setLocalDescription(offer)})
.then(successCback)
.catch(errFunc);
</script>
Got ubuntu running chromium and TWO local ethernet interfaces.
Running aforementioned code yields only 1 call to onicecandidate and
1 call to onicegatheringstatechange. (any STUN/TURN servers are deliberately not specified, so I do expect only local host candidates, but from all interfaces). Only one ethernet interface is examined by ICE.
Why ?
Unless you have permissions for getUserMedia, Chrome will restrict ICE candidates to the interface of the default route. The rationale is explained in this draft