1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-22 09:12:19 -05:00
kaiwa/clientapp/models/resource.js

123 lines
3.6 KiB
JavaScript
Raw Normal View History

/*global app, client*/
2013-08-29 23:38:28 -04:00
"use strict";
var HumanModel = require('human-model');
2013-08-20 13:45:06 -04:00
2013-09-05 19:53:23 -04:00
module.exports = HumanModel.define({
2013-08-29 23:38:28 -04:00
initialize: function () {},
2013-08-20 13:45:06 -04:00
type: 'resource',
session: {
id: ['string', true],
status: 'string',
show: 'string',
priority: ['number', false, 0],
chatState: ['string', false, 'gone'],
idleSince: 'date',
discoInfo: 'object',
timezoneOffset: 'number'
},
derived: {
2013-12-31 18:02:07 -05:00
mucDisplayName: {
deps: ['id'],
fn: function () {
return this.id.split('/')[1] || '';
}
},
idle: {
deps: ['idleSince'],
fn: function () {
return this.idleSince && !isNaN(this.idleSince.valueOf());
2013-12-31 18:02:07 -05:00
}
},
supportsReceipts: {
deps: ['discoInfo'],
fn: function () {
if (!this.discoInfo) return false;
var features = this.discoInfo.features || [];
return features.indexOf('urn:xmpp:receipts') >= 0;
}
},
supportsChatStates: {
deps: ['discoInfo'],
fn: function () {
if (!this.discoInfo) return false;
2013-12-16 13:06:03 -05:00
var features = this.discoInfo.features || [];
return features.indexOf('http://jabber.org/protocol/chatstate') >= 0;
}
},
supportsJingleMedia: {
deps: ['discoInfo'],
fn: function () {
if (!this.discoInfo) return false;
2013-12-16 17:28:13 -05:00
var features = this.discoInfo.features || [];
if (features.indexOf('urn:xmpp:jingle:1') === -1) {
return false;
}
if (features.indexOf('urn:xmpp:jingle:apps:rtp:1') === -1) {
return false;
}
if (features.indexOf('urn:xmpp:jingle:apps:rtp:audio') === -1) {
return false;
}
if (features.indexOf('urn:xmpp:jingle:apps:rtp:video') === -1) {
return false;
}
2014-06-13 16:26:02 -04:00
return true;
}
},
supportsJingleFiletransfer: {
deps: ['discoInfo'],
fn: function () {
if (!this.discoInfo) return false;
var features = this.discoInfo.features || [];
if (features.indexOf('urn:xmpp:jingle:1') === -1) {
return false;
}
if (features.indexOf('urn:xmpp:jingle:apps:file-transfer:3') === -1) {
return false;
}
if (features.indexOf('urn:xmpp:jingle:transports:ice-udp:1') === -1) {
return false;
}
if (features.indexOf('urn:xmpp:jingle:transports:dtls-sctp:1') === -1) {
return false;
}
return true;
}
}
},
fetchTimezone: function () {
var self = this;
if (self.timezoneOffset) return;
app.whenConnected(function () {
client.getTime(self.id, function (err, res) {
if (err) return;
self.timezoneOffset = res.time.tzo;
});
});
},
fetchDisco: function () {
var self = this;
if (self.discoInfo) return;
app.whenConnected(function () {
client.getDiscoInfo(self.id, '', function (err, res) {
if (err) return;
2015-02-09 09:22:17 -05:00
self.discoInfo = res.discoInfo;
});
});
2013-08-20 13:45:06 -04:00
}
});