Hi, thanks for the reply and sorry if the following is a bit wack, I’m still learning so I’ll do my best at explaining.
I need to run const device = new Device();
to create the device object for my mediasoup client. I have to run this in my front-end as it has to be exposed to the chromium front-end to detect the browser (As I assume you cannot construct the device object without exposure to the browser.) This works.
However, I then have to load the rtp capabilities (ie await device.load({ routerRtpCapabilities });
).
If I try to load the capabilities inside the ‘frontend process’ I get an error of DOMException: Failed to execute 'structuredClone' on 'Window': function Array() { [native code] } could not be cloned.
node_modules\mediasoup-client\lib\utils.js
function clone(value) {
if (value === undefined) {
return undefined;
}
else if (Number.isNaN(value)) {
return NaN;
}
else if (typeof structuredClone === 'function') {
// Available in Node >= 18.
----> return structuredClone(value); <-- ERRORS HERE
}
else {
return JSON.parse(JSON.stringify(value));
}
}
If I attempt to return the Device object to the ‘back-end’ process to load the rtpcapabilities there, all functions have to be stripped (for inter-process communication via JSON). And therefore cannot be used to load the rtp capabilities once there.
(See below for comparison)
Correct Device Object
► _canProduceByKind: {audio: false, video: false}
_extendedRtpCapabilities: undefined
► _handlerFactory: () => new Chrome111()
_handlerName: "Chrome111"
_loaded: false
► _observer: EnhancedEventEmitter {_events: {…}, _eventsCount: 0, _maxListeners: Infinity, Symbol(kCapture): false}
_recvRtpCapabilities: undefined
_sctpCapabilities: undefined
handlerName: (...)
loaded: (...)
observer: (...)
rtpCapabilities: (...)
sctpCapabilities: (...)
▼ [[Prototype]]: Object
► canProduce: ƒ canProduce(kind)
► constructor: class Device
► createRecvTransport: ƒ createRecvTransport({ id, iceParameters, iceCandidates, dtlsParameters, sctpParameters, iceServers, iceTransportPolicy, additionalSettings, proprietaryConstraints, appData, })
► createSendTransport: ƒ createSendTransport({ id, iceParameters, iceCandidates, dtlsParameters, sctpParameters, iceServers, iceTransportPolicy, additionalSettings, proprietaryConstraints, appData, })
► createTransport: ƒ createTransport({ direction, id, iceParameters, iceCandidates, dtlsParameters, sctpParameters, iceServers, iceTransportPolicy, additionalSettings, proprietaryConstraints, appData, })
handlerName: (...)
► load: ƒ async load({ routerRtpCapabilities, })
loaded: (...)
observer: (...)
rtpCapabilities: (...)
sctpCapabilities: (...)
► get handlerName: ƒ handlerName()
► get loaded: ƒ loaded()
► get observer: ƒ observer()
► get rtpCapabilities: ƒ rtpCapabilities()
► get sctpCapabilities: ƒ sctpCapabilities()
► [[Prototype]]: Object
Copied Device Object
► _canProduceByKind: {audio: false, video: false}
_extendedRtpCapabilities: undefined
► _handlerFactory: ƒ ()
_handlerName: "Chrome111"
_loaded: false
► _observer: {_events: {…}, _eventsCount: 0, _maxListeners: Infinity, Symbol(kCapture): false}
_recvRtpCapabilities: undefined
_sctpCapabilities: undefined
▼ [[Prototype]]: Object
► constructor: ƒ Object()
► hasOwnProperty: ƒ hasOwnProperty()
► isPrototypeOf: ƒ isPrototypeOf()
► propertyIsEnumerable: ƒ propertyIsEnumerable()
► toLocaleString: ƒ toLocaleString()
► toString: ƒ toString()
► valueOf: ƒ valueOf()
► __defineGetter__: ƒ __defineGetter__()
► __defineSetter__: ƒ __defineSetter__()
► __lookupGetter__: ƒ __lookupGetter__()
► __lookupSetter__: ƒ __lookupSetter__()
► __proto__: (...)
► get __proto__: ƒ __proto__()
► set __proto__: ƒ __proto__()
Ideally it’s all in the main process, to expose as little as possible to the front end (for security in electron) and also the socket io server is all there so it reduces the amount of IPC needed. It seems from forum posts that Electron has been used with Mediasoup but I cant figure out how.
Any wisdom is appreciated, and thank you in advance.