Skip to content

Commit

Permalink
fix: support call switch event (#16)
Browse files Browse the repository at this point in the history
* fix: not disconected when call switched

* enhance: remove JS Proxy

* 0.2.4
  • Loading branch information
embbnux authored Oct 20, 2020
1 parent e684996 commit d299f02
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ringcentral-call-control",
"version": "0.2.3",
"version": "0.2.4",
"main": "lib/index.js",
"license": "MIT",
"repository": {
Expand Down
42 changes: 32 additions & 10 deletions src/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,6 @@ export class Session extends EventEmitter {
this.on('status', ({ party }) => {
this._onPartyUpdated(party);
});

return new Proxy(this, {
get(target, name, receiver) {
if (!Reflect.has(target, name)) {
return target._data[name];
}
return Reflect.get(target, name, receiver);
},
});
}

_updatePartiesSequence(parties: Party[] = [], sequence?: Number) {
Expand Down Expand Up @@ -287,10 +278,34 @@ export class Session extends EventEmitter {
return this.data.id;
}

get accountId() {
return this.data.accountId;
}

get creationTime() {
return this.data.creationTime;
}

get extensionId() {
return this.data.extensionId;
}

get origin() {
return this.data.origin;
}

get parties() {
return this.data.parties || [];
}

get serverId() {
return this.data.serverId;
}

get sessionId() {
return this.data.sessionId;
}

get party() {
const extensionId = this.data.extensionId;
const accountId = this.data.accountId;
Expand All @@ -300,10 +315,17 @@ export class Session extends EventEmitter {
}
return p.extensionId === extensionId;
});
if (parties.length === 0) {
return;
}
if (parties.length === 1) {
return parties[0];
}
return parties.find(p => p.status.code !== PartyStatusCode.disconnected)
const activeParty = parties.find(p => p.status.code !== PartyStatusCode.disconnected);
if (activeParty) {
return activeParty;
}
return parties[parties.length - 1];
}

get otherParties() {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ export class RingCentralCallControl extends EventEmitter {
if (
party &&
party.status.code === PartyStatusCode.disconnected &&
party.status.reason !== 'Pickup'
party.status.reason !== 'Pickup' && // don't end when call switched
party.status.reason !== 'CallSwitch' // don't end when call switched
) {
this._sessionsMap.delete(session.id);
}
Expand Down

0 comments on commit d299f02

Please sign in to comment.