connections
parent
b73ab2c691
commit
91a81d6699
|
|
@ -30,7 +30,7 @@ function useCurrent<T>(thing: T) {
|
||||||
interface Connection {
|
interface Connection {
|
||||||
peerId: string;
|
peerId: string;
|
||||||
clientId: string;
|
clientId: string;
|
||||||
channelID: string;
|
channelId: string;
|
||||||
call: any;
|
call: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,23 +50,49 @@ export default function PeerState(props: any) {
|
||||||
setIncomingCalls(incomingCalls => ([...incomingCalls, call]));
|
setIncomingCalls(incomingCalls => ([...incomingCalls, call]));
|
||||||
}, []));
|
}, []));
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
console.log(connections);
|
||||||
|
}, [connections]);
|
||||||
|
|
||||||
const { send } = useApi({
|
const { send } = useApi({
|
||||||
'voice:join'(data: any) {
|
'voice:join'(data: any) {
|
||||||
if(data.channelId !== channel) return
|
if(data.channelId !== channel) return;
|
||||||
console.log('PEER STATE CONNECTIONS', data);
|
if(data.peerId === peerId) return;
|
||||||
|
setConnections((connections) => ([
|
||||||
|
...connections,
|
||||||
|
{
|
||||||
|
call: null,
|
||||||
|
clientId: data.clientId,
|
||||||
|
peerId: data.peerId,
|
||||||
|
channelId: data.channelId
|
||||||
|
}
|
||||||
|
]))
|
||||||
},
|
},
|
||||||
'voice:leave'(data: any) {
|
'voice:leave'(data: any) {
|
||||||
if(data.channelId !== channel) return
|
if(data.channelId !== channel) return;
|
||||||
console.log('PEER STATE CONNECTIONS', data)
|
if(data.peerId === peerId) return;
|
||||||
|
setConnections(connections => connections.filter(connection => (
|
||||||
|
connection.channelId !== data.channelId ||
|
||||||
|
connection.clientId !== data.clientId ||
|
||||||
|
connection.peerId !== data.peerId
|
||||||
|
)));
|
||||||
},
|
},
|
||||||
'voice:list'(data: any) {
|
'voice:list'(data: any) {
|
||||||
if(data.uid !== channel) return
|
if(data.uid !== channel) return
|
||||||
setConnections(connections => {
|
setConnections(connections => {
|
||||||
|
return data.participants
|
||||||
|
.filter((p: any) => p.peerId !== peerId)
|
||||||
|
.map((participant: any) => {
|
||||||
|
const previousCall = null;
|
||||||
|
return {
|
||||||
|
...participant,
|
||||||
|
call: null
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
console.log('PEER STATE CONNECTIONS', data);
|
console.log('PEER STATE CONNECTIONS', data);
|
||||||
}
|
}
|
||||||
}, [channel]);
|
}, [channel, peerId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(connected) return;
|
if(connected) return;
|
||||||
|
|
|
||||||
Reference in New Issue