Add update image functionality to clients

This commit is contained in:
nicola 2020-03-15 18:55:43 +11:00
parent f4b6a17120
commit a06a26f931

View File

@ -20,6 +20,7 @@ function App() {
peer.current = new Peer(); peer.current = new Peer();
}, []); }, []);
const connectionRef = useRef(null);
useEffect(() => { useEffect(() => {
function handleOpen(id) { function handleOpen(id) {
console.log("My peer ID is: " + id); console.log("My peer ID is: " + id);
@ -27,6 +28,7 @@ function App() {
} }
function handleConnection(connection) { function handleConnection(connection) {
connectionRef.current = connection;
connection.on("open", () => { connection.on("open", () => {
if (imgRef.current) { if (imgRef.current) {
connection.send(imgRef.current); connection.send(imgRef.current);
@ -59,6 +61,9 @@ function App() {
const loadImage = e => { const loadImage = e => {
imgRef.current = e.target.files[0]; imgRef.current = e.target.files[0];
setImgSrc(URL.createObjectURL(imgRef.current)); setImgSrc(URL.createObjectURL(imgRef.current));
if(connectionRef.current) {
connectionRef.current.send(imgRef.current);
}
}; };
return ( return (