Improve connection and sync handling
This commit is contained in:
parent
15d43e101e
commit
86f82c1247
@ -113,6 +113,13 @@ function useSession(onConnectionOpen, onConnectionSync) {
|
|||||||
};
|
};
|
||||||
}, [peer, peerId, connections, onConnectionOpen, onConnectionSync, streams]);
|
}, [peer, peerId, connections, onConnectionOpen, onConnectionSync, streams]);
|
||||||
|
|
||||||
|
function call(connectionId) {
|
||||||
|
const call = peer.call(connectionId, streams[peerId]);
|
||||||
|
call.on("stream", stream => {
|
||||||
|
addStream(stream, connectionId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function sync(connectionIds) {
|
function sync(connectionIds) {
|
||||||
for (let connectionId of connectionIds) {
|
for (let connectionId of connectionIds) {
|
||||||
if (connectionId in connections) {
|
if (connectionId in connections) {
|
||||||
@ -122,10 +129,7 @@ function useSession(onConnectionOpen, onConnectionSync) {
|
|||||||
metadata: { sync: false }
|
metadata: { sync: false }
|
||||||
});
|
});
|
||||||
addConnection(connection, false);
|
addConnection(connection, false);
|
||||||
const call = peer.call(connectionId, streams[peerId]);
|
call(connectionId);
|
||||||
call.on("stream", stream => {
|
|
||||||
addStream(stream, connectionId);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +140,7 @@ function useSession(onConnectionOpen, onConnectionSync) {
|
|||||||
const connection = peer.connect(connectionId, {
|
const connection = peer.connect(connectionId, {
|
||||||
metadata: { sync: true }
|
metadata: { sync: true }
|
||||||
});
|
});
|
||||||
|
addConnection(connection, false);
|
||||||
connection.on("open", () => {
|
connection.on("open", () => {
|
||||||
connection.on("data", data => {
|
connection.on("data", data => {
|
||||||
if (data.id === "sync") {
|
if (data.id === "sync") {
|
||||||
@ -147,12 +152,7 @@ function useSession(onConnectionOpen, onConnectionSync) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const call = peer.call(connectionId, streams[peerId]);
|
call(connectionId);
|
||||||
call.on("stream", remoteStream => {
|
|
||||||
addStream(remoteStream, connectionId);
|
|
||||||
});
|
|
||||||
|
|
||||||
addConnection(connection, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { peer, peerId, streams, connections, connectTo };
|
return { peer, peerId, streams, connections, connectTo };
|
||||||
|
Loading…
Reference in New Issue
Block a user