minimal example
I'd really appreciate a minimal running example how to send data P2P using peer-data and peer-data-server libraries (basic use case). The README.md mentions how to use the library with different frame works. The website shows an example without explanation what it does or what to expect: Should I get output on the console if I open the page twice? The same applies to the Basic Example in the documentation.
Besides, it would be easier to get startet if there was no assumption that a specific build tool (e.g. Webpack) was being used. You might consider using
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Basic PeerData Example</title>
</head>
<body>
<script type="module">
import PeerData from 'https://unpkg.com/[email protected]/dist/index.es.js';
console.log(PeerData);
</script>
</body>
</html>
If you combine this with a simple peer-data-server example, you would only need 3 files:
├── index.html
├── server.js
└── package.json
No build script is required. You only need peer-data-server and socket.io as dependencies.
take a look at this example: https://github.com/vardius/peer-data/tree/master/examples
this example does not use socket channel as a signalling server its simple local webrtc connection with custom signalling channel simply forwarding signalling event from one instance to another
I created one with socket channel as signalling server hope this helps https://github.com/vardius/peer-data/tree/master/examples
Thanks :+1:
local-connection works, but I get errors when I try to connect in socket-channel
Uncaught DOMException: Failed to execute 'addTrack' on 'RTCPeerConnection': A sender already exists for the track.
at RTCPeerConnection.addTrack (https://webrtc.github.io/adapter/adapter-latest.js:628:31)
at https://unpkg.com/[email protected]/dist/index.es.js:193:73
at Array.map (<anonymous>)
at Participant.addStream (https://unpkg.com/[email protected]/dist/index.es.js:193:32)
at http://localhost:3000/remote.js:38:21
at https://unpkg.com/[email protected]/dist/index.es.js:109:70
at Array.forEach (<anonymous>)
at EventDispatcher.dispatch (https://unpkg.com/[email protected]/dist/index.es.js:109:38)
at Participant.dispatchRemoteStream (https://unpkg.com/[email protected]/dist/index.es.js:337:30)
at RTCPeerConnection.wrappedCallback (https://webrtc.github.io/adapter/adapter-latest.js:2692:9)
participant:error DOMException: Failed to execute 'setLocalDescription' on 'RTCPeerConnection': Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer
(anonymous) @ remote.js:24
(anonymous) @ EventDispatcher.ts:25
EventDispatcher.dispatch @ EventDispatcher.ts:25
(anonymous) @ Participant.ts:147
Promise.catch (async)
Participant.renegotiate @ Participant.ts:147
(anonymous) @ remote.js:39
(anonymous) @ EventDispatcher.ts:25
EventDispatcher.dispatch @ EventDispatcher.ts:25
Participant.dispatchRemoteStream @ Participant.ts:221
wrappedCallback @ adapter-latest.js:2692
I guess there exists some code from local-connection in socket-channel that causes this issue, since title and description of socket-channel are
local connection with custom signaling channel
Hey man, i updated reconnect flow to use rollback. there are some still errors in console, for both socket and local examples.
I suspect Failed to execute 'addTrack' on 'RTCPeerConnection': A sender already exists for the track. appears due to even ontrack being spawn twice which is most likely adapter issue. Correct me if i am wrong, but i did not find any other explanation now.
There is new error about remote description, its due to new even being handled by peer-data. https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/onnegotiationneeded
Seems like onnegotiationneeded is called also during initial connection to room before any offer/answer is generated. Will investigate more next day.
Fix the other issue related to onnegotiationneeded https://github.com/vardius/peer-data/releases/tag/v3.2.4
I suspect
Failed to execute 'addTrack' on 'RTCPeerConnection': A sender already exists for the track.appears due to evenontrackbeing spawn twice which is most likely adapter issue. Correct me if i am wrong, but i did not find any other explanation now.
remote:track is printed twice. That means
participant.addStream(event.streams[0]);
is called twice. Should there not be only one remote participant? :thinking: