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
66 changes: 66 additions & 0 deletions packages/ringcentral-integration/modules/CallMonitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Module } from '../../lib/di';
import RcModule from '../../lib/RcModule';
import moduleStatuses from '../../enums/moduleStatuses';
import actionTypes from './actionTypes';
import calleeTypes from '../../enums/calleeTypes';
import callDirections from '../../enums/callDirections';
import sessionStatus from '../Webphone/sessionStatus';
import getCallMonitorReducer, { getCallMatchedReducer } from './getCallMonitorReducer';
import normalizeNumber from '../../lib/normalizeNumber';
import {
Expand Down Expand Up @@ -74,6 +76,7 @@ function matchWephoneSessionWithAcitveCall(sessions, callItem) {
{ dep: 'ContactMatcher', optional: true },
{ dep: 'Webphone', optional: true },
{ dep: 'Call', optional: true },
{ dep: 'ConferenceCall', optional: true },
{ dep: 'ActivityMatcher', optional: true },
{ dep: 'CallMonitorOptions', optional: true },
{ dep: 'TabManager', optional: true },
Expand All @@ -84,6 +87,7 @@ export default class CallMonitor extends RcModule {
* @constructor
* @param {Object} params - params object
* @param {Call} params.call - call module instance
* @param {ConferenceCall} params.conferenceCall - conference call module instance
* @param {AccountInfo} params.accountInfo - accountInfo module instance
* @param {DetailedPresence} params.detailedPresence - detailedPresence module instance
* @param {ActivityMatcher} params.activityMatcher - activityMatcher module instance
Expand All @@ -97,6 +101,7 @@ export default class CallMonitor extends RcModule {
*/
constructor({
call,
conferenceCall,
accountInfo,
detailedPresence,
activityMatcher,
Expand All @@ -115,6 +120,7 @@ export default class CallMonitor extends RcModule {
actionTypes,
});
this._call = call;
this._conferenceCall = conferenceCall;
this._accountInfo = this::ensureExist(accountInfo, 'accountInfo');
this._detailedPresence = this::ensureExist(detailedPresence, 'detailedPresence');
this._contactMatcher = contactMatcher;
Expand Down Expand Up @@ -327,6 +333,60 @@ export default class CallMonitor extends RcModule {
calls => calls.map(callItem => callItem.sessionId)
);

let _lastCallInfo = {};
this.addSelector('lastCallInfo',
() => this.calls,
() => this._conferenceCall && this._conferenceCall.mergingPair.fromSessionId,
() => this._conferenceCall && this._conferenceCall.partyProfiles,
(calls, fromSessionId, partyProfiles) => {
const lastCall = calls.find(
call => call.webphoneSession && call.webphoneSession.id === fromSessionId
);

let lastCalleeType = null;
if (lastCall) {
if (lastCall.toMatches.length) {
lastCalleeType = calleeTypes.contacts;
} else if (isConferenceSession(lastCall.webphoneSession)) {
lastCalleeType = calleeTypes.conference;
} else {
lastCalleeType = calleeTypes.unknow;
}
} else if (_lastCallInfo.calleeType) {
_lastCallInfo = {
..._lastCallInfo,
status: sessionStatus.finished,
};
return _lastCallInfo;
}

if (lastCalleeType === calleeTypes.conference) {
const partiesAvatarUrls = (partyProfiles || []).map(profile => profile.avatarUrl);
_lastCallInfo = {
calleeType: calleeTypes.conference,
avatarUrl: partiesAvatarUrls[0],
extraNum: partiesAvatarUrls.length - 1,
};
} else if (lastCalleeType === calleeTypes.contacts) {
_lastCallInfo = {
calleeType: calleeTypes.contacts,
avatarUrl: lastCall.toMatches[0].profileImageUrl,
name: lastCall.toName,
status: lastCall.webphoneSession.callStatus,
};
} else if (lastCalleeType === calleeTypes.unknow) {
_lastCallInfo = {
calleeType: calleeTypes.unknow,
avatarUrl: null,
name: lastCall.to.phoneNumber,
status: lastCall.webphoneSession ? lastCall.webphoneSession.callStatus : null,
};
}

return _lastCallInfo;
},
);

if (this._activityMatcher) {
this._activityMatcher.addQuerySource({
getQueriesFn: this._selectors.sessionIds,
Expand All @@ -342,6 +402,7 @@ export default class CallMonitor extends RcModule {
async _onStateChange() {
if (
(!this._call || this._call.ready) &&
(!this._conferenceCall || this._conferenceCall.ready) &&
this._accountInfo.ready &&
this._detailedPresence.ready &&
(!this._contactMatcher || this._contactMatcher.ready) &&
Expand All @@ -359,6 +420,7 @@ export default class CallMonitor extends RcModule {
} else if (
(
(this._call && !this._call.ready) ||
(this._conferenceCall && !this._conferenceCall.ready) ||
!this._accountInfo.ready ||
!this._detailedPresence.ready ||
(this._contactMatcher && !this._contactMatcher.ready) ||
Expand Down Expand Up @@ -525,4 +587,8 @@ export default class CallMonitor extends RcModule {
get otherDeviceCalls() {
return this._selectors.otherDeviceCalls();
}

get lastCallInfo() {
return this._selectors.lastCallInfo();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ export function getMergingStatusReducer(types) {
}

export function getMergingPairReducer(types) {
return (state = {}, { type, from, to }) => {
return (state = {}, { type, fromSessionId, toSessionId }) => {
switch (type) {
case types.updateFromSession:
return { from };
return { fromSessionId };
case types.updateToSession:
return { ...state, to };
return { ...state, toSessionId };
case types.mergeSucceeded:
case types.resetSuccess:
return {};
Expand Down
44 changes: 29 additions & 15 deletions packages/ringcentral-integration/modules/ConferenceCall/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,6 @@ export default class ConferenceCall extends RcModule {
...options
}) {
super({
auth,
alert,
call,
callingSettings,
client,
rolesAndPermissions,
pulling,
contactMatcher,
webphone,
connectivityMonitor,
...options,
actionTypes,
});
Expand All @@ -108,6 +98,20 @@ export default class ConferenceCall extends RcModule {
this._timers = {};
this._pulling = pulling;
this.capacity = capacity;

this.addSelector('partyProfiles',
() => (
Object.values(this.conferences)[0] &&
Object.values(this.conferences)[0].conference.parties
),
() => {
const conferenceData = Object.values(this.conferences)[0];
if (!conferenceData) {
return [];
}
return this.getOnlinePartyProfiles(conferenceData.conference.id);
},
);
}

isConferenceSession(sessionId) {
Expand Down Expand Up @@ -354,7 +358,8 @@ export default class ConferenceCall extends RcModule {
* to avoid `this._webphone` criterias to improve performance ahead of time
*/
async mergeToConference(webphoneSessions = []) {
webphoneSessions = webphoneSessions.filter(session => Object.prototype.toString.call(session).toLowerCase() === '[object object]');
webphoneSessions = webphoneSessions.filter(session => !this.isConferenceSession(session.id))
.filter(session => Object.prototype.toString.call(session).toLowerCase() === '[object object]');

if (!webphoneSessions.length) {
this._alert.warning({
Expand Down Expand Up @@ -449,16 +454,16 @@ export default class ConferenceCall extends RcModule {
* we need to record the merge destination when merge from the call control pages
* @param {webphone.session} from
*/
setMergeParty({ from, to }) {
if (from) {
setMergeParty({ fromSessionId, toSessionId }) {
if (fromSessionId) {
return this.store.dispatch({
type: this.actionTypes.updateFromSession,
from,
fromSessionId,
});
}
return this.store.dispatch({
type: this.actionTypes.updateToSession,
to,
toSessionId,
});
}

Expand Down Expand Up @@ -547,6 +552,7 @@ export default class ConferenceCall extends RcModule {
this._timout = timeout;
return timeout;
}

_init() {
this.store.dispatch({
type: this.actionTypes.initSuccess
Expand Down Expand Up @@ -758,4 +764,12 @@ export default class ConferenceCall extends RcModule {
get isMerging() {
return this.state.isMerging;
}

get mergingPair() {
return this.state.mergingPair;
}

get partyProfiles() {
return this._selectors.partyProfiles();
}
}
1 change: 0 additions & 1 deletion packages/ringcentral-integration/modules/Webphone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export default class Webphone extends RcModule {
this._remoteVideo = null;
this._localVideo = null;
this._sessions = new Map();

this._reducer = getWebphoneReducer(this.actionTypes);

this.addSelector('sessionPhoneNumbers',
Expand Down
85 changes: 69 additions & 16 deletions packages/ringcentral-widgets-demo/dev-server/Phone.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import SDK from 'ringcentral';
import RingCentralClient from 'ringcentral-client';
import { combineReducers } from 'redux';

import RcModule from 'ringcentral-integration/lib/RcModule';

Expand Down Expand Up @@ -43,6 +42,7 @@ import Conversations from 'ringcentral-integration/modules/Conversations';
import ContactSearch from 'ringcentral-integration/modules/ContactSearch';
import DateTimeFormat from 'ringcentral-integration/modules/DateTimeFormat';
import Conference from 'ringcentral-integration/modules/Conference';
import ConferenceCall from 'ringcentral-integration/modules/ConferenceCall';

import ActiveCalls from 'ringcentral-integration/modules/ActiveCalls';
import DetailedPresence from 'ringcentral-integration/modules/DetailedPresence';
Expand Down Expand Up @@ -161,7 +161,15 @@ import LocalForageStorage from 'ringcentral-integration/lib/LocalForageStorage';
enableLoadOldMessages: true,
},
spread: true
}
},
{ provide: 'ConferenceCall', useClass: ConferenceCall },
// {
// provide: 'ConferenceCallOptions',
// useValue: {
// pulling: false,
// },
// spread: true,
// },
]
})
export default class BasePhone extends RcModule {
Expand All @@ -172,6 +180,7 @@ export default class BasePhone extends RcModule {
contactSearch,
contacts,
contactMatcher,
conferenceCall,
...options
}) {
super({
Expand Down Expand Up @@ -216,27 +225,71 @@ export default class BasePhone extends RcModule {
readyCheckFn: () => contacts.ready,
});


webphone._onCallEndFunc = (session) => {
if (routerInteraction.currentPath !== '/calls/active') {
webphone._onCallEndFunc = (session, currentSession) => {
if (
routerInteraction.currentPath.indexOf('/conferenceCall/mergeCtrl') === 0 &&
webphone.cachedSessions.length && (
!currentSession ||
(webphone.cachedSessions.find(cachedSession => cachedSession.id === currentSession.id))
)
) {
return;
}
const currentSession = webphone.activeSession;
if (currentSession && session.id !== currentSession.id) {
return;

if (currentSession
&& routerInteraction.currentPath.indexOf('/conferenceCall/mergeCtrl') === 0) {
const mergingPairFromId = conferenceCall.mergingPair.fromSessionId;
if (session.id !== mergingPairFromId) {
routerInteraction.push('/calls/active');
return;
}
}

if (
!![
'/conferenceCall/mergeCtrl',
'/conferenceCall/dialer/',
'/calls/active'
].find(path => routerInteraction.currentPath.indexOf(path) !== -1) &&
(!currentSession || session.id === currentSession.id)
) {
if (
routerInteraction.currentPath.indexOf('/conferenceCall/mergeCtrl') === 0 ||
routerInteraction.currentPath.indexOf('/conferenceCall/dialer/') === 0 ||
!currentSession
) {
routerInteraction.push('/dialer');
return;
}
if (routerInteraction.currentPath.indexOf('/calls/active') !== 0) { // mean have params
routerInteraction.push('/calls/active');
}
routerInteraction.goBack();
}
routerInteraction.goBack();
};
webphone._onCallStartFunc = () => {
if (routerInteraction.currentPath === '/calls/active') {

webphone._onCallStartFunc = (session) => {
if (routerInteraction.currentPath.indexOf('/conferenceCall/dialer/') === 0) {
routerInteraction.push('/conferenceCall/mergeCtrl');
return;
}
routerInteraction.push('/calls/active');
};
webphone._onCallRingFunc = () => {

const isConferenceCallSession = (
conferenceCall
&& conferenceCall.isConferenceSession(session.id)
);

if (
webphone.ringSessions.length > 1
routerInteraction.currentPath.indexOf('/calls/active') !== 0 &&
routerInteraction.currentPath.indexOf('/conferenceCall/mergeCtrl') !== 0 &&
!(isConferenceCallSession && routerInteraction.currentPath === '/calls')
) {
routerInteraction.push('/calls/active');
}
};

webphone._onCallRingFunc = () => {
if (webphone.ringSessions.length > 1) {
if (routerInteraction.currentPath !== '/calls') {
routerInteraction.push('/calls');
}
Expand Down Expand Up @@ -366,6 +419,6 @@ export function createPhone({
},
]
})
class Phone extends BasePhone {}
class Phone extends BasePhone { }
return Phone.create();
}
Loading