diff options
author | Devaev Maxim <[email protected]> | 2021-05-16 23:47:16 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2021-05-16 23:47:16 +0300 |
commit | 5eb0d71cfd2344d30db24d472a6153a64d81279c (patch) | |
tree | ef0c679be6a7e74b58303d131bd054a82717ed9d /web/share/js/kvm/stream.js | |
parent | 03946dd476549639429149cf89c461a9374de710 (diff) |
dynamic import
Diffstat (limited to 'web/share/js/kvm/stream.js')
-rw-r--r-- | web/share/js/kvm/stream.js | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/web/share/js/kvm/stream.js b/web/share/js/kvm/stream.js index 1008cb92..7371c2e5 100644 --- a/web/share/js/kvm/stream.js +++ b/web/share/js/kvm/stream.js @@ -25,10 +25,10 @@ import {tools, $} from "../tools.js"; import {wm} from "../wm.js"; -/*import {Janus} from "./janus.js"; +var _Janus = null; -function _JanusStreamer(set_active_callback, set_inactive_callback, set_info_callback) { +/*function _JanusStreamer(set_active_callback, set_inactive_callback, set_info_callback) { var self = this; var __janus = null; @@ -210,9 +210,27 @@ export function Streamer() { }; self.setJanusEnabled = function(enabled) { - __janus_enabled = (!!window.RTCPeerConnection && enabled); - tools.info("Stream: Janus WebRTC Gateway state:", __janus_enabled); - self.setState(__state); + let supported = !!window.RTCPeerConnection; + let set_enabled = function() { + __janus_enabled = (enabled && supported && _Janus !== null); + tools.info(`Stream: Janus WebRTC state: enabled=${enabled}, supported=${supported}, imported=${!!_Janus}`); + self.setState(__state); + }; + if (enabled && supported) { + if (_Janus === null) { + import("./janus.js").then((module) => { + _Janus = module.Janus; + set_enabled(); + }).catch((err) => { + tools.error("Can't import Janus module:", err); + set_enabled(); + }); + } else { + set_enabled(); + } + } else { + set_enabled(); + } }; self.setState = function(state) { |