Permalink
Browse files

update embed code and remove extra var image

  • Loading branch information...
moeiscool committed May 12, 2018
1 parent 94182a1 commit 4bf071abb5706f9240f32617bf3bb4b8aa52f3ca
Showing with 32 additions and 31 deletions.
  1. +0 −1 web/libs/js/main.dash2.js
  2. +32 −30 web/pages/embed.ejs
@@ -1871,7 +1871,6 @@ $.ccio.globalWebsocket=function(d,user){
// var base64Frame = 'data:image/jpeg;base64,'+$.ccio.base64ArrayBuffer(imageData)
$.ccio.mon[d.ke+d.id+user.auth_token].imageLoading = true
// $.ccio.mon[d.ke+d.id+user.auth_token].image.src = base64Frame
var image = ctx2d.createImageData(ctx.width, ctx.height)
var arrayBufferView = new Uint8Array(imageData);
var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
$.ccio.mon[d.ke+d.id+user.auth_token].imageUrl = URL.createObjectURL( blob );
@@ -185,38 +185,40 @@ $(document).ready(function(){
id:d.id,
url: '<%=data.url%>'
})
ws.on('data',function(base64){
console.log(base64)
if(!$.shinobi.mon[d.id].ctx||$.shinobi.mon[d.id].ctx.length===0){
$.shinobi.mon[d.id].ctx = $('#SHINOBI_'+d.ke+'_'+d.id+' .stream-element')
}
var ctx = $.shinobi.mon[d.id].ctx[0]
$.shinobi.mon[d.id].image = new Image()
var image = $.shinobi.mon[d.id].image
image.onload = function() {
$.shinobi.mon[d.id].imageLoading = false
d.x = 0
d.y = 0
// d.ratio = Math.min(ctx.width/image.width,ctx.height/image.height)
// d.height = image.height * d.ratio
// d.width = image.width * d.ratio
// if(d.width < ctx.width){
// d.x = (ctx.width / 2) - (d.width / 2)
// }
// if(d.height < ctx.height){
// d.y = (ctx.height / 2) - (d.height / 2)
// }
// ctx.getContext("2d").drawImage(image,d.x,d.y,d.width,d.height)
ctx.getContext("2d").drawImage(image,d.x,d.y,ctx.width,ctx.height)
URL.revokeObjectURL($.ccio.mon[d.ke+d.id+user.auth_token].imageUrl)
}
ws.on('data',function(imageData){
try{
if($.shinobi.mon[d.id].imageLoading === true)return
if(!$.shinobi.mon[d.id].ctx||$.shinobi.mon[d.id].ctx.length===0){
$.shinobi.mon[d.id].ctx = $('#SHINOBI_'+d.ke+'_'+d.id+' .stream-element')
}
var ctx = $.shinobi.mon[d.id].ctx[0]
if(!$.shinobi.mon[d.id].image){
$.shinobi.mon[d.id].image = new Image()
var image = $.shinobi.mon[d.id].image
image.onload = function() {
$.shinobi.mon[d.id].imageLoading = false
d.x = 0
d.y = 0
// d.ratio = Math.min(ctx.width/image.width,ctx.height/image.height)
// d.height = image.height * d.ratio
// d.width = image.width * d.ratio
// if(d.width < ctx.width){
// d.x = (ctx.width / 2) - (d.width / 2)
// }
// if(d.height < ctx.height){
// d.y = (ctx.height / 2) - (d.height / 2)
// }
// ctx.getContext("2d").drawImage(image,d.x,d.y,d.width,d.height)
ctx.getContext("2d").drawImage(image,d.x,d.y,ctx.width,ctx.height)
}
}
var base64Frame = 'data:image/jpeg;base64,'+base64
if($.shinobi.mon[d.id].imageLoading === true)return console.log('drop');
// var base64Frame = 'data:image/jpeg;base64,'+$.ccio.base64ArrayBuffer(imageData)
$.shinobi.mon[d.id].imageLoading = true
$.shinobi.mon[d.id].image.src = base64Frame
$.shinobi.mon[d.id].last_frame = base64Frame
// $.shinobi.mon[d.id].image.src = base64Frame
var arrayBufferView = new Uint8Array(imageData);
var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
$.shinobi.mon[d.id].imageUrl = URL.createObjectURL( blob );
$.shinobi.mon[d.id].image.src = $.shinobi.mon[d.id].imageUrl
$.shinobi.mon[d.id].last_frame = 'data:image/jpeg;base64,'+$.ccio.base64ArrayBuffer(imageData)
}catch(er){
console.log(er)
$.ccio.log('base64 frame')

0 comments on commit 4bf071a

Please sign in to comment.