Skip to content

Commit

Permalink
emit token as state
Browse files Browse the repository at this point in the history
  • Loading branch information
Morten Henriksen committed Aug 3, 2015
1 parent 2e9b2a1 commit eb61318
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions lib/client/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ Push.Configure = function(options) {
options.iframe.addEventListener('pushToken', function(evt) {
if (evt.androidToken) {
// Format the android token
Push.emit('token', { gcm: evt.androidToken });
Push.emitState('token', { gcm: evt.androidToken });
} else if (evt.iosToken) {
// Format the ios token
Push.emit('token', { apn: evt.iosToken });
Push.emitState('token', { apn: evt.iosToken });
}
});

Expand All @@ -196,7 +196,7 @@ Push.Configure = function(options) {
if (options.gcm.projectNumber)
chrome.gcm.register(options.gcm.projectNumber, function(token) {
if (token) {
self.emit('token', { gcm: token });
self.emitState('token', { gcm: token });
} else {
// Error
self.emit('error', { type: 'gcm.browser', error: 'Access denied' });
Expand Down Expand Up @@ -233,7 +233,7 @@ Push.Configure = function(options) {
// alert('granted');
// The web service URL is a valid push provider, and the user said yes.
// permissionData.deviceToken is now available to use.
self.emit('token', { apn: permissionData.deviceToken });
self.emitState('token', { apn: permissionData.deviceToken });
}
};

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

self.emit('token', {
self.emitState('token', {
SimplePush: {
channel: channel,
endPoint: pushEndpoint
Expand Down
2 changes: 1 addition & 1 deletion lib/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ var reportTokenToServer = function(token, appName) {
initPushUpdates = function(appName) {

// Start listening for tokens
Push.addListener('token', function(token) {
Push.on('token', function(token) {
// The app should be ready, lets call in
reportTokenToServer(token, appName || 'main');
});
Expand Down
4 changes: 2 additions & 2 deletions lib/client/cordova.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ onNotificationGCM = function(e) {
switch( e.event ) {
case 'registered':
if ( e.regid.length > 0 ) {
Push.emit('token', { gcm: ''+e.regid } );
Push.emitState('token', { gcm: ''+e.regid } );
}
break;

Expand Down Expand Up @@ -298,7 +298,7 @@ Push.Configure = function(options) {

pushNotification.register(function(token) {
// Got apn / ios token
self.emit('token', { apn: token });
self.emitState('token', { apn: token });
}, function(error) {
// Emit error
self.emit('error', { type: 'apn.cordova', error: error });
Expand Down
6 changes: 3 additions & 3 deletions lib/server/push.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ Push.Configure = function(options) {
// console.log('Replace token: ' + currentToken + ' -- ' + newToken);
// If the server gets a token event its passing in the current token and
// the new value - if new value is undefined this empty the token
self.emit('token', currentToken, newToken);
self.emitState('token', currentToken, newToken);
};

// Rig the removeToken callback
_removeToken = function(token) {
// console.log('Remove token: ' + token);
// Invalidate the token
self.emit('token', token, null);
self.emitState('token', token, null);
};


Expand Down Expand Up @@ -480,7 +480,7 @@ Push.Configure = function(options) {
sending: true
}
});

// Make sure we only handle notifications reserved by this
// instance
if (reserved) {
Expand Down

0 comments on commit eb61318

Please sign in to comment.