lundi 18 avril 2016

Subscribe global javascript events in Ember JS (controller)

Im implementing Ziggeo (http://ziggeo.com/) in our Ember JS application, and Ziggeo has a Javascript SDK where you subscribe to events like this

ZiggeoApi.Events.on("submitted", function (data) {
   alert("Submitted a new video with token '" + data.video.token + "'!");
});

I manage to receive the event if I add it globally in JS like this: <script> ZiggeoApi.token = 'myToken'; ZiggeoApi.Events.on("submitted", function (data) { console.log('video updated: ' + data); }); </script>

But how can I listen to global events in Ember (controller)?

I tried this, and it somehow worked, except for that "this" context will not be the controller, so I cant call other ember components, like the store, or store.createRecord, etc.

export default Ember.Controller.extend(Ember.Evented, {
session: Ember.inject.service('session'),

  ziggeoRecordDone: ZiggeoApi.Events.on("submitted", (function(data) {
      console.log("Ziggeo Record Done YEAH; HURRA");
      ZiggeoApi.videoOnLoad = data.video.token;
     ...




Aucun commentaire:

Enregistrer un commentaire