如何在React Native中记录window.API.cmi中的scorm交互

发布于 2025-01-12 15:20:44 字数 1026 浏览 1 评论 0原文

我有 SCORM 文件并使用包 react-native-webview 打开它。我需要跟踪进度,但是当我注入 javascript 来设置变量时,catch 部分执行并且警报显示 TypeError: undefined is not an object (evaluating 'window.API.cmi)

const injectTrack = () => {
const setTrackInjection = `
    try {
        window.API.cmi.core.student_id = "${user?.id ? user?.id : ''}";  
        window.API.cmi.core.student_name = "${user?.firstname ? user?.firstname : ''}";
        window.API.cmi.suspend_data = '${suspend_data}';
        window.API.cmi.core.total_time = '${total_time}';
        window.API.cmi.core.session_time = '${session_time}';
        window.API.cmi.core.score.raw = '${scoreRaw}';
        window.API.cmi.core.score.max = '${scoreMax}';
        window.API.cmi.core.score.min = '${scoreMin}';
        window.API.cmi.core.lesson_status = '${lesson_status}';
        window.API.cmi.core.exit = '${exit}';
        
    } catch(error){
        alert(error);
    }
    true;`;

webviewRef.current.injectJavaScript(setTrackInjection);

};

I have the SCORM file and opened it using the package react-native-webview. I need to track the progress but when I injected the javascript to set the variables the catch part executed and the alert shows me TypeError: undefined is not an object (evaluating 'window.API.cmi)

const injectTrack = () => {
const setTrackInjection = `
    try {
        window.API.cmi.core.student_id = "${user?.id ? user?.id : ''}";  
        window.API.cmi.core.student_name = "${user?.firstname ? user?.firstname : ''}";
        window.API.cmi.suspend_data = '${suspend_data}';
        window.API.cmi.core.total_time = '${total_time}';
        window.API.cmi.core.session_time = '${session_time}';
        window.API.cmi.core.score.raw = '${scoreRaw}';
        window.API.cmi.core.score.max = '${scoreMax}';
        window.API.cmi.core.score.min = '${scoreMin}';
        window.API.cmi.core.lesson_status = '${lesson_status}';
        window.API.cmi.core.exit = '${exit}';
        
    } catch(error){
        alert(error);
    }
    true;`;

webviewRef.current.injectJavaScript(setTrackInjection);

};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文