Add experimental push notification support.

This commit is contained in:
Lance Stout 2014-01-23 16:34:21 -08:00
parent aa8fea64cc
commit 03e8e493d7
5 changed files with 91 additions and 2 deletions

View File

@ -12,6 +12,7 @@ var MainView = require('./views/main');
var Router = require('./router');
var Storage = require('./storage');
var xmppEventHandlers = require('./helpers/xmppEventHandlers');
var pushNotifications = require('./helpers/pushNotifications');
var Notify = require('notify.js');
var Desktop = require('./helpers/desktop');
var AppCache = require('./helpers/cache');
@ -64,6 +65,7 @@ module.exports = {
};
self.api = window.client = StanzaIO.createClient(config);
client.use(pushNotifications);
xmppEventHandlers(self.api, self);
if (self.api.jingle.capabilities.length > 1) {

View File

@ -0,0 +1,77 @@
"use strict";
var jxt = require('jxt');
var stanzaio = require('stanza.io');
jxt.extend(stanzaio.Message, jxt.define({
name: 'pushNotification',
namespace: 'urn:xmpp:push:0',
element: 'push',
fields: {
body: jxt.subText('urn:xmpp:push:0', 'body')
}
}));
jxt.extend(stanzaio.Iq, jxt.define({
name: 'registerPush',
namespace: 'urn:xmpp:push:0',
element: 'register',
fields: {
service: jxt.text()
}
}));
jxt.extend(stanzaio.Iq, jxt.define({
name: 'unregisterPush',
namespace: 'urn:xmpp:push:0',
element: 'unregister',
fields: {
service: jxt.text()
}
}));
jxt.extend(stanzaio.Iq, jxt.define({
name: 'otalkRegister',
namespace: 'http://otalk.im/protocol/push',
element: 'register',
fields: {
deviceID: jxt.text()
}
}));
module.exports = function (client) {
client.registerPushService = function (jid, cb) {
return client.sendIq({
type: 'set',
registerPush: {
service: jid
}
}, cb);
};
client.getPushServices = function (cb) {
return client.getDiscoItems('', 'urn:xmpp:push', cb);
};
client.unregisterPushService = function (jid, cb) {
return client.sendIq({
type: 'set',
unregisterPush: {
service: jid
}
}, cb);
};
client.otalkRegister = function (deviceID, cb) {
return client.sendIq({
type: 'set',
to: 'push@push.otalk.im/prod',
otalkRegister: {
deviceID: deviceID
}
}, cb);
};
};

View File

@ -79,7 +79,7 @@ module.exports = function (client, app) {
}
localStorage.config = JSON.stringify({
jid: client.config.jid,
jid: client.config.jid.bare,
server: client.config.server,
wsURL: client.config.wsURL,
credentials: creds

View File

@ -28,6 +28,7 @@ module.exports = HumanModel.define({
this.bind('change:rosterVer', this.save, this);
this.contacts.bind('change:unreadCount', this.updateUnreadCount, this);
app.state.bind('change:active', this.updateIdlePresence, this);
app.state.bind('change:deviceIDReady', this.registerDevice, this);
},
props: {
jid: ['object', true],
@ -195,5 +196,13 @@ module.exports = HumanModel.define({
this.stream.stop();
this.stream = null;
}
},
registerDevice: function () {
var deviceID = app.state.deviceID;
client.otalkRegister(deviceID).then(function () {
client.registerPush('push@push.otalk.im/prod');
}).catch(function (err) {
console.log('Could not enable push notifications');
});
}
});

View File

@ -1,6 +1,6 @@
{
"name": "otalk.im",
"version": "0.0.16",
"version": "0.0.17",
"description": "Otalk: WebRTC Enabled XMPP Client, in the Browser",
"repository": {
"type": "git",
@ -21,6 +21,7 @@
"human-model": "2.6.0",
"human-view": "1.5.0",
"jade": "0.35.0",
"jxt": "0.5.1",
"moonboots": "1.0.0",
"node-uuid": "1.4.1",
"notify.js": "0.0.3",