In my Ember app I'm using ember-inject-script which I installed:
npm install --save-dev ember-inject-script
The controller.js file for my page looks like this:
import Ember from 'ember';
import injectScript from 'ember-inject-script';
export default Ember.Controller.extend({
init: function() {
this._super();
var url = "https://meet.jit.si/external_api.js";
injectScript(url);
var domain = "meet.jit.si";
var room = "JitsiMeetAPIExample";
var width = 700;
var height = 700;
var htmlElement = document.querySelector('#meet');
var api = new JitsiMeetExternalAPI(domain, room, width, height,
htmlElement);
}
});
The Template is this:
<h2>Jitsi Meet</h2>
<div id="meet"></div>
{{outlet}}
Yet I get a console error:
Error while processing route: projects.index JitsiMeetExternalAPI is not defined ReferenceError: JitsiMeetExternalAPI is not defined
Embedding the Jitsi Meet API into your site or app enables you to host and provide secure video meetings with your colleagues, teams, and stakeholders. The Meet API provides a full complement of comprehensive meeting features.
GitHub - jitsi/lib-jitsi-meet: A low-level JS video API that allows adding a completely custom video experience to web apps.
Well, here's what we believe is the easiest way in the world to do so: <script src='https://meet.jit.si/external_api.js'></script> ... const domain = 'meet.jit.si'; const options = { roomName: 'PickAnAppropriateMeetingNameHere', width: 700, height: 700, parentNode: document.
injectScript
in asynchronous so you can't use JitsiMeetExternalAPI
very next statement. You need to use then
.
Another issue is, you are accessing the DOM element in controller init method, which will not be available. generally controller is not DOM aware. for this I will encourage you to write Component and use didInsertElement
hook
One more alternative approach to load js at the required time, is in routes beforeModel hook, you can just use Ember.$.getJSON(url).
beforeModel(){
return Ember.$.getJSON(url);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With