Emberjs and Socket.io

I am trying to add some real-time functionality to the ember app using socket.io. But since the socket instance created by io.connect() resides outside of my App namespace, and since App.controllerName.doSomething() is no longer allowed, how can I access a controller and update it’s content? (Note: not using ember-data).

1 Like

You can create your socket instance inside another controller:

App.SocketController = Ember.Controller.extend({
  needs: ['other'],
  init: function() {
    this._super();
    this.socket = io.connect(); //I don't remember the correct syntax
    this.socket.on('data', this.onData.bind(this);
  },
  onData: function() {
    this.get('controllers.other').doSomething();
  }
});

App.OtherController = Ember.Controller.extend({
  doSomething: function() {
  }
});
4 Likes