UNPKG

@bddh/starling-realtime-client

Version:

2 lines (1 loc) 5.78 kB
"use strict";var HUMAN_WRAPPER_ID="cloud-brtc-player-wrapper",RTC_VIDEO_ID="remotevideo500";exports.DEFAULT_CANVAS_ID="starling-cutout-canvas",exports.HUMAN_WRAPPER_ID=HUMAN_WRAPPER_ID,exports.LAST_FRAME_COVER_CANVAS_CLASS="canvas-item",exports.LAST_FRAME_COVER_INNER_CANVAS_ID="starling-last-frame-cover-canvas",exports.RTC_VIDEO_ID=RTC_VIDEO_ID,exports.appendLastFrameCoverSibling=function(mountEl){if(mountEl&&!mountEl.querySelector("[".concat("data-dh-last-frame-cover",'="1"]'))){var wrap=document.createElement("div");wrap.className="".concat("canvas-item"," "),wrap.setAttribute("data-dh-last-frame-cover","1");var canvas=document.createElement("canvas");canvas.id="starling-last-frame-cover-canvas",Object.assign(canvas.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",objectFit:"cover",display:"block",zIndex:"0"}),wrap.appendChild(canvas),mountEl.appendChild(wrap)}},exports.appendRtcDomStyle=function(){var style=document.createElement("style");style.appendChild(document.createTextNode('\n [id^="videoremote1-"] {\n display: none !important;\n }\n \n video#remotevideo500 {\n width: auto !important;\n height: auto !important;\n max-width: 100% !important;\n max-height: 100% !important;\n width: 100% !important;\n height: 100% !important;\n object-fit: cover;\n }\n\n .cloud-brtc-player-wrapper {\n width: inherit !important;\n background-size: cover;\n height: inherit;\n display: flex;\n justify-content: center;\n }\n\n #starling-cutout-canvas {\n object-fit: cover;\n }\n\n [data-dh-last-frame-cover="1"] {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n z-index: 1;\n visibility: hidden;\n }\n\n [data-dh-last-frame-cover="1"] canvas {\n width: 100%;\n height: 100%;\n object-fit: cover;\n display: block;\n }\n ')),document.head.appendChild(style)},exports.captureLastFrameToCover=function(){var cover=document.getElementById("starling-last-frame-cover-canvas");if(!cover)return!1;var ctx=cover.getContext("2d");if(!ctx)return!1;var chroma=document.getElementById("starling-cutout-canvas"),video=document.getElementById(RTC_VIDEO_ID);return chroma&&chroma.width>0&&chroma.height>0?(cover.width=chroma.width,cover.height=chroma.height,ctx.drawImage(chroma,0,0),!0):!!(video&&video.videoWidth>0&&video.videoHeight>0)&&(cover.width=video.videoWidth,cover.height=video.videoHeight,ctx.drawImage(video,0,0,video.videoWidth,video.videoHeight),!0)},exports.checkIsHuawei=function(){var ua=navigator.userAgent||navigator.vendor;return/huawei/i.test(ua)||/honor/i.test(ua)},exports.createHumanDom=function(options){var _options$autoChromaKe=options.autoChromaKey,autoChromaKey=void 0!==_options$autoChromaKe&&_options$autoChromaKe,_options$autoplay=options.autoplay,autoplay=void 0===_options$autoplay||_options$autoplay;if(document.getElementById(RTC_VIDEO_ID))return console.error('DOM with id "'.concat(RTC_VIDEO_ID,'" already exists.')),null;var playerWrapper=document.createElement("div");playerWrapper.className=HUMAN_WRAPPER_ID,playerWrapper.id=HUMAN_WRAPPER_ID,playerWrapper.style.position="relative";var video=document.createElement("video");if(video.id=RTC_VIDEO_ID,video.width=0,video.height=0,video.setAttribute("width","100%"),video.setAttribute("height","100%"),video.setAttribute("data-playing","true"),video.setAttribute("playsinline",""),autoplay&&video.setAttribute("autoplay",""),playerWrapper.appendChild(video),autoChromaKey){var canvas=document.createElement("canvas");canvas.id="starling-cutout-canvas",Object.assign(canvas.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:autoChromaKey?"block":"none"}),video.style.visibility="hidden",playerWrapper.appendChild(canvas)}return{playerWrapper:playerWrapper,video:video}},exports.ensureCutoutDomMounted=function(){if(document.getElementById("starling-cutout-canvas"))return!0;var wrapper=document.getElementById(HUMAN_WRAPPER_ID),video=document.getElementById(RTC_VIDEO_ID);if(!wrapper||!video)return!1;var canvas=document.createElement("canvas");return canvas.id="starling-cutout-canvas",Object.assign(canvas.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:"block"}),video.style.visibility="hidden",wrapper.appendChild(canvas),!0},exports.muteHumanVideo=function(muted){var humanVideoDom=document.getElementById(RTC_VIDEO_ID);return humanVideoDom&&(humanVideoDom.muted=muted),humanVideoDom},exports.playHumanVideo=function(play){var humanVideoDom=document.getElementById(RTC_VIDEO_ID);try{if(humanVideoDom)return play?humanVideoDom.play():humanVideoDom.pause()}catch(e){console.info(e)}},exports.removeHumanDom=function(){var humanDom=document.getElementById(HUMAN_WRAPPER_ID);humanDom&&humanDom.parentNode&&humanDom.parentNode.removeChild(humanDom)},exports.removeLastFrameCoverWrapper=function(){var wrap=document.querySelector("[".concat("data-dh-last-frame-cover",'="1"]'));null!=wrap&&wrap.parentNode&&wrap.parentNode.removeChild(wrap)},exports.setHumanPlayerWrapperVisible=function(visible){var el=document.getElementById(HUMAN_WRAPPER_ID);el&&(el.style.visibility=visible?"visible":"hidden",el.style.pointerEvents=visible?"":"none")},exports.setLastFrameCoverVisible=function(visible){var inner=document.getElementById("starling-last-frame-cover-canvas"),wrap=null==inner?void 0:inner.parentNode;wrap&&(wrap.style.visibility=visible?"visible":"hidden")};