Skip to content

Instantly share code, notes, and snippets.

@jefBinomed
Created June 17, 2015 14:50
Show Gist options
  • Save jefBinomed/1d548336d9e66db196ba to your computer and use it in GitHub Desktop.
Save jefBinomed/1d548336d9e66db196ba to your computer and use it in GitHub Desktop.
Programmez-07/08_2015-PortalWebrtc-05
var init = false;
function snapshot(){
var canvasToUse = canvasRemoteElement;
var contextToUse = ctxRemote;
varvideoToUse = remoteVideo;
canvasRemoteElement.width = remoteVideo.videoWidth;
canvasRemoteElement.height = remoteVideo.videoHeight;
if (remoteStream){
ctxRemote.drawImage(remoteVideo,0,0);
}
var idealWidth = Math.min(canvasToUse.parentElement.clientWidth,videoToUse.video
Width + 100);
varminVideoWidth = Math.min(canvasToUse.parentElement.clientWidth -50,videoToUse.
videoWidth);
var ratio = videoToUse.videoWidth /videoToUse.videoHeight;
var idealHeight = Math.min(idealWidth / ratio,videoToUse.videoHeight);
varuseVideoWidth = idealWidth === videoToUse.videoWidth + 100;
canvasToUse.width = idealWidth; //landscapeMode? idealHeight : idealWidth;
canvasToUse.height = canvasToUse.width;
canvasToUse.style.top = ((canvasToUse.parentElement.clientHeight - canvasToUse.
height) /2)+"px";
canvasToUse.style.left = ((canvasToUse.parentElement.clientWidth - canvasToUse.
width) /2)+"px";
canvasFireElement.width = idealWidth;// landscapeMode? idealHeight : idealWidth;
canvasFireElement.height = canvasFireElement.width;
canvasFireElement.style.top = ((canvasToUse.parentElement.clientHeight - canvasFire
Element.height) /2)+"px";
canvasFireElement.style.left = ((canvasToUse.parentElement.clientWidth - canvasFire
Element.width) /2)+"px";
var refValue = idealWidth;
if (localStream){
if (!init
&& canvasToUse.width == Math.round(refValue)
&& canvasToUse.height == Math.round(refValue)
&& canvasFireElement.width == Math.round(refValue)
&& canvasFireElement.height == Math.round(refValue)){
if (canvasFireElement.width != 100){
init = true;
canvasDemo.canvas = document.getElementById('canvasFireLocalVideo');
canvasDemo.init();
}
}
if (init){
canvasDemo.refresh();
}
}
window.requestAnimationFrame(snapshot);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment