如何在React Native中记录window.API.cmi中的scorm交互
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论