![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
ember-pusher
Advanced tools
A library for declaratively managing connections to Pusher channels and events in your Ember application.
You are able to connect to different channels and events declaratively as the user traverses through your application. The interface to event handlers are natural methods on your controllers. In fact: The full event bubbling framework is available to the pusher initiated events.
Yes
I guess? Ship it! :shipit:
Good question!
First things first: Stick your pusher connection options on your Application
object. Anything you pass into the connection
hash will be passed in as
options to the pusher connection. This is a good place for auth params, and
things like that. You can get a list of all the options from
Pusher's API.
App = Ember.Application.create({
PUSHER_OPTS: { key: 'foo', connection: {} }
});
Next, for any controllers that you want to catch pusher events on:
EmberPusher.Bindings
.PUSHER_SUBSCRIPTIONS
where the keys are channel names and the
values are arrays of events for the channel. If you have dynamic channel
names or events, you can totally just construct your PUSHER_SUBSCRIPTIONS
hash in init()
of your controller (note: be sure to call this._super()
afterwards). Private channels are fine.There are two ways to setup logging. The first is to log all events which
can be accomplished by setting logAllEvents
in your PUSHER_OPTS
hash:
App = Ember.Application.create({
PUSHER_OPTS: { key: 'foo', connection: { ... }, logAllEvents: true }
});
The second method of logging, is to set logPusherEvents
on the controllers
that you're binding. For example:
var YourController = Em.Controller.extend(EmberPusher.Bindings, {
logPusherEvents: true,
PUSHER_SUBSCRIPTIONS: {
myChannel: ['my-event']
}
});
Note: Things work as expected if you set either of these options at runtime
var YourController = Em.Controller.extend(EmberPusher.Bindings, {
PUSHER_SUBSCRIPTIONS: {
craycray: ['event-one', 'event-two'],
anotherone: ['event-three']
},
actions: {
eventOne: function(){ console.log("eventOne is working!"); },
eventTwo: function(){ console.log("eventTwo is working!"); },
eventThree: function(){ console.log("eventThree is working!"); }
}
});
Note: The event names have camelize()
called on them, so that you can
keep your controller's methods looking consistent. Event handlers are tracked
and torn down when a controller is destroyed.
That's about it! When events come in, they should be triggered on the listening controllers. It should be noted that event bubbling will all work as expected, so you can actually implement your handlers wherever suits your needs best.
Have fun! Certainly let me know if you see any bugs.
In order to send events from the client you will need to enable client events
for your Pusher application. In your Ember controllers you must mixin
EmberPusher.ClientEvents
and call the pusherTrigger
method.
var YourController = Em.Controller.extend(EmberPusher.ClientEvents, {
actions: {
sendSomeEvent: function() {
// Pusher requires that the event be prefixed with 'client-'
var eventName = 'client-some-event';
this.pusherTrigger(this.get('channelName'), eventName, this.get('data'));
}
}
});
My events aren't firing! :'(
Are you sure you've got the right event name on your controller? Do
an Em.String.camelize('foo-bar')
on your event name. That's what you should
have implemented on your controller. Did you make sure to extend
EmberPusher.Bindings
on the controller(s) you want to catch events on?
Can I connect to a private channel!?
Yes.
PUSHER_SUBSCRIPTIONS: { 'private-user.3' : ['cuckoo'] }
What versions of Ember are supported!?
~>1.0.0
Can I bind to channel connection events!?
Indeed.
App.MyController = Ember.Controller.extend(EmberPusher.Bindings, {
PUSHER_SUBSCRIPTIONS: {
my-channel: ['pusher:subscription_succeeded']
},
actions: {
'pusher:subscriptionSucceeded': function() {
console.log("Connected!");
}
}
});
What can I bind to for the connection status and socket id!?
You could bind to isConnected
and socketId
which are both on the pusherController.
App.MyController = Ember.Controller.extend(EmberPusher.Bindings, {
socketIdChanged: function() {
console.log("Socket ID changed", this.pusher.get('socketId'));
}.observes('pusher.socketId').on('init'),
pusherConnectionStatusChanged: function() {
console.log("Connection status changed", this.pusher.get('isConnected'));
}.observes('pusher.isConnected').on('init')
});
grunt test
- Runs Mocha tests through PhantomJS
grunt server
- Run tests through a browser. Visit http://localhost:8000/test
.
grunt build
- build 'er
@wycats - Architectural advice.
FAQs
An implementation of a declarative interface to Pusher for Ember
The npm package ember-pusher receives a total of 1,249 weekly downloads. As such, ember-pusher popularity was classified as popular.
We found that ember-pusher demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.