lms/public/build/assets/zoom-live-class-CPblQlTd.js
2025-12-15 12:26:23 +01:00

2 lines
4.5 KiB
JavaScript

import{u as L,r as l,j as n}from"./vendor-BKmmeuxg.js";import{u as k}from"./use-auth-NG-DQJrC.js";const C=({live_class:r,watchHistory:m,zoom_sdk_client_id:p})=>{const{props:_}=L(),{auth:u,translate:x}=_,{frontend:o}=x,{isAdmin:b}=k(),[y,i]=l.useState(!0),[g,s]=l.useState(null),[j,w]=l.useState(!1),f=l.useRef(!1),M=b?"/dashboard/courses":`/play-course/${r.course.slug}/${m.id}/${m.current_watching_id}`,a=(()=>{if(!r.additional_info)return null;try{return typeof r.additional_info=="object"?r.additional_info:typeof r.additional_info=="string"?JSON.parse(r.additional_info):null}catch{return null}})(),Z=async()=>{if(window.ZoomMtg)return w(!0),Promise.resolve();const t=["https://source.zoom.us/4.0.0/lib/vendor/react.min.js","https://source.zoom.us/4.0.0/lib/vendor/react-dom.min.js","https://source.zoom.us/4.0.0/lib/vendor/redux.min.js","https://source.zoom.us/4.0.0/lib/vendor/redux-thunk.min.js","https://source.zoom.us/4.0.0/zoom-meeting-4.0.0.min.js"];for(const e of t)await new Promise((d,h)=>{const c=document.createElement("script");c.src=e,c.async=!1,c.onload=()=>{d()},c.onerror=()=>{h(new Error(`Failed to load script: ${e}`))},document.head.appendChild(c),setTimeout(()=>h(new Error(`Script load timeout: ${e}`)),1e4)});w(!0)},v=async()=>{try{i(!0);const t=await fetch(route("live-class.signature",r.id),{method:"GET",headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"}});if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);const e=await t.json();if(e.error)throw new Error(e.error);return e}catch(t){return s(t instanceof Error?t.message:o.failed_to_get_meeting_configuration),null}},z=async t=>{try{if(!window.ZoomMtg)throw new Error(o.zoom_sdk_not_loaded);window.ZoomMtg.checkSystemRequirements();const e=document.getElementById("app")||document.body;e.innerHTML="",document.body.style.margin="0",document.body.style.padding="0",document.body.style.overflow="hidden",document.body.style.height="100vh",document.body.style.width="100vw",window.ZoomMtg.preLoadWasm(),window.ZoomMtg.prepareWebSDK(),window.ZoomMtg.i18n.load("en-US"),window.ZoomMtg.i18n.onLoad(()=>{window.ZoomMtg.init({leaveUrl:window.location.origin+M,disableCORP:!window.crossOriginIsolated,success:()=>{E(t)},error:d=>{s(o.failed_to_initialize_meeting+": "+(d.message||d)),i(!1)}})}),N()}catch(e){s(e instanceof Error?e.message:o.failed_to_initialize_meeting),i(!1)}},E=t=>{window.ZoomMtg.join({meetingNumber:t.meetingNumber,userName:u.user.name,signature:t.signature,userEmail:u.user.email||"",passWord:t.password,success:e=>{i(!1),window.ZoomMtg.getCurrentUser({success:d=>{}}),window.ZoomMtg.getAttendeeslist({})},error:e=>{s(o.failed_to_join_meeting+": "+(e.message||e)),i(!1)}})},N=()=>{window.ZoomMtg.inMeetingServiceListener("onUserJoin",t=>{}),window.ZoomMtg.inMeetingServiceListener("onUserLeave",t=>{}),window.ZoomMtg.inMeetingServiceListener("onUserIsInWaitingRoom",t=>{}),window.ZoomMtg.inMeetingServiceListener("onMeetingStatus",t=>{})},S=()=>{if(window.ZoomMtg)try{window.ZoomMtg.leave()}catch{}};return l.useEffect(()=>f.current?void 0:(f.current=!0,(async()=>{if(!p){s(o.zoom_sdk_not_configured),i(!1);return}if(!a){s(o.meeting_information_not_found),i(!1);return}try{await Z();const e=await v();if(!e)return;await z(e)}catch(e){s(e instanceof Error?e.message:o.failed_to_initialize_meeting),i(!1)}})(),S),[]),y?n.jsx("div",{className:"flex min-h-screen items-center justify-center bg-gray-900",children:n.jsxs("div",{className:"text-center",children:[n.jsx("div",{className:"mx-auto mb-4 h-12 w-12 animate-spin rounded-full border-b-2 border-white"}),n.jsx("h1",{className:"text-xl font-semibold text-white",children:r.class_topic}),n.jsx("p",{className:"text-gray-300",children:j?o.joining_meeting:o.loading_zoom_sdk})]})}):g?n.jsx("div",{className:"flex min-h-screen items-center justify-center bg-gray-100",children:n.jsxs("div",{className:"max-w-md rounded-lg bg-white p-8 text-center shadow-lg",children:[n.jsx("h1",{className:"mb-4 text-2xl font-bold text-red-600",children:o.unable_to_join_meeting}),n.jsx("p",{className:"text-muted-foreground mb-4",children:g}),(a==null?void 0:a.join_url)&&n.jsxs("div",{className:"mt-4",children:[n.jsx("p",{className:"mb-2 text-sm text-gray-500",children:o.you_can_join_directly}),n.jsx("a",{href:a.join_url,target:"_blank",rel:"noopener noreferrer",className:"inline-block rounded bg-blue-600 px-4 py-2 text-white hover:bg-blue-700",children:o.open_in_zoom_app})]}),n.jsx("button",{onClick:()=>window.location.reload(),className:"mt-4 rounded bg-gray-600 px-4 py-2 text-white hover:bg-gray-700",children:o.try_again})]})}):null};export{C as default};