Skip to content

Commit

Permalink
fix(plugin-phone): put back locusJoinInFlight, locusLeaveInFlight, wh…
Browse files Browse the repository at this point in the history
…ich disappeared in a bad merge
  • Loading branch information
Ian W. Remmel committed Mar 28, 2017
1 parent 6ee09f7 commit 72f1f41
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
42 changes: 29 additions & 13 deletions packages/plugin-phone/src/call.js
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`) {
Expand Down Expand Up @@ -519,6 +529,7 @@ const Call = SparkPlugin.extend({
*/
@oneFlight
dial(invitee, options) {
this.locusJoinInFlight = true;
this.logger.info(`call: dialing`);

if (base64.validate(invitee)) {
Expand All @@ -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;
Expand All @@ -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`);
Expand All @@ -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`)));
Expand Down Expand 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`);
});
},

Expand Down
15 changes: 11 additions & 4 deletions packages/plugin-phone/src/web-rtc-media.js
Expand Up @@ -101,6 +101,10 @@ const WebRTCMedia = AmpState.extend({
type: `boolean`
},
audioConstraint: `any`,
ended: {
default: false,
type: `boolean`
},
localMediaStream: {
default: undefined,
type: `object`
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-phone/test/integration/spec/call.js
Expand Up @@ -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;
});
Expand Down

0 comments on commit 72f1f41

Please sign in to comment.