@bddh/starling-realtime-client
Version:
2 lines (1 loc) • 4.51 kB
JavaScript
var e="starling-cutout-canvas",t="cloud-brtc-player-wrapper",n="remotevideo500",i="canvas-item",o="starling-last-frame-cover-canvas",a="data-dh-last-frame-cover";function d(i){var o=i.autoChromaKey,a=void 0!==o&&o,d=i.autoplay,r=void 0===d||d;if(document.getElementById(n))return console.error('DOM with id "'.concat(n,'" already exists.')),null;var l=document.createElement("div");l.className=t,l.id=t,l.style.position="relative";var c=document.createElement("video");if(c.id=n,c.width=0,c.height=0,c.setAttribute("width","100%"),c.setAttribute("height","100%"),c.setAttribute("data-playing","true"),c.setAttribute("playsinline",""),r&&c.setAttribute("autoplay",""),l.appendChild(c),a){var u=document.createElement("canvas");u.id=e,Object.assign(u.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:a?"block":"none"}),c.style.visibility="hidden",l.appendChild(u)}return{playerWrapper:l,video:c}}function r(){if(document.getElementById(e))return!0;var i=document.getElementById(t),o=document.getElementById(n);if(!i||!o)return!1;var a=document.createElement("canvas");return a.id=e,Object.assign(a.style,{position:"absolute",top:"0",left:"0",height:"100%",width:"100%",zIndex:"1",display:"block"}),o.style.visibility="hidden",i.appendChild(a),!0}function l(e){if(e&&!e.querySelector("[".concat(a,'="1"]'))){var t=document.createElement("div");t.className="".concat(i," "),t.setAttribute(a,"1");var n=document.createElement("canvas");n.id=o,Object.assign(n.style,{position:"absolute",top:"0",left:"0",width:"100%",height:"100%",objectFit:"cover",display:"block",zIndex:"0"}),t.appendChild(n),e.appendChild(t)}}function c(){var t=document.getElementById(o);if(!t)return!1;var i=t.getContext("2d");if(!i)return!1;var a=document.getElementById(e),d=document.getElementById(n);return a&&a.width>0&&a.height>0?(t.width=a.width,t.height=a.height,i.drawImage(a,0,0),!0):!!(d&&d.videoWidth>0&&d.videoHeight>0)&&(t.width=d.videoWidth,t.height=d.videoHeight,i.drawImage(d,0,0,d.videoWidth,d.videoHeight),!0)}function u(e){var n=document.getElementById(t);n&&(n.style.visibility=e?"visible":"hidden",n.style.pointerEvents=e?"":"none")}function h(e){var t=document.getElementById(o),n=null==t?void 0:t.parentNode;n&&(n.style.visibility=e?"visible":"hidden")}function s(){var e=document.querySelector("[".concat(a,'="1"]'));null!=e&&e.parentNode&&e.parentNode.removeChild(e)}function v(){var e=document.getElementById(t);e&&e.parentNode&&e.parentNode.removeChild(e)}function m(e){var t=document.getElementById(n);return t&&(t.muted=e),t}function p(e){var t=document.getElementById(n);try{if(t)return e?t.play():t.pause()}catch(e){console.info(e)}}function y(){var e=navigator.userAgent||navigator.vendor;return/huawei/i.test(e)||/honor/i.test(e)}function g(){var e=document.createElement("style");e.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(e)}export{e as DEFAULT_CANVAS_ID,t as HUMAN_WRAPPER_ID,i as LAST_FRAME_COVER_CANVAS_CLASS,o as LAST_FRAME_COVER_INNER_CANVAS_ID,n as RTC_VIDEO_ID,l as appendLastFrameCoverSibling,g as appendRtcDomStyle,c as captureLastFrameToCover,y as checkIsHuawei,d as createHumanDom,r as ensureCutoutDomMounted,m as muteHumanVideo,p as playHumanVideo,v as removeHumanDom,s as removeLastFrameCoverWrapper,u as setHumanPlayerWrapperVisible,h as setLastFrameCoverVisible};