Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions packages/ringcentral-integration/modules/Webphone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const FOURTH_RETRIES_DELAY = 30 * 1000;
const FIFTH_RETRIES_DELAY = 60 * 1000;
const MAX_RETRIES_DELAY = 2 * 60 * 1000;

const INCOMING_CALL_INVALID_STATE_ERROR_CODE = 2;

/**
* @constructor
* @description Web phone module to handle phone interaction with WebRTC.
Expand Down Expand Up @@ -725,30 +727,35 @@ export default class Webphone extends RcModule {

@proxify
async answer(sessionId) {
const session = this._sessions.get(sessionId);
if (!session) {
const sipSession = this._sessions.get(sessionId);
const session = this.sessions.find(session => session.id === sessionId);
if (!session || !isRing(session)) {
return;
}
try {
this._holdOtherSession(session.id);
this._onAccepted(session, 'inbound');
this._beforeCallStart(session);
await session.accept(this.acceptOptions);
this._onCallStart(session);
this._holdOtherSession(sessionId);
this._onAccepted(sipSession, 'inbound');
this._beforeCallStart(sipSession);
await sipSession.accept(this.acceptOptions);
this._onCallStart(sipSession);
this.store.dispatch({ // for track
type: this.actionTypes.callAnswer,
});
} catch (e) {
console.log('Accept failed');
console.error(e);
this._onCallEnd(session);
if (e.code !== INCOMING_CALL_INVALID_STATE_ERROR_CODE) {
// FIXME:
// 2 means the call is answered
this._onCallEnd(sipSession);
}
}
}

@proxify
async reject(sessionId) {
const session = this._sessions.get(sessionId);
if (!session) {
if (!session || session.__rc_callStatus === sessionStatus.finished) {
return;
}
try {
Expand Down
6 changes: 1 addition & 5 deletions packages/ringcentral-widgets-demo/dev-server/Phone.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,7 @@ export default class BasePhone extends RcModule {
});

webphone.onCallStart(() => {
if (
routerInteraction.currentPath.indexOf('/calls/active') !== 0
) {
routerInteraction.push('/calls/active');
}
routerInteraction.push('/calls/active');
});

webphone.onCallRing(() => {
Expand Down