Ember addon for easy integration with Pusher
- mechanism of integration is based on Ember.Evented
- addon is a mixin which is easy to include
ember install ember-pusher-guru
Set pusherKey
value in environment:
// my-project/config/environment.js
var ENV = {
pusherKey: '49482as87s88s6d9sw74',
...
And extend security policy rule:
contentSecurityPolicy: {
'connect-src': "'self' ws://ws.pusherapp.com"
}
Then you need to add this line:
<script type="text/javascript">window.ALLOW_PUSHER_OVERRIDE = true;</script>
to your tests/index.html
right after the body
tag. This will allow pusher-test-stub
to work and run your tests.
You need to create service which must be extended from pusher-base
service:
# my-project/services/pusher.js
import Pusher from 'ember-pusher-guru/services/pusher-base';
export default Pusher.extend({
authEndpoint: 'http://backend.com/auth' // optional (for authentication)
channelsData: [
{ channelName1: ['eventName1'] },
{ channelName2: ['eventName2', 'eventName3'] }
...
]
});
You can create it as you want, but pusher
is default.
And then use pusher-initializer mixin wherever you want and define connection events to method via pusherActions
import PusherInitializer from 'ember-pusher-guru/mixins/pusher-initializer';
export default Ember.Route.extend(PusherInitializer, {
// if you named your pusher service otherwise you need to inject it under the name `pusher`
// pusher: Ember.inject.service('my-pusher-service-name'),
pusherActions: [
{ eventName: 'methodName' },
{ event2name: 'method2name' }
],
methodName() {
// code
}
});