Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Janus.debug("streamsDone:", stream);
config.myStream = stream;
var pc_config = {"iceServers": iceServers};
//~ var pc_constraints = {'mandatory': {'MozDontOfferDataChannel':true}};
var pc_constraints = {
"optional": [{"DtlsSrtpKeyAgreement": true}]
};
if(ipv6Support === true) {
// FIXME This is only supported in Chrome right now
// For support in Firefox track this: https://bugzilla.mozilla.org/show_bug.cgi?id=797262
pc_constraints.optional.push({"googIPv6":true});
}
Janus.log("Creating PeerConnection");
console.log("Creating PeerConnection");
Janus.debug(pc_constraints);
config.pc = new RTCPeerConnection(pc_config, pc_constraints);
Janus.debug(config.pc);
console.log(config.pc);
if(config.pc.getStats) { // FIXME
config.volume.value = 0;
config.bitrate.value = "0 kbits/sec";
}
Janus.log("Preparing local SDP and gathering candidates (trickle=" + config.trickle + ")");
console.log("Preparing local SDP and gathering candidates (trickle=" + config.trickle + ")");
config.pc.onicecandidate = function(event) {
// console.log("config.pc.onicecandidate")
// if (event.candidate == null ||
// (webrtcDetectedBrowser === 'edge' && event.candidate.candidate.indexOf('endOfCandidates') > 0)) {
// Janus.log("End of candidates.");
// config.iceDone = true;
const webrtcMiddleware = (function() {
let socketId = null;
const configuration = {"iceServers": [{"url": "stun:stun.l.google.com:19302"}]};
const connection = {'optional': [{'DtlsSrtpKeyAgreement': true}, {'RtpDataChannels': true }]};
const peerconn = new RTCPeerConnection(configuration, connection);
// const sdpConstraints = {'mandatory': { 'OfferToReceiveAudio': false, 'OfferToReceiveVideo': false }};
const offerOpts = { offertoreceiveaudio: false, offertoreceivevideo: false }
peerconn.onnegotiationneeded = function(event) {
console.log('onnegotiationneeded');
};
peerconn.oniceconnectionstatechange = function(event) {
console.log('oniceconnectionstatechange');
};
peerconn.onsignalingstatechange = function() {
console.log('onsignalingstatechange');
};
peerconn.onaddstream = function() {
console.log('onaddstream');
};
peerconn.onremovestream = function() {
// TODO
}
// Until we implement the proxying of open requests within the Janus core, we open a channel ourselves whatever the case
config.dataChannel = config.pc.createDataChannel("JanusDataChannel", {ordered:false}); // FIXME Add options (ordered, maxRetransmits, etc.)
config.dataChannel.onmessage = onDataChannelMessage;
config.dataChannel.onopen = onDataChannelStateChange;
config.dataChannel.onclose = onDataChannelStateChange;
config.dataChannel.onerror = onDataChannelError;
}
// Create offer/answer now
if(jsep === null || jsep === undefined) {
console.log("createOffer")
createOffer(handleId, media, callbacks);
} else {
config.pc.setRemoteDescription(
new RTCSessionDescription(jsep),
function() {
Janus.log("Remote description accepted!");
createAnswer(handleId, media, callbacks);
}, callbacks.error);
}
}
};
constraints.video.mandatory.chromeMediaSourceId = event.data.sourceId;
getScreenMedia(constraints, callback);
}
} else if (event.data.type == 'janusGetScreenPending') {
window.clearTimeout(event.data.id);
}
});
return;
}
}
// If we got here, we're not screensharing
if(media === null || media === undefined || media.video !== 'screen') {
// Check whether all media sources are actually available or not
MediaStreamTrack.getSources(sourceInfos => {
console.log(sourceInfos);
getUserMedia({
audio: true,
video: {
facingMode: (true ? "user" : "environment"),
}
}, (stream) => {
localStream = stream
console.log("Succeeded to get the local camera!")
streamsDone(handleId, jsep, media, callbacks, stream)
}, (error) => {
console.log("Failed to get the local camera!")
console.log(error)
}
)
});
initWebRTC(cb) {
let isFront = true;
let self = this;
MediaStreamTrack.getSources(sourceInfos => {
console.log(sourceInfos);
let videoSourceId = self.options.useOTG ? "UVCCamera" : undefined;
// for (const i = 0; i < sourceInfos.length; i++) {
// const sourceInfo = sourceInfos[i];
// if (sourceInfo.kind == "video" && sourceInfo.facing == (isFront ? "front" : "back")) {
// videoSourceId = sourceInfo.id;
// }
// }
let constraints = {
audio: true,
video: {
mandatory: {
minWidth: 1280, // Provide your own width, height and frame rate here
minHeight: 720,
minFrameRate: 30
},
setIceCandidate = async (candidate) => {
try {
// set ice candidate
if (this.connection && candidate) {
await this.connection.addIceCandidate(new RTCIceCandidate(candidate));
}
} catch (err) {
// error setting ice candidate?
console.log(err);
}
};
// videoSourceId = sourceInfo.id;
// }
// }
let constraints = {
audio: true,
video: {
mandatory: {
minWidth: 1280, // Provide your own width, height and frame rate here
minHeight: 720,
minFrameRate: 30
},
facingMode: (isFront ? "user" : "environment"),
optional: (videoSourceId ? [{ sourceId: videoSourceId }] : [])
}
};
getUserMedia(constraints, function (stream) {
self.state.localStream = stream;
self.initJanus(self.state.url, cb);
}, console.log);
});
}
//~ var pc_constraints = {'mandatory': {'MozDontOfferDataChannel':true}};
var pc_constraints = {
"optional": [{ "DtlsSrtpKeyAgreement": true }]
};
if (ipv6Support === true) {
// FIXME This is only supported in Chrome right now
// For support in Firefox track this: https://bugzilla.mozilla.org/show_bug.cgi?id=797262
pc_constraints.optional.push({ "googIPv6": true });
}
if (adapter.browserDetails.browser === "edge") {
// This is Edge, enable BUNDLE explicitly
pc_config.bundlePolicy = "max-bundle";
}
Janus.log("Creating PeerConnection");
Janus.debug(pc_constraints);
config.pc = new RTCPeerConnection(pc_config, pc_constraints);
Janus.debug(config.pc);
if (config.pc.getStats) { // FIXME
config.volume.value = 0;
config.bitrate.value = "0 kbits/sec";
}
Janus.log("Preparing local SDP and gathering candidates (trickle=" + config.trickle + ")");
config.pc.oniceconnectionstatechange = function (e) {
if (config.pc)
pluginHandle.iceState(config.pc.iceConnectionState);
};
config.pc.onicecandidate = function (event) {
if (event.candidate == null ||
(adapter.browserDetails.browser === 'edge' && event.candidate.candidate.indexOf('endOfCandidates') > 0)) {
Janus.log("End of candidates.");
config.iceDone = true;
if (config.trickle === true) {
callbacks.error("Invalid handle");
return;
}
var config = pluginHandle.webrtcStuff;
if (jsep !== undefined && jsep !== null) {
if (config.pc === null) {
Janus.warn("Wait, no PeerConnection?? if this is an answer, use createAnswer and not handleRemoteJsep");
callbacks.error("No PeerConnection: if this is an answer, use createAnswer and not handleRemoteJsep");
return;
}
if (adapter.browserDetails.browser === "edge") {
// This is Edge, add an a=end-of-candidates at the end
jsep.sdp += "a=end-of-candidates\r\n";
}
config.pc.setRemoteDescription(
new RTCSessionDescription(jsep),
function () {
Janus.log("Remote description accepted!");
callbacks.success();
}, callbacks.error);
} else {
callbacks.error("Invalid JSEP");
}
}
config.dataChannel = config.pc.createDataChannel("JanusDataChannel", { ordered: false }); // FIXME Add options (ordered, maxRetransmits, etc.)
config.dataChannel.onmessage = onDataChannelMessage;
config.dataChannel.onopen = onDataChannelStateChange;
config.dataChannel.onclose = onDataChannelStateChange;
config.dataChannel.onerror = onDataChannelError;
}
// Create offer/answer now
if (jsep === null || jsep === undefined) {
createOffer(handleId, media, callbacks);
} else {
if (adapter.browserDetails.browser === "edge") {
// This is Edge, add an a=end-of-candidates at the end
jsep.sdp += "a=end-of-candidates\r\n";
}
config.pc.setRemoteDescription(
new RTCSessionDescription(jsep),
function () {
Janus.log("Remote description accepted!");
createAnswer(handleId, media, callbacks);
}, callbacks.error);
}
}