I’m using mediasoap and typescript in an express server application and here’s the Broadcast
type that i defined which has a property of type Router
(a class defined in mediasoup module) and here’s the problem:
Upon creating an instance of broadcast the router does not get created properly and here’s why:
- I cannot log the created object in console (
console.log
output:[object Object]
) - There’s an array as a 3rd level nested property in router object called
codecs
, which is very important and it doesn’t get set upon creation.
But when I create the router object separately it works just fine! even if I create the broadcast object with a null value for the router and then set the router property with the separately created fine working router object it again stops behaving properly
Broadcast Class:
import { types } from "mediasoup";
export class Broadcast {
Id: string;
Title: string;
Router: types.Router;
Streamer: Streamer;
Participants: Array<Participant>;
}
Here’s a scenario to demonstrate the problem
BroadcastService Class:
export class BroadcastService {
_streamerService: StreamerService;
constructor() {
this._streamerService = new StreamerService();
}
async CreateBroadcast(title: string, streamer: Streamer): Promise<Broadcast> {
var broadcast: Broadcast = {
Title: title,
Id: uuidv4(),
Streamer: this._streamerService.CreateStreamer(streamer.Id),
Router: null,
Participants: new Array<Participant>()
};
return broadcast;
}
}
Separated Instantiation:
var broadcast = await broadcastService.CreateBroadcast();
console.log(broadcast.Router); // null due to Broadcast constructor
var mediaCodecs = config.router.mediaCodecs;
var router = await this.Worker.createRouter({ mediaCodecs });
console.log(router.rtpCapabilities.codecs); // logs the correct codecs
broadcast.Router = router;
console.log(broadcast.Router.rtpCapabilities.codecs); // result: [object Object],[object Object],[object Object]