Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const handleRouterRtpCapabilitiesRequest = async (jsonMessage) => {
const { routerRtpCapabilities, sessionId } = jsonMessage;
console.log('handleRouterRtpCapabilities() [rtpCapabilities:%o]', routerRtpCapabilities);
try {
const device = new mediasoup.Device();
// Load the mediasoup device with the router rtp capabilities gotten from the server
await device.load({ routerRtpCapabilities });
peer = new Peer(sessionId, device);
createTransport();
} catch (error) {
console.error('handleRouterRtpCapabilities() failed to init device [error:%o]', error);
socket.close();
}
};
export async function main() {
console.log(`starting up ... my peerId is ${myPeerId}`);
try {
device = new mediasoup.Device();
} catch (e) {
if (e.name === 'UnsupportedError') {
console.error('browser not supported for video calls');
return;
} else {
console.error(e);
}
}
// use sendBeacon to tell the server we're disconnecting when
// the page unloads
window.addEventListener('unload', () => sig('leave', {}, true));
}
global.kurento.rtp.sendEndpoint = kmsEndpoint;
console.log("SDP Offer from App to Kurento RTP SEND: %s\n", kmsSdpOffer);
const kmsSdpAnswer = await kmsEndpoint.processOffer(kmsSdpOffer);
console.log("SDP Answer from Kurento RTP SEND to App:\n%s", kmsSdpAnswer);
// WARNING: A real application would need to parse this SDP Answer and adapt
// to the parameters given in it, following the SDP Offer/Answer Model.
const kmsSdpAnswerObj = SdpTransform.parse(kmsSdpAnswer);
console.log("kmsSdpAnswerObj: %s", JSON.stringify(kmsSdpAnswerObj, null, 2));
// Build an RtpSendParameters from the Kurento SDP Answer,
// this gives us the Kurento RTP stream's SSRC, payload type, etc.
const kmsRtpCapabilities = MediasoupSdpUtils.extractRtpCapabilities({
sdpObject: kmsSdpAnswerObj
});
console.log(
"kmsRtpCapabilities: %s",
JSON.stringify(kmsRtpCapabilities, null, 2)
);
const msExtendedRtpCapabilities = MediasoupOrtc.getExtendedRtpCapabilities(
kmsRtpCapabilities,
global.mediasoup.router.rtpCapabilities
);
console.log(
"msExtendedRtpCapabilities: %s",
JSON.stringify(msExtendedRtpCapabilities, null, 2)
);
);
const msExtendedRtpCapabilities = MediasoupOrtc.getExtendedRtpCapabilities(
kmsRtpCapabilities,
global.mediasoup.router.rtpCapabilities
);
console.log(
"msExtendedRtpCapabilities: %s",
JSON.stringify(msExtendedRtpCapabilities, null, 2)
);
const kmsRtpSendParameters = MediasoupOrtc.getSendingRtpParameters(
"video",
msExtendedRtpCapabilities
);
kmsRtpSendParameters.encodings = MediasoupRtpUtils.getRtpEncodings({
sdpObject: kmsSdpAnswerObj,
kind: "video"
});
console.log(
"kmsRtpSendParameters: %s",
JSON.stringify(kmsRtpSendParameters, null, 2)
);
// mediasoup RTP producer (Receive media from Kurento)
// ---------------------------------------------------
const msProducer = await msTransport.produce({
kind: "video",
rtpParameters: kmsRtpSendParameters,
paused: false
});
const kmsSdpAnswerObj = SdpTransform.parse(kmsSdpAnswer);
console.log("kmsSdpAnswerObj: %s", JSON.stringify(kmsSdpAnswerObj, null, 2));
// Build an RtpSendParameters from the Kurento SDP Answer,
// this gives us the Kurento RTP stream's SSRC, payload type, etc.
const kmsRtpCapabilities = MediasoupSdpUtils.extractRtpCapabilities({
sdpObject: kmsSdpAnswerObj
});
console.log(
"kmsRtpCapabilities: %s",
JSON.stringify(kmsRtpCapabilities, null, 2)
);
const msExtendedRtpCapabilities = MediasoupOrtc.getExtendedRtpCapabilities(
kmsRtpCapabilities,
global.mediasoup.router.rtpCapabilities
);
console.log(
"msExtendedRtpCapabilities: %s",
JSON.stringify(msExtendedRtpCapabilities, null, 2)
);
const kmsRtpSendParameters = MediasoupOrtc.getSendingRtpParameters(
"video",
msExtendedRtpCapabilities
);
kmsRtpSendParameters.encodings = MediasoupRtpUtils.getRtpEncodings({
sdpObject: kmsSdpAnswerObj,
kind: "video"
});
});
console.log(
"kmsRtpCapabilities: %s",
JSON.stringify(kmsRtpCapabilities, null, 2)
);
const msExtendedRtpCapabilities = MediasoupOrtc.getExtendedRtpCapabilities(
kmsRtpCapabilities,
global.mediasoup.router.rtpCapabilities
);
console.log(
"msExtendedRtpCapabilities: %s",
JSON.stringify(msExtendedRtpCapabilities, null, 2)
);
const kmsRtpSendParameters = MediasoupOrtc.getSendingRtpParameters(
"video",
msExtendedRtpCapabilities
);
kmsRtpSendParameters.encodings = MediasoupRtpUtils.getRtpEncodings({
sdpObject: kmsSdpAnswerObj,
kind: "video"
});
console.log(
"kmsRtpSendParameters: %s",
JSON.stringify(kmsRtpSendParameters, null, 2)
);
// mediasoup RTP producer (Receive media from Kurento)
// ---------------------------------------------------
const msProducer = await msTransport.produce({
this._dispatch = dispatch;
// Redux store getState function.
this._getState = getState;
// This device
this._device = device;
// My peer name.
this._peerName = peerName;
// protoo-client Peer instance.
this._protoo = new protooClient.Peer(protooTransport);
// mediasoup-client Room instance.
this._room = new mediasoupClient.Room(ROOM_OPTIONS);
this._room.roomId = roomId;
// Transport for sending.
this._sendTransport = null;
// Transport for receiving.
this._recvTransport = null;
// Local mic mediasoup Producer.
this._micProducer = null;
// Local webcam mediasoup Producer.
this._webcamProducer = null;
// Map of webcam MediaDeviceInfos indexed by deviceId.
// @type {Map}
async function loadDevice(routerRtpCapabilities) {
try {
device = new mediasoup.Device();
} catch (error) {
if (error.name === 'UnsupportedError') {
console.error('browser not supported');
}
}
await device.load({ routerRtpCapabilities });
}
const socketRequest = SocketPromise(socket);
const uiVCodecName = document.querySelector(
"input[name='uiVCodecName']:checked"
).value;
const response = await socketRequest({
type: "START_MEDIASOUP",
vCodecName: uiVCodecName
});
const routerRtpCapabilities = response.data;
console.log("[server] mediasoup router created");
let device = null;
try {
device = new MediasoupClient.Device();
} catch (err) {
if (err.name === "UnsupportedError") {
console.error("mediasoup-client doesn't support this browser");
return;
}
}
global.mediasoup.device = device;
try {
await device.load({ routerRtpCapabilities });
} catch (err) {
if (err.name === "InvalidStateError") {
console.warn("mediasoup device was already loaded");
}
}
async function startMediasoup() {
const socket = global.server.socket;
const socketRequest = SocketPromise(socket);
const response = await socketRequest({ type: "START_MEDIASOUP" });
const routerRtpCapabilities = response.data;
console.log("[server] mediasoup router created");
let device = null;
try {
device = new MediasoupClient.Device();
} catch (err) {
if (err.name === "UnsupportedError") {
console.error("mediasoup-client doesn't support this browser");
return;
}
}
global.mediasoup.device = device;
try {
await device.load({ routerRtpCapabilities });
} catch (err) {
if (err.name === "InvalidStateError") {
console.warn("mediasoup device was already loaded");
}
}