Skip to content

Commit 156f8a2

Browse files
add active call transfer functionality
1 parent 9ba14fc commit 156f8a2

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

Project/src/MakeCall/MakeCall.js

Lines changed: 32 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,16 @@ 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+
});
168+
158169

159170
this.callAgent.on('callsUpdated', e => {
160171
console.log(`callsUpdated, added=${e.added}, removed=${e.removed}`);
@@ -986,6 +997,25 @@ this.callAgent.on('incomingCall', async (args) => {
986997
{this.state.ufdMessages.map((msg, index) => <li key={index}>{msg.msg}</li>)}
987998
</MessageBar>
988999
}
1000+
{
1001+
this.state.activeCallDetails && <MessageBar
1002+
messageBarType={MessageBarType.info}
1003+
isMultiline={true}
1004+
onDismiss={() => { this.setState({ activeCallDetails: undefined }) }}
1005+
dismissButtonAriaLabel="Close">
1006+
<div className="ms-Grid-row ml-2 mr-2">
1007+
<b>You're in an active call!</b>
1008+
<DefaultButton onClick={async () => {
1009+
const newCall = await this.callAgent.activeCallTransfer(this.state.activeCallDetails, {isTransfer: true});
1010+
this.setState({call: newCall});
1011+
}}>Transfer to this device</DefaultButton>
1012+
<DefaultButton onClick={async () => {
1013+
const newCall = await this.callAgent.activeCallTransfer(this.state.activeCallDetails, {isTransfer: false});
1014+
this.setState({call: newCall});
1015+
}}>Join here</DefaultButton>
1016+
</div>
1017+
</MessageBar>
1018+
}
9891019
{
9901020
!this.state.incomingCall && !this.state.call && !this.state.callSurvey &&
9911021
<div>

0 commit comments

Comments
 (0)