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

Save jingle changes

This commit is contained in:
Lance Stout 2013-10-15 00:02:45 -07:00
parent 2cec815821
commit c736a7722e
8 changed files with 85 additions and 10 deletions

View File

@ -28,6 +28,7 @@ module.exports = {
} }
config = JSON.parse(config); config = JSON.parse(config);
config.useStreamManagement = false;
_.extend(this, Backbone.Events); _.extend(this, Backbone.Events);

View File

@ -333,4 +333,50 @@ module.exports = function (client, app) {
} }
} }
}); });
client.on('jingle:incoming', function (session) {
var contact = me.getContact(session.peer);
contact.callState = 'incoming';
contact.jingleCall = session;
});
client.on('jingle:outgoing', function (session) {
var contact = me.getContact(session.peer);
contact.callState = 'outgoing';
contact.jingleCall = session;
});
client.on('jingle:terminated', function (session) {
var contact = me.getContact(session.peer);
contact.callState = '';
contact.jingleCall = null;
});
client.on('jingle:accepted', function (session) {
var contact = me.getContact(session.peer);
contact.callState = 'active';
});
client.on('jingle:localstream:added', function (stream) {
me.stream = stream;
});
client.on('jingle:localstream:removed', function () {
me.stream = null;
});
client.on('jingle:remotestream:added', function (session) {
var contact = me.getContact(session.peer);
contact.stream = session.stream;
});
client.on('jingle:remotestream:removed', function (session) {
var contact = me.getContact(session.peer);
contact.stream = null;
});
client.on('jingle:ringing', function (session) {
var contact = me.getContact(session.peer);
contact.callState = 'ringing';
});
}; };

View File

@ -2,6 +2,7 @@
"use strict"; "use strict";
var _ = require('underscore'); var _ = require('underscore');
var crypto = require('crypto');
var async = require('async'); var async = require('async');
var uuid = require('node-uuid'); var uuid = require('node-uuid');
var HumanModel = require('human-model'); var HumanModel = require('human-model');
@ -44,7 +45,9 @@ module.exports = HumanModel.define({
offlineStatus: ['string', true, ''], offlineStatus: ['string', true, ''],
topResource: 'string', topResource: 'string',
unreadCount: ['number', true, 0], unreadCount: ['number', true, 0],
_forceUpdate: ['number', true, 0] _forceUpdate: ['number', true, 0],
callState: 'string',
stream: 'object'
}, },
derived: { derived: {
displayName: { displayName: {
@ -137,7 +140,7 @@ module.exports = HumanModel.define({
} }
}, },
jingleResources: { jingleResources: {
cache: false, deps: ['_forceUpdate'],
fn: function () { fn: function () {
return this.resources.filter(function (res) { return this.resources.filter(function (res) {
return res.supportsJingleMedia; return res.supportsJingleMedia;
@ -149,6 +152,17 @@ module.exports = HumanModel.define({
resources: Resources, resources: Resources,
messages: Messages messages: Messages
}, },
call: function () {
if (this.jingleResources) {
var peer = this.jingleResources[0];
this.callState = 'starting';
app.api.jingle.startLocalMedia(null, function (err) {
if (!err) {
app.api.call(peer.id);
}
});
}
},
setAvatar: function (id, type) { setAvatar: function (id, type) {
var self = this; var self = this;
fetchAvatar(this.jid, id, type, function (avatar) { fetchAvatar(this.jid, id, type, function (avatar) {
@ -254,8 +268,9 @@ module.exports = HumanModel.define({
save: function () { save: function () {
if (!this.inRoster) return; if (!this.inRoster) return;
var storageId = crypto.createHash('sha1').update(this.owner + '/' + this.id).digest('hex');
var data = { var data = {
storageId: this.storageId, storageId: storageId,
owner: this.owner, owner: this.owner,
jid: this.jid, jid: this.jid,
name: this.name, name: this.name,

View File

@ -6,7 +6,6 @@ var Contacts = require('./contacts');
var Contact = require('./contact'); var Contact = require('./contact');
var MUCs = require('./mucs'); var MUCs = require('./mucs');
var MUC = require('./muc'); var MUC = require('./muc');
var uuid = require('node-uuid');
var fetchAvatar = require('../helpers/fetchAvatar'); var fetchAvatar = require('../helpers/fetchAvatar');
@ -74,7 +73,6 @@ module.exports = HumanModel.define({
contact = new Contact(data); contact = new Contact(data);
contact.inRoster = true; contact.inRoster = true;
contact.owner = this.jid.bare; contact.owner = this.jid.bare;
contact.storageId = uuid.v4();
contact.save(); contact.save();
this.contacts.add(contact); this.contacts.add(contact);
} }

View File

@ -7,6 +7,7 @@ var templates = require('../templates');
var Message = require('../views/message'); var Message = require('../views/message');
var MessageModel = require('../models/message'); var MessageModel = require('../models/message');
var chatHelpers = require('../helpers/chatHelpers'); var chatHelpers = require('../helpers/chatHelpers');
var attachMediaStream = require('attachmediastream');
module.exports = BasePage.extend(chatHelpers).extend({ module.exports = BasePage.extend(chatHelpers).extend({
@ -22,6 +23,8 @@ module.exports = BasePage.extend(chatHelpers).extend({
this.listenTo(this.model.messages, 'change:edited', this.refreshModel); this.listenTo(this.model.messages, 'change:edited', this.refreshModel);
this.listenTo(this.model.messages, 'change:pending', this.refreshModel); this.listenTo(this.model.messages, 'change:pending', this.refreshModel);
this.listenTo(this.model, 'change:stream', this.handleStream);
this.render(); this.render();
}, },
events: { events: {
@ -80,7 +83,8 @@ module.exports = BasePage.extend(chatHelpers).extend({
handlePageUnloaded: function () { handlePageUnloaded: function () {
this.scrollPageUnload(); this.scrollPageUnload();
}, },
handleCallClick: function () { handleCallClick: function (e) {
e.preventDefault();
this.model.call(); this.model.call();
return false; return false;
}, },
@ -191,6 +195,11 @@ module.exports = BasePage.extend(chatHelpers).extend({
var resources = val || this.model.jingleResources; var resources = val || this.model.jingleResources;
this.$('button.call').prop('disabled', !resources.length); this.$('button.call').prop('disabled', !resources.length);
}, },
handleStream: function () {
if (this.model.stream) {
attachMediaStream(this.model.stream, this.$('.remoteVideo'));
}
},
appendModel: function (model, preload) { appendModel: function (model, preload) {
var self = this; var self = this;
var isGrouped = model.shouldGroupWith(this.lastModel); var isGrouped = model.shouldGroupWith(this.lastModel);

View File

@ -3,7 +3,7 @@
"version": "0.0.1", "version": "0.0.1",
"description": "Otalk: WebRTC Enabled XMPP Client, in the Browser", "description": "Otalk: WebRTC Enabled XMPP Client, in the Browser",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git@github.com:andyet/otalk.git" "url": "git@github.com:andyet/otalk.git"
}, },
"dependencies": { "dependencies": {
@ -23,9 +23,12 @@
"templatizer": "0.1.2", "templatizer": "0.1.2",
"underscore": "1.5.1", "underscore": "1.5.1",
"raf-component": "1.1.1", "raf-component": "1.1.1",
"stanza.io": "2.5.7", "stanza.io": "2.5.9",
"notify.js": "0.0.1", "notify.js": "0.0.1",
"wildemitter": "0.0.5" "wildemitter": "0.0.5",
"attachmediastream": "",
"crypto-browserify": "1.0.3",
"browserify": "2.25.1"
}, },
"devDependencies": { "devDependencies": {
"precommit-hook": "0.3.6" "precommit-hook": "0.3.6"

View File

@ -1,5 +1,5 @@
CACHE MANIFEST CACHE MANIFEST
# 0.0.1 1381790561081 # 0.0.1 1381820535074
CACHE: CACHE:
/app.js /app.js

View File

@ -28,6 +28,9 @@ var clientApp = new Moonboots({
__dirname + '/clientapp/libraries/resampler.js', __dirname + '/clientapp/libraries/resampler.js',
__dirname + '/clientapp/libraries/IndexedDBShim.min.js' __dirname + '/clientapp/libraries/IndexedDBShim.min.js'
], ],
browserify: {
debug: false
},
stylesheets: [ stylesheets: [
__dirname + '/public/css/otalk.css' __dirname + '/public/css/otalk.css'
], ],