import { ConsumerType , Producer , Router , RtpCapabilities , RtpParameters , Transport , } from "mediasoup/lib/types" ; import { MyPeer } from "../MyPeer" ; export const createConsumer = async ( router , producer , rtpCapabilities , transport , peerId , peerConsuming ) : Promise < Consumer > => { if ( ! router . canConsume ( { producerId : producer . id , rtpCapabilities } ) ) { throw new Error ( `recv-track: client cannot consume ${ producer . appData . peerId }` ) ; } const consumer = await transport . consume ( { producerId : producer . id , rtpCapabilities , paused : false , appData : { peerId , mediaPeerId : producer . appData . peerId } , } ) ; peerConsuming . consumers . push ( consumer ) ; return { peerId : producer . appData . peerId , consumerParameters : { producerId : producer . id , id : consumer . id , kind : consumer . kind , rtpParameters : consumer . rtpParameters , type : consumer . type , producerPaused : consumer . producerPaused , } , } ; } ; export interface Consumer { peerId : string ; consumerParameters : { producerId : string ; id : string ; kind : string ; rtpParameters : RtpParameters ; type : ConsumerType ; producerPaused : boolean ; } ; } ;