-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How work with customChannel? #10
Comments
Hi @jarukus, sorry for the delay but I just noticed you issue. Below simple example, please let me know if you have more questions. As shown in basic example https://github.com/vardius/react-peer-data#examples
Simple example, probably could be improved. It is draft only, you have to make it work yourself. But I hope you get the idea. import React, { useEffect } from 'react';
import { usePeerData } from 'react-peer-data';
function App() {
const peerData = usePeerData();
const room = peerData.connect('my-room);
useEffect(() => {
room
.on("participant", participant => {
participant
.on("disconnected", () => { console.log('disconnected', participant.id); })
.on("track", event => { console.log('stream', participant.id, event.streams[0]); })
.on("message", payload => { console.log(participant.id, payload); })
.on("error", event => {
console.error('peer', participant.id, event);
participant.renegotiate();
});
// @TODO: store participants in global context or global state ?
// send only to given participant
participant.send('Hi mate! this is private message.');
})
.on("error", event => { console.error('room', name, event); });
return () => room.disconnect()
}, [room]);
//payload object can be everything
const payload = {msg: "Hi there!", date: now()};
//send to everybody in room
room.send(payload);
return null; // @TODO: render participants
}
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: