From 479cea6ac1afd60a68ddaccaa51bc7d7e7168bc5 Mon Sep 17 00:00:00 2001 From: Nicolas Perriault Date: Thu, 5 Jun 2014 19:57:42 +0200 Subject: [PATCH] Bug 1020451 Implement basic accept/reject call buttons so that video isn't shown before the call is accepted. r=Standard8 --- browser/components/loop/MozLoopService.jsm | 2 +- .../loop/content/js/conversation.js | 63 +++++++++++++++++-- .../loop/content/shared/css/conversation.css | 16 +++++ .../loop/content/shared/css/readme.html | 10 +++ .../test/desktop-local/conversation_test.js | 46 +++++++++++++- .../en-US/chrome/browser/loop/loop.properties | 3 + 6 files changed, 130 insertions(+), 10 deletions(-) diff --git a/browser/components/loop/MozLoopService.jsm b/browser/components/loop/MozLoopService.jsm index ba6931b95904..ec336e14e819 100644 --- a/browser/components/loop/MozLoopService.jsm +++ b/browser/components/loop/MozLoopService.jsm @@ -350,7 +350,7 @@ let MozLoopServiceInternal = { return; } - this.openChatWindow(null, "LooP", "about:loopconversation#start/" + version); + this.openChatWindow(null, "LooP", "about:loopconversation#incoming/" + version); }, /** diff --git a/browser/components/loop/content/js/conversation.js b/browser/components/loop/content/js/conversation.js index a5d857e50252..3d48967218f7 100644 --- a/browser/components/loop/content/js/conversation.js +++ b/browser/components/loop/content/js/conversation.js @@ -18,6 +18,48 @@ loop.conversation = (function(OT, mozL10n) { */ var router; + /** + * Incoming call view. + * @type {loop.shared.views.BaseView} + */ + var IncomingCallView = sharedViews.BaseView.extend({ + template: _.template([ + '

', + '

', + ' ', + ' ', + '

' + ].join("")), + + className: "incoming-call", + + events: { + "click .btn-accept": "handleAccept", + "click .btn-decline": "handleDecline" + }, + + /** + * User clicked on the "accept" button. + * @param {MouseEvent} event + */ + handleAccept: function(event) { + event.preventDefault(); + this.model.trigger("accept"); + }, + + /** + * User clicked on the "decline" button. + * @param {MouseEvent} event + */ + handleDecline: function(event) { + event.preventDefault(); + // XXX For now, we just close the window. + window.close(); + } + }); + /** * Call ended view. * @type {loop.shared.views.BaseView} @@ -53,7 +95,8 @@ loop.conversation = (function(OT, mozL10n) { */ var ConversationRouter = loop.desktopRouter.DesktopConversationRouter.extend({ routes: { - "start/:version": "start", + "incoming/:version": "incoming", + "call/accept": "accept", "call/ongoing": "conversation", "call/ended": "ended" }, @@ -73,16 +116,23 @@ loop.conversation = (function(OT, mozL10n) { }, /** - * start is the initial route that does any necessary prompting and set - * up for the call. + * Incoming call route. * * @param {String} loopVersion The version from the push notification, set * by the router from the URL. */ - start: function(loopVersion) { - // XXX For now, we just kick the conversation straight away, bug 990678 - // will implement the follow-ups. + incoming: function(loopVersion) { this._conversation.set({loopVersion: loopVersion}); + this._conversation.once("accept", function() { + this.navigate("call/accept", {trigger: true}); + }.bind(this)); + this.loadView(new IncomingCallView({model: this._conversation})); + }, + + /** + * Accepts an incoming call. + */ + accept: function() { this._conversation.initiate({ baseServerUrl: window.navigator.mozLoop.serverUrl, outgoing: false @@ -134,6 +184,7 @@ loop.conversation = (function(OT, mozL10n) { return { ConversationRouter: ConversationRouter, EndedCallView: EndedCallView, + IncomingCallView: IncomingCallView, init: init }; })(window.OT, document.mozL10n); diff --git a/browser/components/loop/content/shared/css/conversation.css b/browser/components/loop/content/shared/css/conversation.css index c7f00617f0ef..cf62590e0a36 100644 --- a/browser/components/loop/content/shared/css/conversation.css +++ b/browser/components/loop/content/shared/css/conversation.css @@ -55,3 +55,19 @@ .call-ended p { text-align: center; } + +/* Incoming call */ +.incoming-call { + text-align: center; + min-height: 200px; +} + +.incoming-call h2 { + font-size: 1.5em; + font-weight: normal; + margin-top: 3em; +} + +.incoming-call button { + margin-right: .2em; +} diff --git a/browser/components/loop/content/shared/css/readme.html b/browser/components/loop/content/shared/css/readme.html index 70cbd2c70cb2..ff607aa10ffd 100644 --- a/browser/components/loop/content/shared/css/readme.html +++ b/browser/components/loop/content/shared/css/readme.html @@ -166,6 +166,16 @@

Oops! This is a warning.

+

Incoming call

+ +
+

Incoming call

+

+ + +

+
+