Skip to content

Commit

Permalink
Register as "pusher:main"
Browse files Browse the repository at this point in the history
  • Loading branch information
mmun committed May 1, 2014
1 parent 5c3cd86 commit 14c8e0d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
12 changes: 4 additions & 8 deletions lib/ember-pusher/bindings.js
Expand Up @@ -3,27 +3,23 @@ var global = (typeof window !== 'undefined') ? window : {},

var Bindings = Ember.Mixin.create({

needs: 'pusher',

init: function() {
var pusherController, target;
var target;
this._super();
if(!this.PUSHER_SUBSCRIPTIONS) { return; }
pusherController = this.get('controllers.pusher');
target = this;
Object.keys(target.PUSHER_SUBSCRIPTIONS).forEach(function (channelName) {
var events = target.PUSHER_SUBSCRIPTIONS[channelName];
pusherController.wire(target, channelName, events);
target.pusher.wire(target, channelName, events);
});
},

willDestroy: function() {
var pusherController, target;
var target;
if(!this.PUSHER_SUBSCRIPTIONS) { return; }
pusherController = this.get('controllers.pusher');
target = this;
Object.keys(target.PUSHER_SUBSCRIPTIONS).forEach(function (channelName) {
pusherController.unwire(target, channelName);
target.pusher.unwire(target, channelName);
});
this._super();
},
Expand Down
4 changes: 1 addition & 3 deletions lib/ember-pusher/client_events.js
Expand Up @@ -3,12 +3,10 @@ var global = (typeof window !== 'undefined') ? window : {},

var ClientEvents = Ember.Mixin.create({

needs: 'pusher',

// Fire an event programmatically. All Events must unfortunately use
// the client-<eventname> format for client events (a pusher restriction).
pusherTrigger: function(channelName, eventName, data) {
var channel = this.get('controllers.pusher').channelFor(channelName);
var channel = this.pusher.channelFor(channelName);
channel.trigger(eventName, data);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/ember-pusher/controller.js
Expand Up @@ -105,7 +105,7 @@ var Controller = Ember.Controller.extend({
bindings[channelName].channel = pusher.subscribe(channelName);

// Spit out a bunch of logging if asked
if(this.namespace.PUSHER_OPTS.logAllEvents) {
if(this.namespace && this.namespace.PUSHER_OPTS.logAllEvents) {
bindings[channelName].channel.bind_all(function(eventName, data) {
console.log(
"Pusher event received on " + channelName + ":",
Expand Down Expand Up @@ -140,6 +140,7 @@ var Controller = Ember.Controller.extend({
},

channelFor: function(channelName) {
// debugger;
return this.get('bindings')[channelName].channel;
},

Expand Down
5 changes: 3 additions & 2 deletions lib/ember-pusher/initializer.js
Expand Up @@ -15,17 +15,18 @@ function initialize() {
initialize: function(container, application) {
var pusherController, options, pusher, dict;

dict = 'controller:pusher';
dict = 'pusher:main';
container.register(dict, Controller);

pusherController = container.lookup('controller:pusher');
pusherController = container.lookup(dict);
options = application.PUSHER_OPTS;

Ember.assert("You need to provide PUSHER_OPTS on your application", options);
Ember.assert("You need to include the pusher libraries", Pusher);
pusher = new Pusher(options.key, options.connection);
pusherController.didCreatePusher(pusher);

console.log('totes injected');
application.inject('controller', 'pusher', dict);
application.inject('route', 'pusher', dict);
}
Expand Down
2 changes: 1 addition & 1 deletion test/lib/controller_test.js
Expand Up @@ -23,7 +23,7 @@ App = Ember.Application.create({
describe("Controller", function() {

before(function(){
pusherController = App.__container__.lookup('controller:pusher');
pusherController = App.__container__.lookup('pusher:main');
pusherController.get('connection').connection.socket_id = '1234';
channelName = 'craycraychannel';
bindings = pusherController.get('bindings');
Expand Down

0 comments on commit 14c8e0d

Please sign in to comment.