|
1 | 1 | import React from "react"; |
2 | 2 | import { CallClient, LocalVideoStream, Features, CallAgentKind, VideoStreamRenderer } from '@azure/communication-calling'; |
3 | 3 | import { AzureCommunicationTokenCredential, createIdentifierFromRawId} from '@azure/communication-common'; |
4 | | -import { PrimaryButton } from '@fluentui/react/lib/Button'; |
| 4 | +import { DefaultButton, PrimaryButton } from '@fluentui/react/lib/Button'; |
5 | 5 | import { TextField } from '@fluentui/react/lib/TextField'; |
6 | 6 | import { MessageBar, MessageBarType, Toggle } from '@fluentui/react'; |
7 | 7 | import { Icon } from '@fluentui/react/lib/Icon'; |
@@ -83,7 +83,8 @@ export default class MakeCall extends React.Component { |
83 | 83 | }, |
84 | 84 | preCallDiagnosticsResults: {}, |
85 | 85 | isTeamsUser: false, |
86 | | - identityMri: undefined |
| 86 | + identityMri: undefined, |
| 87 | + activeCallDetails: undefined |
87 | 88 | }; |
88 | 89 |
|
89 | 90 | // override logger to be able to dowload logs locally |
@@ -155,6 +156,17 @@ export default class MakeCall extends React.Component { |
155 | 156 | await this.callClient.createTeamsCallAgent(tokenCredential) : |
156 | 157 | await this.callClient.createCallAgent(tokenCredential, { displayName: userDetails.displayName }); |
157 | 158 | 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 | + |
158 | 170 |
|
159 | 171 | this.callAgent.on('callsUpdated', e => { |
160 | 172 | console.log(`callsUpdated, added=${e.added}, removed=${e.removed}`); |
@@ -224,6 +236,8 @@ export default class MakeCall extends React.Component { |
224 | 236 | this.logInComponentRef.current.setCallAgent(this.callAgent); |
225 | 237 | this.logInComponentRef.current.setCallClient(this.callClient); |
226 | 238 | this.autoJoinMeetingByMeetingLink(); |
| 239 | + const activeCalls = await this.callAgent.getActiveCallDetails(); |
| 240 | + this.setState({ activeCallDetails: activeCalls.callId ? activeCalls : undefined }); |
227 | 241 | } catch (e) { |
228 | 242 | console.error(e); |
229 | 243 | } |
@@ -986,6 +1000,32 @@ this.callAgent.on('incomingCall', async (args) => { |
986 | 1000 | {this.state.ufdMessages.map((msg, index) => <li key={index}>{msg.msg}</li>)} |
987 | 1001 | </MessageBar> |
988 | 1002 | } |
| 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 | + } |
989 | 1029 | { |
990 | 1030 | !this.state.incomingCall && !this.state.call && !this.state.callSurvey && |
991 | 1031 | <div> |
|
0 commit comments