Skip to content

Commit eb61318

Browse files
author
Morten Henriksen
committed
emit token as state
1 parent 2e9b2a1 commit eb61318

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

lib/client/browser.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ Push.Configure = function(options) {
172172
options.iframe.addEventListener('pushToken', function(evt) {
173173
if (evt.androidToken) {
174174
// Format the android token
175-
Push.emit('token', { gcm: evt.androidToken });
175+
Push.emitState('token', { gcm: evt.androidToken });
176176
} else if (evt.iosToken) {
177177
// Format the ios token
178-
Push.emit('token', { apn: evt.iosToken });
178+
Push.emitState('token', { apn: evt.iosToken });
179179
}
180180
});
181181

@@ -196,7 +196,7 @@ Push.Configure = function(options) {
196196
if (options.gcm.projectNumber)
197197
chrome.gcm.register(options.gcm.projectNumber, function(token) {
198198
if (token) {
199-
self.emit('token', { gcm: token });
199+
self.emitState('token', { gcm: token });
200200
} else {
201201
// Error
202202
self.emit('error', { type: 'gcm.browser', error: 'Access denied' });
@@ -233,7 +233,7 @@ Push.Configure = function(options) {
233233
// alert('granted');
234234
// The web service URL is a valid push provider, and the user said yes.
235235
// permissionData.deviceToken is now available to use.
236-
self.emit('token', { apn: permissionData.deviceToken });
236+
self.emitState('token', { apn: permissionData.deviceToken });
237237
}
238238
};
239239

@@ -265,7 +265,7 @@ Push.Configure = function(options) {
265265
// Store the endpoint
266266
pushEndpoint = e.target.result;
267267

268-
self.emit('token', {
268+
self.emitState('token', {
269269
SimplePush: {
270270
channel: channel,
271271
endPoint: pushEndpoint

lib/client/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ var reportTokenToServer = function(token, appName) {
109109
initPushUpdates = function(appName) {
110110

111111
// Start listening for tokens
112-
Push.addListener('token', function(token) {
112+
Push.on('token', function(token) {
113113
// The app should be ready, lets call in
114114
reportTokenToServer(token, appName || 'main');
115115
});

lib/client/cordova.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ onNotificationGCM = function(e) {
109109
switch( e.event ) {
110110
case 'registered':
111111
if ( e.regid.length > 0 ) {
112-
Push.emit('token', { gcm: ''+e.regid } );
112+
Push.emitState('token', { gcm: ''+e.regid } );
113113
}
114114
break;
115115

@@ -298,7 +298,7 @@ Push.Configure = function(options) {
298298

299299
pushNotification.register(function(token) {
300300
// Got apn / ios token
301-
self.emit('token', { apn: token });
301+
self.emitState('token', { apn: token });
302302
}, function(error) {
303303
// Emit error
304304
self.emit('error', { type: 'apn.cordova', error: error });

lib/server/push.api.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ Push.Configure = function(options) {
4242
// console.log('Replace token: ' + currentToken + ' -- ' + newToken);
4343
// If the server gets a token event its passing in the current token and
4444
// the new value - if new value is undefined this empty the token
45-
self.emit('token', currentToken, newToken);
45+
self.emitState('token', currentToken, newToken);
4646
};
4747

4848
// Rig the removeToken callback
4949
_removeToken = function(token) {
5050
// console.log('Remove token: ' + token);
5151
// Invalidate the token
52-
self.emit('token', token, null);
52+
self.emitState('token', token, null);
5353
};
5454

5555

@@ -480,7 +480,7 @@ Push.Configure = function(options) {
480480
sending: true
481481
}
482482
});
483-
483+
484484
// Make sure we only handle notifications reserved by this
485485
// instance
486486
if (reserved) {

0 commit comments

Comments
 (0)