提交 0322da07 authored 作者: Anthony Minessale's avatar Anthony Minessale

add local mute to verto

上级 a8bb1ca2
This diff was suppressed by a .gitattributes entry.
...@@ -77,6 +77,9 @@ ...@@ -77,6 +77,9 @@
useVideo: null, useVideo: null,
useStereo: false, useStereo: false,
userData: null, userData: null,
localVideo: null,
screenShare: false,
useCamera: "any",
iceServers: false, iceServers: false,
videoParams: {}, videoParams: {},
audioParams: {}, audioParams: {},
...@@ -84,9 +87,11 @@ ...@@ -84,9 +87,11 @@
onICEComplete: function() {}, onICEComplete: function() {},
onICE: function() {}, onICE: function() {},
onOfferSDP: function() {} onOfferSDP: function() {}
} },
}, options); }, options);
this.enabled = true;
this.mediaData = { this.mediaData = {
SDP: null, SDP: null,
profile: {}, profile: {},
...@@ -118,11 +123,12 @@ ...@@ -118,11 +123,12 @@
checkCompat(); checkCompat();
}; };
$.FSRTC.prototype.useVideo = function(obj) { $.FSRTC.prototype.useVideo = function(obj, local) {
var self = this; var self = this;
if (obj) { if (obj) {
self.options.useVideo = obj; self.options.useVideo = obj;
self.options.localVideo = local;
if (moz) { if (moz) {
self.constraints.offerToReceiveVideo = true; self.constraints.offerToReceiveVideo = true;
} else { } else {
...@@ -130,6 +136,7 @@ ...@@ -130,6 +136,7 @@
} }
} else { } else {
self.options.useVideo = null; self.options.useVideo = null;
self.options.localVideo = null;
if (moz) { if (moz) {
self.constraints.offerToReceiveVideo = false; self.constraints.offerToReceiveVideo = false;
} else { } else {
...@@ -196,8 +203,9 @@ ...@@ -196,8 +203,9 @@
doCallback(self, "onError", e); doCallback(self, "onError", e);
} }
function onStreamSuccess(self) { function onStreamSuccess(self, stream) {
console.log("Stream Success"); console.log("Stream Success");
doCallback(self, "onStream", stream);
} }
function onICE(self, candidate) { function onICE(self, candidate) {
...@@ -281,6 +289,7 @@ ...@@ -281,6 +289,7 @@
if (self.options.useVideo) { if (self.options.useVideo) {
self.options.useVideo.style.display = 'none'; self.options.useVideo.style.display = 'none';
self.options.useVideo[moz ? 'mozSrcObject' : 'src'] = "";
} }
if (self.localStream) { if (self.localStream) {
...@@ -288,17 +297,58 @@ ...@@ -288,17 +297,58 @@
self.localStream = null; self.localStream = null;
} }
if (self.options.localVideo) {
self.options.localVideo.style.display = 'none';
self.options.localVideo[moz ? 'mozSrcObject' : 'src'] = "";
}
if (self.options.localVideoStream) {
self.options.localVideoStream.stop();
}
if (self.peer) { if (self.peer) {
console.log("stopping peer"); console.log("stopping peer");
self.peer.stop(); self.peer.stop();
} }
}; };
$.FSRTC.prototype.createAnswer = function(sdp) { $.FSRTC.prototype.getMute = function() {
var self = this;
return self.enabled;
}
$.FSRTC.prototype.setMute = function(what) {
var self = this;
var audioTracks = self.localStream.getAudioTracks();
for (var i = 0, len = audioTracks.length; i < len; i++ ) {
switch(what) {
case "on":
audioTracks[i].enabled = true;
break;
case "off":
audioTracks[i].enabled = false;
break;
case "toggle":
audioTracks[i].enabled = !audioTracks[i].enabled;
default:
break;
}
self.enabled = audioTracks[i].enabled;
}
return !self.enabled;
}
$.FSRTC.prototype.createAnswer = function(params) {
var self = this; var self = this;
self.type = "answer"; self.type = "answer";
self.remoteSDP = sdp; self.remoteSDP = params.sdp;
console.debug("inbound sdp: ", sdp); console.debug("inbound sdp: ", params.sdp);
self.options.useCamera = params.useCamera || "any";
self.options.useMic = params.useMic || "any";
function onSuccess(stream) { function onSuccess(stream) {
self.localStream = stream; self.localStream = stream;
...@@ -336,53 +386,117 @@ ...@@ -336,53 +386,117 @@
onStreamError(self, e); onStreamError(self, e);
} }
var mediaParams = getMediaParams(self);
console.log("Audio constraints", mediaParams.audio);
console.log("Video constraints", mediaParams.video);
if (self.options.useVideo && self.options.localVideo) {
getUserMedia({
constraints: {
audio: false,
video: {
mandatory: self.options.videoParams,
optional: []
},
},
localVideo: self.options.localVideo,
onsuccess: function(e) {self.options.localVideoStream = e; console.log("local video ready");},
onerror: function(e) {console.error("local video error!");}
});
}
getUserMedia({
constraints: {
audio: mediaParams.audio,
video: mediaParams.video
},
video: mediaParams.useVideo,
onsuccess: onSuccess,
onerror: onError
});
};
function getMediaParams(obj) {
var audio; var audio;
if (this.options.videoParams && this.options.videoParams.chromeMediaSource == 'screen') { if (obj.options.videoParams && obj.options.screenShare) {//obj.options.videoParams.chromeMediaSource == 'desktop') {
this.options.videoParams = { //obj.options.videoParams = {
chromeMediaSource: 'screen', // chromeMediaSource: 'screen',
maxWidth:screen.width, // maxWidth:screen.width,
maxHeight:screen.height // maxHeight:screen.height
}; // chromeMediaSourceId = sourceId;
// };
console.error("SCREEN SHARE"); console.error("SCREEN SHARE");
audio = false; audio = false;
} else { } else {
audio = { audio = {
mandatory: this.options.audioParams, mandatory: obj.options.audioParams,
optional: [] optional: []
}; };
if (obj.options.useMic !== "any") {
audio.optional = [{sourceId: obj.options.useMic}]
}
} }
console.log("Mandatory audio constraints", this.options.audioParams); if (obj.options.useVideo && obj.options.localVideo) {
console.log("Mandatory video constraints", this.options.videoParams); getUserMedia({
constraints: {
audio: false,
video: {
mandatory: obj.options.videoParams,
optional: []
},
},
localVideo: obj.options.localVideo,
onsuccess: function(e) {self.options.localVideoStream = e; console.log("local video ready");},
onerror: function(e) {console.error("local video error!");}
});
}
getUserMedia({ var video = {
constraints: { mandatory: obj.options.videoParams,
audio: audio, optional: []
video: this.options.useVideo ? { }
mandatory: this.options.videoParams,
optional: [] var useVideo = obj.options.useVideo;
} : null
}, if (useVideo && obj.options.useCamera && obj.options.useCamera !== "none") {
video: this.options.useVideo ? true : false, if (obj.options.useCamera !== "any") {
onsuccess: onSuccess, video.optional = [{sourceId: obj.options.useCamera}]
onerror: onError }
}); } else {
video = null;
useVideo = null;
}
return {audio: audio, video: video, useVideo: useVideo};
}
};
$.FSRTC.prototype.call = function(profile) { $.FSRTC.prototype.call = function(profile) {
checkCompat(); checkCompat();
var self = this; var self = this;
var screen = false;
self.type = "offer"; self.type = "offer";
if (self.options.videoParams && self.options.screenShare) { //self.options.videoParams.chromeMediaSource == 'desktop') {
screen = true;
}
function onSuccess(stream) { function onSuccess(stream) {
self.localStream = stream; self.localStream = stream;
self.peer = RTCPeerConnection({ self.peer = RTCPeerConnection({
type: self.type, type: self.type,
...@@ -393,7 +507,7 @@ ...@@ -393,7 +507,7 @@
onICEComplete: function() { onICEComplete: function() {
return onICEComplete(self); return onICEComplete(self);
}, },
onRemoteStream: function(stream) { onRemoteStream: screen ? function(stream) {console.error("SKIP");} : function(stream) {
return onRemoteStream(self, stream); return onRemoteStream(self, stream);
}, },
onOfferSDP: function(sdp) { onOfferSDP: function(sdp) {
...@@ -409,53 +523,35 @@ ...@@ -409,53 +523,35 @@
iceServers: self.options.iceServers, iceServers: self.options.iceServers,
}); });
onStreamSuccess(self); onStreamSuccess(self, stream);
} }
function onError(e) { function onError(e) {
onStreamError(self, e); onStreamError(self, e);
} }
var mediaParams = getMediaParams(self);
var audio; console.log("Audio constraints", mediaParams.audio);
console.log("Video constraints", mediaParams.video);
if (this.options.videoParams && this.options.videoParams.chromeMediaSource == 'screen') {
this.options.videoParams = {
chromeMediaSource: 'screen',
maxWidth:screen.width,
maxHeight:screen.height
};
console.error("SCREEN SHARE");
audio = false;
} else {
audio = {
mandatory: this.options.audioParams,
optional: []
};
}
console.log("Mandatory audio constraints", this.options.audioParams);
console.log("Mandatory video constraints", this.options.videoParams);
getUserMedia({ getUserMedia({
constraints: { constraints: {
audio: audio, audio: mediaParams.audio,
video: this.options.useVideo ? { video: mediaParams.video
mandatory: this.options.videoParams,
optional: []
} : null
}, },
video: this.options.useVideo ? true : false, video: mediaParams.useVideo,
onsuccess: onSuccess, onsuccess: onSuccess,
onerror: onError onerror: onError
}); });
/* /*
navigator.getUserMedia({ navigator.getUserMedia({
video: this.options.useVideo, video: self.options.useVideo,
audio: true audio: true
}, onSuccess, onError); }, onSuccess, onError);
*/ */
...@@ -823,14 +919,22 @@ ...@@ -823,14 +919,22 @@
}); });
function streaming(stream) { function streaming(stream) {
var video = options.video; //var video = options.video;
if (video) { //var localVideo = options.localVideo;
video[moz ? 'mozSrcObject' : 'src'] = moz ? stream : window.webkitURL.createObjectURL(stream); //if (video) {
// video[moz ? 'mozSrcObject' : 'src'] = moz ? stream : window.webkitURL.createObjectURL(stream);
//video.play(); //video.play();
//}
if (options.localVideo) {
options.localVideo[moz ? 'mozSrcObject' : 'src'] = moz ? stream : window.webkitURL.createObjectURL(stream);
options.localVideo.style.display = 'block';
} }
if (options.onsuccess) { if (options.onsuccess) {
options.onsuccess(stream); options.onsuccess(stream);
} }
media = stream; media = stream;
} }
......
...@@ -1726,6 +1726,16 @@ ...@@ -1726,6 +1726,16 @@
}; };
$.verto.dialog.prototype.setMute = function(what) {
var dialog = this;
return dialog.rtc.setMute(what);
};
$.verto.dialog.prototype.getMute = function(what) {
var dialog = this;
return dialog.rtc.getMute(what);
};
$.verto.dialog.prototype.useStereo = function(on) { $.verto.dialog.prototype.useStereo = function(on) {
var dialog = this; var dialog = this;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论