UNPKG

@tycoonsystems/tycoon-modules

Version:
1 lines 2.89 kB
import{fetchPost}from"@tycoonsystems/tycoon-modules/utility/fetch/fetch.js";import{checkSignedIn,logout}from"@tycoonsystems/tycoon-modules/utility/onboarding/SignIn.js";const beginStream=async(t,e,r)=>{var s=checkSignedIn();if(console.log(s),s&&s.identifier&&s.hash){e={cus_id:r.stripeSecret.user,dontForce:r.dontForce,streamSettings:r.streamSettings,domainKey:e,hash:s.hash,identifier:s.identifier,streamingFor:r?.streamingFor,record:r.record,admin:r.admin,askEmbed:r?.askEmbed,customer:r?.customer,foruser:r?.foruser},s=await fetchPost(t+"/m/beginstream",null,null,e);if(s&&s.hasOwnProperty("status")){if("disauthenticated"==s.status)return logout(),"disauthenticated";if("failed"==s.status)return!1;if("success"==s.status)return s}}return!1},endStream=async(t,e,r)=>{var s=checkSignedIn();if(s&&s.identifier&&s.hash){e={stream:r.stream,domainKey:e,hash:s.hash,identifier:s.identifier,customer:r.customer,foruser:r.foruser},s=await fetchPost(t+"/m/endstream",null,null,e);if(s&&s.hasOwnProperty("status")){if("disauthenticated"==s.status)return logout(),"disauthenticated";if("failed"==s.status)return!1;if("success"==s.status)return s}}return!1},doFetchAuthForStream=async(t,e,r,s)=>{s=s(),r={stream:r,domainKey:e,hash:s?.hash,identifier:s?.identifier},e=await fetchPost(t+"/m/getauthforstream",null,null,r);if(e&&e.hasOwnProperty("status")){if("disauthenticated"==e.status)return logout(),"disauthenticated";if("failed"==e.status)return!1;if("success"==e.status)return e}return!1},updateStreamConfigRequest=async(t,e,r)=>{var s=checkSignedIn();if(s&&s.identifier&&s.hash){e={stream:r.stream,streamData:r.streamData,streamSettings:r.streamSettings,domainKey:e,hash:s.hash,identifier:s.identifier,customer:r?.customer,foruser:r?.foruser},s=await fetchPost(t+"/m/updatestreamconfig",null,null,e);if(s&&s.hasOwnProperty("status")){if("disauthenticated"==s.status)return logout(),"disauthenticated";if("failed"==s.status)return!1;if("success"==s.status)return s}}return!1},requestStreamingPermissions=async(t,e)=>{var r=checkSignedIn();if(r&&r.identifier&&r.hash){e={domainKey:e,hash:r.hash,identifier:r.identifier},r=await fetchPost(t+"/m/requeststreamingpermissions",null,null,e);if(r&&r.hasOwnProperty("status")){if("disauthenticated"==r.status)return logout(),"disauthenticated";if("failed"==r.status)return!1;if("success"==r.status)return r}}return!1},checkAuthorization=(t,e,r,s,i,a)=>{return i?(s(),!0):!(i=t?.meta?.streamSettings??t?.meta)||!i?.private||(r?._loggedIn?.identifier&&t?.author&&t.author==r._loggedIn.identifier||!!e?.allowed)&&(s&&s(),!0)},checkPlayerIsPlaying=t=>{try{return 0<t?.current?.currentTime()&&!1===t?.current?.paused()&&!1===t?.current?.ended()&&2<t?.current?.readyState()?!0:!1}catch(t){return console.log(t),!1}};export{beginStream,endStream,doFetchAuthForStream,updateStreamConfigRequest,requestStreamingPermissions,checkAuthorization,checkPlayerIsPlaying};