From 72f1f4109e5da56669d8ada7292a73cd67309e64 Mon Sep 17 00:00:00 2001 From: "Ian W. Remmel" Date: Tue, 28 Mar 2017 15:17:30 -0700 Subject: [PATCH] fix(plugin-phone): put back locusJoinInFlight, locusLeaveInFlight, which disappeared in a bad merge --- packages/plugin-phone/src/call.js | 42 +++++++++++++------ packages/plugin-phone/src/web-rtc-media.js | 15 +++++-- .../test/integration/spec/call.js | 6 ++- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/packages/plugin-phone/src/call.js b/packages/plugin-phone/src/call.js index 907f23904d7..deeb043760b 100644 --- a/packages/plugin-phone/src/call.js +++ b/packages/plugin-phone/src/call.js @@ -8,7 +8,7 @@ /* global RTCPeerConnection, RTCSessionDescription */ import {SparkPlugin} from '@ciscospark/spark-core'; -import {base64, oneFlight, retry, tap} from '@ciscospark/common'; +import {base64, oneFlight, retry, tap, whileInFlight} from '@ciscospark/common'; import { USE_INCOMING, FETCH @@ -128,6 +128,15 @@ const Call = SparkPlugin.extend({ * @readonly */ localMediaStreamUrl: `string`, + + locusJoinInFlight: { + default: false, + type: `boolean` + }, + locusLeaveInFlight: { + default: false, + type: `boolean` + }, /** * Object URL that refers to {@link Call#remoteMediaStream}. Will be * automatically deallocated when the call ends @@ -477,6 +486,7 @@ const Call = SparkPlugin.extend({ * @returns {Promise} */ @oneFlight + @whileInFlight(`locusJoinInFlight`) answer(options) { this.logger.info(`call: answering`); if (!this.locus || this.direction === `out`) { @@ -519,6 +529,7 @@ const Call = SparkPlugin.extend({ */ @oneFlight dial(invitee, options) { + this.locusJoinInFlight = true; this.logger.info(`call: dialing`); if (base64.validate(invitee)) { @@ -541,6 +552,9 @@ const Call = SparkPlugin.extend({ .then(tap(() => this.logger.info(`call: dialed`))) .catch((reason) => { this.trigger(`error`, reason); + }) + .then(() => { + this.locusJoinInFlight = false; }); return this; @@ -564,13 +578,13 @@ const Call = SparkPlugin.extend({ this.media.end(); - if (!this.locus) { - if (this.locusJoinInFlight) { - this.logger.info(`call: no locus, waiting for rest call to complete before hanging up`); - return this.when(`change:locus`) - .then(() => this.hangup()); - } + if (this.locusJoinInFlight) { + this.logger.info(`call: locus join in flight, waiting for rest call to complete before hanging up`); + return this.when(`change:locusJoinInFlight`) + .then(() => this.hangup()); + } + if (!this.locus) { this.stopListening(this.spark.mercury); this.off(); this.logger.info(`call: hang up complete, call never created`); @@ -587,13 +601,10 @@ const Call = SparkPlugin.extend({ * @returns {Promise} */ @oneFlight + @whileInFlight(`locusLeaveInFlight`) _hangup() { - this.locusLeaveInFlight = true; return this.spark.locus.leave(this.locus) .then((locus) => this._setLocus(locus)) - .then(() => { - this.locusLeaveInFlight = false; - }) .then(tap(() => this.stopListening(this.spark.mercury))) .then(tap(() => this.off())) .then(tap(() => this.logger.info(`call: hung up`))); @@ -871,9 +882,14 @@ const Call = SparkPlugin.extend({ })) .then((locus) => { this._setLocus(locus); - this.locusJoinInFlight = false; const answer = JSON.parse(this.mediaConnection.remoteSdp).sdp; - return this.media.acceptAnswer(answer); + this.logger.info(`accepting offer`); + this.logger.info(`peer state`, this.media.peer && this.media.peer.signalingState); + if (!this.media.ended) { + return this.media.acceptAnswer(answer) + .then(() => this.logger.info(`offer accepted`)); + } + this.logger.info(`call: already ended, not accepting answer`); }); }, diff --git a/packages/plugin-phone/src/web-rtc-media.js b/packages/plugin-phone/src/web-rtc-media.js index e4d2afcfbcd..a6c720ea8ac 100644 --- a/packages/plugin-phone/src/web-rtc-media.js +++ b/packages/plugin-phone/src/web-rtc-media.js @@ -101,6 +101,10 @@ const WebRTCMedia = AmpState.extend({ type: `boolean` }, audioConstraint: `any`, + ended: { + default: false, + type: `boolean` + }, localMediaStream: { default: undefined, type: `object` @@ -214,11 +218,14 @@ const WebRTCMedia = AmpState.extend({ }, end() { - if (this.peer && this.peer.signalingState !== `closed`) { - end(this.peer); + if (!this.ended) { + if (this.peer && this.peer.signalingState !== `closed`) { + end(this.peer); + } + this.unset(`localMediaStream`); + this.unset(`remoteMediaStream`); + this.ended = true; } - this.unset(`localMediaStream`); - this.unset(`remoteMediaStream`); }, initialize(...args) { diff --git a/packages/plugin-phone/test/integration/spec/call.js b/packages/plugin-phone/test/integration/spec/call.js index 80529c08d1e..e5573dc3133 100644 --- a/packages/plugin-phone/test/integration/spec/call.js +++ b/packages/plugin-phone/test/integration/spec/call.js @@ -521,8 +521,10 @@ describe(`plugin-phone`, function() { .then(([c]) => { handler.add(c); assert.equal(c.status, `initiated`); - return call.hangup() - .then(() => c.when(`disconnected`, () => assert.equal(c.status, `disconnected`))); + return Promise.all([ + call.hangup(), + c.when(`disconnected`, () => assert.equal(c.status, `disconnected`)) + ]); }); return p; });