mirror of
https://github.com/moparisthebest/kaiwa
synced 2024-08-13 17:03:51 -04:00
Add experimental push notification support.
This commit is contained in:
parent
aa8fea64cc
commit
03e8e493d7
@ -12,6 +12,7 @@ var MainView = require('./views/main');
|
|||||||
var Router = require('./router');
|
var Router = require('./router');
|
||||||
var Storage = require('./storage');
|
var Storage = require('./storage');
|
||||||
var xmppEventHandlers = require('./helpers/xmppEventHandlers');
|
var xmppEventHandlers = require('./helpers/xmppEventHandlers');
|
||||||
|
var pushNotifications = require('./helpers/pushNotifications');
|
||||||
var Notify = require('notify.js');
|
var Notify = require('notify.js');
|
||||||
var Desktop = require('./helpers/desktop');
|
var Desktop = require('./helpers/desktop');
|
||||||
var AppCache = require('./helpers/cache');
|
var AppCache = require('./helpers/cache');
|
||||||
@ -64,6 +65,7 @@ module.exports = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self.api = window.client = StanzaIO.createClient(config);
|
self.api = window.client = StanzaIO.createClient(config);
|
||||||
|
client.use(pushNotifications);
|
||||||
xmppEventHandlers(self.api, self);
|
xmppEventHandlers(self.api, self);
|
||||||
|
|
||||||
if (self.api.jingle.capabilities.length > 1) {
|
if (self.api.jingle.capabilities.length > 1) {
|
||||||
|
77
clientapp/helpers/pushNotifications.js
Normal file
77
clientapp/helpers/pushNotifications.js
Normal 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);
|
||||||
|
};
|
||||||
|
};
|
@ -79,7 +79,7 @@ module.exports = function (client, app) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
localStorage.config = JSON.stringify({
|
localStorage.config = JSON.stringify({
|
||||||
jid: client.config.jid,
|
jid: client.config.jid.bare,
|
||||||
server: client.config.server,
|
server: client.config.server,
|
||||||
wsURL: client.config.wsURL,
|
wsURL: client.config.wsURL,
|
||||||
credentials: creds
|
credentials: creds
|
||||||
|
@ -28,6 +28,7 @@ module.exports = HumanModel.define({
|
|||||||
this.bind('change:rosterVer', this.save, this);
|
this.bind('change:rosterVer', this.save, this);
|
||||||
this.contacts.bind('change:unreadCount', this.updateUnreadCount, this);
|
this.contacts.bind('change:unreadCount', this.updateUnreadCount, this);
|
||||||
app.state.bind('change:active', this.updateIdlePresence, this);
|
app.state.bind('change:active', this.updateIdlePresence, this);
|
||||||
|
app.state.bind('change:deviceIDReady', this.registerDevice, this);
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
jid: ['object', true],
|
jid: ['object', true],
|
||||||
@ -195,5 +196,13 @@ module.exports = HumanModel.define({
|
|||||||
this.stream.stop();
|
this.stream.stop();
|
||||||
this.stream = null;
|
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');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "otalk.im",
|
"name": "otalk.im",
|
||||||
"version": "0.0.16",
|
"version": "0.0.17",
|
||||||
"description": "Otalk: WebRTC Enabled XMPP Client, in the Browser",
|
"description": "Otalk: WebRTC Enabled XMPP Client, in the Browser",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -21,6 +21,7 @@
|
|||||||
"human-model": "2.6.0",
|
"human-model": "2.6.0",
|
||||||
"human-view": "1.5.0",
|
"human-view": "1.5.0",
|
||||||
"jade": "0.35.0",
|
"jade": "0.35.0",
|
||||||
|
"jxt": "0.5.1",
|
||||||
"moonboots": "1.0.0",
|
"moonboots": "1.0.0",
|
||||||
"node-uuid": "1.4.1",
|
"node-uuid": "1.4.1",
|
||||||
"notify.js": "0.0.3",
|
"notify.js": "0.0.3",
|
||||||
|
Loading…
Reference in New Issue
Block a user