Skip to content

Commit 9314822

Browse files
Merge pull request #282 from Azure-Samples/dmceachernmsft/active-call-transfer
Active call transfer feature
2 parents 9ba14fc + b92d7b0 commit 9314822

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

Project/src/MakeCall/MakeCall.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import { CallClient, LocalVideoStream, Features, CallAgentKind, VideoStreamRenderer } from '@azure/communication-calling';
33
import { AzureCommunicationTokenCredential, createIdentifierFromRawId} from '@azure/communication-common';
4-
import { PrimaryButton } from '@fluentui/react/lib/Button';
4+
import { DefaultButton, PrimaryButton } from '@fluentui/react/lib/Button';
55
import { TextField } from '@fluentui/react/lib/TextField';
66
import { MessageBar, MessageBarType, Toggle } from '@fluentui/react';
77
import { Icon } from '@fluentui/react/lib/Icon';
@@ -83,7 +83,8 @@ export default class MakeCall extends React.Component {
8383
},
8484
preCallDiagnosticsResults: {},
8585
isTeamsUser: false,
86-
identityMri: undefined
86+
identityMri: undefined,
87+
activeCallDetails: undefined
8788
};
8889

8990
// override logger to be able to dowload logs locally
@@ -155,6 +156,17 @@ export default class MakeCall extends React.Component {
155156
await this.callClient.createTeamsCallAgent(tokenCredential) :
156157
await this.callClient.createCallAgent(tokenCredential, { displayName: userDetails.displayName });
157158
window.callAgent = this.callAgent;
159+
160+
this.callAgent.on('activeCallsUpdated', (args) => {
161+
console.log(`activeCallsUpdated, activeCalls=${args.activeCallDetails}`);
162+
this.setState({activeCallDetails: args.activeCallDetails});
163+
});
164+
165+
this.callAgent.on('noActiveCalls', () => {
166+
console.log('noActiveCalls event received - user no longer in a call');
167+
this.setState({activeCallDetails: undefined});
168+
});
169+
158170

159171
this.callAgent.on('callsUpdated', e => {
160172
console.log(`callsUpdated, added=${e.added}, removed=${e.removed}`);
@@ -224,6 +236,8 @@ export default class MakeCall extends React.Component {
224236
this.logInComponentRef.current.setCallAgent(this.callAgent);
225237
this.logInComponentRef.current.setCallClient(this.callClient);
226238
this.autoJoinMeetingByMeetingLink();
239+
const activeCalls = await this.callAgent.getActiveCallDetails();
240+
this.setState({ activeCallDetails: activeCalls.callId ? activeCalls : undefined });
227241
} catch (e) {
228242
console.error(e);
229243
}
@@ -986,6 +1000,32 @@ this.callAgent.on('incomingCall', async (args) => {
9861000
{this.state.ufdMessages.map((msg, index) => <li key={index}>{msg.msg}</li>)}
9871001
</MessageBar>
9881002
}
1003+
{
1004+
this.state.activeCallDetails && !this.state.call && <MessageBar
1005+
messageBarType={MessageBarType.warning}
1006+
isMultiline={true}
1007+
onDismiss={() => { this.setState({ activeCallDetails: undefined }) }}
1008+
dismissButtonAriaLabel="Close">
1009+
<div className="ms-Grid-row">
1010+
<b className="ms-Grid-col">You're in an active call!</b>
1011+
<div className="ms-Grid-col">
1012+
<DefaultButton onClick={async () => {
1013+
const callOptions = await this.getCallOptions({video: false, micMuted: false});
1014+
const newCall = await this.callAgent.activeCallTransfer(this.state.activeCallDetails, {isTransfer: true, joinCallOptions: callOptions});
1015+
this.setState({call: newCall});
1016+
}}>Transfer to this device</DefaultButton>
1017+
</div>
1018+
<div className="ms-Grid-col">
1019+
<DefaultButton onClick={async () => {
1020+
const callOptions = await this.getCallOptions({video: false, micMuted: false});
1021+
const newCall = await this.callAgent.activeCallTransfer(this.state.activeCallDetails, {isTransfer: false, joinCallOptions: callOptions});
1022+
this.setState({call: newCall});
1023+
}}>Add this device</DefaultButton>
1024+
</div>
1025+
1026+
</div>
1027+
</MessageBar>
1028+
}
9891029
{
9901030
!this.state.incomingCall && !this.state.call && !this.state.callSurvey &&
9911031
<div>

0 commit comments

Comments
 (0)