This commit is contained in:
parent
6d4076969e
commit
c442e1aa47
@ -4,29 +4,16 @@ import * as mediasoupClient from 'mediasoup-client'
|
|||||||
import { io } from 'socket.io-client'
|
import { io } from 'socket.io-client'
|
||||||
|
|
||||||
const ICE_SERVERS: RTCIceServer[] = [
|
const ICE_SERVERS: RTCIceServer[] = [
|
||||||
// {
|
{ urls: 'stun:stun.l.google.com:19302' },
|
||||||
// urls: 'stun:stun.relay.metered.ca:80',
|
{ urls: 'stun:stun.l.google.com:5349' },
|
||||||
// },
|
{ urls: 'stun:stun1.l.google.com:3478' },
|
||||||
// {
|
{ urls: 'stun:stun1.l.google.com:5349' },
|
||||||
// urls: 'turn:global.relay.metered.ca:80',
|
{ urls: 'stun:stun2.l.google.com:19302' },
|
||||||
// username: '4cad09c0111f423f5283814c',
|
{ urls: 'stun:stun2.l.google.com:5349' },
|
||||||
// credential: 'B1dO8AGehex4o3pt',
|
{ urls: 'stun:stun3.l.google.com:3478' },
|
||||||
// },
|
{ urls: 'stun:stun3.l.google.com:5349' },
|
||||||
// {
|
{ urls: 'stun:stun4.l.google.com:19302' },
|
||||||
// urls: 'turn:global.relay.metered.ca:80?transport=tcp',
|
{ urls: 'stun:stun4.l.google.com:5349' },
|
||||||
// username: '4cad09c0111f423f5283814c',
|
|
||||||
// credential: 'B1dO8AGehex4o3pt',
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// urls: 'turn:global.relay.metered.ca:443',
|
|
||||||
// username: '4cad09c0111f423f5283814c',
|
|
||||||
// credential: 'B1dO8AGehex4o3pt',
|
|
||||||
// },
|
|
||||||
{
|
|
||||||
urls: 'turns:global.relay.metered.ca:443?transport=tcp',
|
|
||||||
username: '4cad09c0111f423f5283814c',
|
|
||||||
credential: 'B1dO8AGehex4o3pt',
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
export const useMediasoup = createGlobalState(() => {
|
export const useMediasoup = createGlobalState(() => {
|
||||||
@ -42,7 +29,17 @@ export const useMediasoup = createGlobalState(() => {
|
|||||||
let sendTransport: mediasoupClient.types.Transport
|
let sendTransport: mediasoupClient.types.Transport
|
||||||
let recvTransport: mediasoupClient.types.Transport
|
let recvTransport: mediasoupClient.types.Transport
|
||||||
|
|
||||||
|
socket.on('producers', async (producers) => {
|
||||||
|
for (const producer of producers) {
|
||||||
|
await consume(producer.producerId)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
socket.on('newProducer', async ({ producerId }) => {
|
socket.on('newProducer', async ({ producerId }) => {
|
||||||
|
await consume(producerId)
|
||||||
|
})
|
||||||
|
|
||||||
|
async function consume(producerId: number) {
|
||||||
const params = await socket.emitWithAck('consume', {
|
const params = await socket.emitWithAck('consume', {
|
||||||
producerId,
|
producerId,
|
||||||
transportId: recvTransport.id,
|
transportId: recvTransport.id,
|
||||||
@ -59,7 +56,7 @@ export const useMediasoup = createGlobalState(() => {
|
|||||||
|
|
||||||
streams.value.push(stream)
|
streams.value.push(stream)
|
||||||
triggerRef(streams)
|
triggerRef(streams)
|
||||||
})
|
}
|
||||||
|
|
||||||
async function loadDevice() {
|
async function loadDevice() {
|
||||||
device = new mediasoupClient.Device()
|
device = new mediasoupClient.Device()
|
||||||
|
|||||||
@ -48,6 +48,13 @@ createWorker();
|
|||||||
io.on("connection", (socket) => {
|
io.on("connection", (socket) => {
|
||||||
console.log("Client connected:", socket.id);
|
console.log("Client connected:", socket.id);
|
||||||
|
|
||||||
|
socket.emit('producers', producers.values().map(producer => {
|
||||||
|
return {
|
||||||
|
producerId: producer.id,
|
||||||
|
kind: producer.kind,
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
|
||||||
socket.on("getRtpCapabilities", (cb) => {
|
socket.on("getRtpCapabilities", (cb) => {
|
||||||
cb(router.rtpCapabilities);
|
cb(router.rtpCapabilities);
|
||||||
});
|
});
|
||||||
@ -103,7 +110,7 @@ io.on("connection", (socket) => {
|
|||||||
producers.set(socket.id, [...(producers.get(socket.id) || []), producer]);
|
producers.set(socket.id, [...(producers.get(socket.id) || []), producer]);
|
||||||
|
|
||||||
cb({ id: producer.id });
|
cb({ id: producer.id });
|
||||||
socket.broadcast.emit("newProducer", { producerId: producer.id });
|
socket.broadcast.emit("newProducer", { producerId: producer.id, kind: producer.kind });
|
||||||
|
|
||||||
producer.observer.on("close", () => {
|
producer.observer.on("close", () => {
|
||||||
console.log("producer closed", producer.id);
|
console.log("producer closed", producer.id);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user