diff --git a/app.js b/app.js index e6717ab..24826eb 100644 --- a/app.js +++ b/app.js @@ -32,44 +32,6 @@ var heating_v1 = require('./routes/heating_v1'); var projector_v1 = require('./routes/projector_v1'); var isProduction = false; -var iosTokens = []; -var apnTimer = 0; - -var apn = require('apn'); - -var apnService = new apn.connection({ key: 'conf/key.pem', - cert: 'conf/cert.pem', production: false }); - -apnService.on('connected', function() { - logger.debug('APN Connected'); - }); - -apnService.on('transmitted', function(notification, device) { - logger.debug('APN Notification transmitted to:' + device.token.toString('hex')); - }); - -apnService.on('transmissionError', function(errCode, notification, device) { - logger.error('APNNotification caused error: ' + errCode + ' for device ', device, notification); - if (errCode === 8) { - logger.error('A error code of 8 indicates that the device token is invalid. This could be for a number of reasons - are you using the correct environment? i.e. Production vs. Sandbox'); - } - }); - -apnService.on('timeout', function() { - logger.debug('Connection Timeout'); - }); - -apnService.on('disconnected', function() { - logger.debug('Disconnected from APNS'); - }); - -apnService.on('socketError', logger.error); - - - - - - mqttConnect.setEmitter(busEmitter); mqttConnect.doConnection(); @@ -260,7 +222,9 @@ app.post('/api/v1/register/ios', function(req, res) { registrationId = body['registrationId']; logger.debug(registrationId); - if (iosTokens.indexOf(registrationId) === -1) { + cal.registeriOSToken(id); + + /* if (iosTokens.indexOf(registrationId) === -1) { iosTokens.push(registrationId); logger.info('IOS Device registered.'); @@ -281,7 +245,7 @@ app.post('/api/v1/register/ios', function(req, res) { }, 30000); } - +*/ } }); diff --git a/app/js/appv2.js b/app/js/appv2.js index c1293ea..f02867c 100644 --- a/app/js/appv2.js +++ b/app/js/appv2.js @@ -18,7 +18,7 @@ var SOController = (function() { var lastWeatherRequest = 0; var soWebSocket; var iosConfig = { - "badge": true, "sound": true, "alert": true, + badge: true, sound: true, alert: true, }; var lightsList = { @@ -42,7 +42,7 @@ var SOController = (function() { var iOS = ['iPad', 'iPhone', 'iPod'].indexOf(navigator.platform) >= 0; if (iOS) { $('#iosTaskbar').show(); - // path = 'http://localhost:3000/'; + // path = 'http://localhost:3000/'; } var module = {lights: lightsList}; @@ -301,32 +301,31 @@ var SOController = (function() { }; var cordovaNotify = function(d) { + console.log('+++ CORDOVA NOTIFY +++'); try { navigator.notification.beep(1); - } catch(e) - { + } catch (e) { console.log(e); } try { navigator.notification.confirm( - d.msg, // message - notifyConfirm, // callback to invoke with index of button pressed - 'Smartoffice Console', // title - ['Extend','Ignore'] // buttonLabels + d.msg, // Message + notifyConfirm, // Callback to invoke with index of button pressed + 'Smartoffice Console', // Title + ['Extend','Ignore'] // ButtonLabels ); - } catch(e) - { + } catch (e) { console.log(e); } }; - var setupPush = function() { - console.log('Setting up push notifications..'); + var setupPushNotifications = function() { + console.log('Setting up iOS push notifications..'); - var push = PushNotification.init({"android":{},"ios":iosConfig,"windows":{}}); + var push = PushNotification.init({android: {},ios: iosConfig,windows: {}}); push.on('registration', function(d) { console.log('*PUSH* Registration: ', JSON.stringify(d)); @@ -365,7 +364,11 @@ var SOController = (function() { module.notify = function(d) { if (window.cordova && !(window.cordova instanceof HTMLElement)) { - cordovaNotify(d); + if (device.platform === 'android' || device.platform === 'Android') { + cordovaNotify(d); + } else if (device.platform === 'iOS' || device.platform === 'ios') { + setupPushNotifications(); + } } else { browserNotify(d); } diff --git a/lib/office/officeController.js b/lib/office/officeController.js index aaa6d63..b09fd88 100644 --- a/lib/office/officeController.js +++ b/lib/office/officeController.js @@ -8,13 +8,43 @@ var events = require('events'); var eventBus ; var util = require('util'); -/*var pushNotifications = require('node-pushnotifications'); +var apn = require('apn'); + +var apnService = new apn.connection({ key: 'conf/key.pem', + cert: 'conf/cert.pem', production: false }); + +apnService.on('connected', function() { + logger.debug('APN Connected'); + }); + +apnService.on('transmitted', function(notification, device) { + logger.debug('APN Notification transmitted to:' + device.token.toString('hex')); + }); + +apnService.on('transmissionError', function(errCode, notification, device) { + logger.error('APNNotification caused error: ' + errCode + ' for device ', device, notification); + if (errCode === 8) { + logger.error('A error code of 8 indicates that the device token is invalid. This could be for a number of reasons - are you using the correct environment? i.e. Production vs. Sandbox'); + } + }); + +apnService.on('timeout', function() { + logger.debug('Connection Timeout'); + }); + +apnService.on('disconnected', function() { + logger.debug('Disconnected from APNS'); + }); + +apnService.on('socketError', logger.error); + + + -var gcmSender = new gcm.Sender({ - key: 'AIzaSyBl1vJ00d_lMb5yKGp97jZ94Oc70GRpZiw' - });*/ var officeController = function(neweventbus) { + this.iosTokens = []; + logger.debug((typeof neweventbus)); if ((typeof neweventbus !== 'undefined') && (neweventbus !== null)) { @@ -282,6 +312,15 @@ officeController.prototype.returnCalendar = function() { }; + +officeController.prototype.registeriOSToken = function(id) { + if (this.iosTokens.indexOf(id) === -1) { + this.iosTokens.push(id); + logger.info('C - IOS Device registered.'); + } +}; + + //OfficeController.prototype.getRoomStatus = function () { // this.calendarControl.getRoomStatus(); // console.log('Checking Calendar.');