JSFiddle - React, Tailwind, and code Playground
by morphcast
JavaScript
class ScriptLoader{static loadScript(e,t=null){return new Promise((a=>{const o=document.createElement("script");o.type="text/javascript",o.readyState?o.onreadystatechange=function(){"loaded"!==o.readyState&&"complete"!==o.readyState||(o.onreadystatechange=null,a())}:o.onload=function(){a()},t&&o.setAttribute("data-config",t),o.src=e,document.getElementsByTagName("head")[0].appendChild(o)}))}}function downloadAiSDK(){return null==ScriptLoader.p&&(ScriptLoader.p=ScriptLoader.loadScript("https://sdk.morphcast.com/mphtools/v1.1/mphtools.js","cameraPrivacyPopup, compatibilityUI, compatibilityAutoCheck").then((()=>ScriptLoader.loadScript("https://sdk.morphcast.com/emotion-statistics/v1.0-beta/script.js"))).then((()=>ScriptLoader.loadScript("https://ai-sdk.morphcast.com/v1.16/ai-sdk.js"))).then((()=>CY))),ScriptLoader.p}downloadAiSDK().then((e=>{const t={sendDatainterval:5e3,tickInterval:1e3,stopAfter:6e4,apiKey:"kkkk",licenseKey:"9087cfd2037a28a79769fdcaa4962252379cd2e2fd0b"},a=new MorphCastStatistics.StatisticsUploader(t);e.loader().licenseKey("9087cfd2037a28a79769fdcaa4962252379cd2e2fd0b").addModule(e.modules().FACE_AROUSAL_VALENCE.name,{smoothness:.7}).addModule(e.modules().FACE_ATTENTION.name,{smoothness:.83}).addModule(e.modules().DATA_AGGREGATOR.name,{initialWaitMs:2e3,periodMs:1e3}).load().then((async({start:e,stop:o})=>{await e(),await a.start(),setTimeout((async()=>{await a.stop(),await o()}),t.stopAfter)})),window.addEventListener(e.modules().EVENT_BARRIER.eventName,(e=>{console.log("EVENT_BARRIER result",e.detail)})),window.addEventListener(e.modules().DATA_AGGREGATOR.eventName,(e=>{console.log("DATA_AGGREGATOR result",e.detail)})),MphTools.CameraPrivacyPopup.setText({title:"Allow us to use your camera",description:"This experience is designed to be viewed with your camera on. The next screen will ask your consent to access data from your camera.",url:"https://YOUR_DOMAIN/<YOUR_PRIVACY_POLICY>"})}));