Skip to content

Commit

Permalink
Event parser updated to accomodate latest changes such as naming upda…
Browse files Browse the repository at this point in the history
…te on AddParticipantFailed
  • Loading branch information
minwoolee-msft committed Mar 7, 2023
1 parent cc4ad1a commit 208f9b8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@ import { PhoneNumberIdentifier } from '@azure/communication-common';
import { TokenCredential } from '@azure/core-auth';

// @public
export interface AddParticipantOptions extends OperationOptions {
invitationTimeoutInSeconds?: number;
export interface AddParticipantFailed {
callConnectionId?: string;
correlationId?: string;
kind: "AddParticipantFailed";
operationContext?: string;
participant?: CommunicationIdentifier;
resultInformation?: ResultInformation;
serverCallId?: string;
}

// @public
export interface AddParticipantResult {
export interface AddParticipantOptions extends OperationOptions {
invitationTimeoutInSeconds?: number;
operationContext?: string;
participant?: CallParticipant;
}

// @public
export interface AddParticipantsFailed {
callConnectionId?: string;
correlationId?: string;
kind: "AddParticipantsFailed";
export interface AddParticipantResult {
operationContext?: string;
participants?: CommunicationIdentifier[];
resultInformation?: ResultInformation;
serverCallId?: string;
participant?: CallParticipant;
}

// @public
export interface AddParticipantsSucceeded {
export interface AddParticipantSucceeded {
callConnectionId?: string;
correlationId?: string;
kind: "AddParticipantsSucceeded";
kind: "AddParticipantSucceeded";
operationContext?: string;
participants?: CommunicationIdentifier[];
participant?: CommunicationIdentifier;
resultInformation?: ResultInformation;
serverCallId?: string;
}
Expand Down Expand Up @@ -79,7 +79,7 @@ export interface CallAutomationClientOptions extends CommonClientOptions {
}

// @public
export type CallAutomationEvent = AddParticipantsSucceeded | AddParticipantsFailed | CallConnected | CallDisconnected | CallTransferAccepted | CallTransferFailed | ParticipantsUpdated | RecordingStateChanged | PlayCompleted | PlayFailed | PlayCanceled | RecognizeCompleted | RecognizeCanceled | RecognizeFailed;
export type CallAutomationEvent = AddParticipantSucceeded | AddParticipantFailed | CallConnected | CallDisconnected | CallTransferAccepted | CallTransferFailed | ParticipantsUpdated | RecordingStateChanged | PlayCompleted | PlayFailed | PlayCanceled | RecognizeCompleted | RecognizeCanceled | RecognizeFailed;

// @public
export class CallAutomationEventParser {
Expand Down Expand Up @@ -342,7 +342,7 @@ export interface ParticipantsUpdated {
callConnectionId?: string;
correlationId?: string;
kind: "ParticipantsUpdated";
participants?: CommunicationIdentifier[];
participants?: CallParticipant[];
serverCallId?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

import { createSerializer } from "@azure/core-client";

import { communicationIdentifierConverter } from "./utli/converters";
import {
communicationIdentifierConverter,
callParticipantConverter
} from "./utli/converters";

import {
CallAutomationEvent,
AddParticipantsSucceeded,
AddParticipantsFailed,
AddParticipantSucceeded,
AddParticipantFailed,
CallConnected,
CallDisconnected,
CallTransferAccepted,
Expand All @@ -24,7 +27,7 @@ import {
} from "./models/events";

import { CloudEventMapper } from "./models/mapper";
import { CommunicationIdentifierModel } from "./generated/src";
import { CallParticipantInternal } from "./generated/src";

const serializer = createSerializer();

Expand Down Expand Up @@ -56,13 +59,13 @@ export class CallAutomationEventParser {
let callbackEvent: CallAutomationEvent;
let parsed: any = data;
switch (eventType) {
case "Microsoft.Communication.AddParticipantsSucceeded":
callbackEvent = { kind: "AddParticipantsSucceeded" } as AddParticipantsSucceeded;
parsed = communicationIdentifierParserForEvent(data);
case "Microsoft.Communication.AddParticipantSucceeded":
callbackEvent = { kind: "AddParticipantSucceeded" } as AddParticipantSucceeded;
data.participant = communicationIdentifierConverter(data.participant)
break;
case "Microsoft.Communication.AddParticipantsFailed":
callbackEvent = { kind: "AddParticipantsFailed" } as AddParticipantsFailed;
parsed = communicationIdentifierParserForEvent(data);
case "Microsoft.Communication.AddParticipantFailed":
callbackEvent = { kind: "AddParticipantFailed" } as AddParticipantFailed;
data.participant = communicationIdentifierConverter(data.participant)
break;
case "Microsoft.Communication.CallConnected":
callbackEvent = { kind: "CallConnected" } as CallConnected;
Expand All @@ -78,7 +81,7 @@ export class CallAutomationEventParser {
break;
case "Microsoft.Communication.ParticipantsUpdated":
callbackEvent = { kind: "ParticipantsUpdated" } as ParticipantsUpdated;
parsed = communicationIdentifierParserForEvent(data);
parsed = participantsParserForEvent(data);
break;
case "Microsoft.Communication.RecordingStateChanged":
callbackEvent = { kind: "RecordingStateChanged" } as RecordingStateChanged;
Expand Down Expand Up @@ -134,13 +137,13 @@ function parseAndWrap(
}
}

function communicationIdentifierParserForEvent(data: any): any {
function participantsParserForEvent(data: any): any {
const { participants, ...rest } = data;
return {
...rest,
participants: participants?.map(
(participant: CommunicationIdentifierModel) =>
communicationIdentifierConverter(participant)
(participant: CallParticipantInternal) =>
callParticipantConverter(participant)
),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import {
RecognizeCompleted as RestRecognizeCompleted,
RecognizeFailed as RestRecognizeFailed,
RecognizeCanceled as RestRecognizeCanceled,
ResultInformation,
ResultInformation
} from "../generated/src/models";

import { CallParticipant } from "./models";

/** Callback events for Call Automation */
export type CallAutomationEvent =
| AddParticipantsSucceeded
| AddParticipantsFailed
| AddParticipantSucceeded
| AddParticipantFailed
| CallConnected
| CallDisconnected
| CallTransferAccepted
Expand Down Expand Up @@ -51,8 +52,8 @@ export {
ResultInformation
};

/** The participants successfully added event. */
export interface AddParticipantsSucceeded {
/** The participant successfully added event. */
export interface AddParticipantSucceeded {
/** Call connection ID. */
callConnectionId?: string;
/** Server call ID. */
Expand All @@ -63,14 +64,14 @@ export interface AddParticipantsSucceeded {
operationContext?: string;
/** Contains the resulting SIP code/sub-code and message from NGC services. */
resultInformation?: ResultInformation;
/** The list of participants in the call. */
participants?: CommunicationIdentifier[];
/** The participant in the call. */
participant?: CommunicationIdentifier;
/** kind of this event. */
kind: "AddParticipantsSucceeded";
kind: "AddParticipantSucceeded";
}

/** The failed to add participants event. */
export interface AddParticipantsFailed {
/** The failed to add participant event. */
export interface AddParticipantFailed {
/** Call connection ID. */
callConnectionId?: string;
/** Server call ID. */
Expand All @@ -81,10 +82,10 @@ export interface AddParticipantsFailed {
operationContext?: string;
/** Contains the resulting SIP code/sub-code and message from NGC services. */
resultInformation?: ResultInformation;
/** The list of participants in the call. */
participants?: CommunicationIdentifier[];
/** The participant in the call. */
participant?: CommunicationIdentifier;
/** kind of this event. */
kind: "AddParticipantsFailed";
kind: "AddParticipantFailed";
}

/** Event when call was established. */
Expand Down Expand Up @@ -120,7 +121,7 @@ export interface ParticipantsUpdated {
/** Correlation ID for event to call correlation. Also called ChainId for skype chain ID. */
correlationId?: string;
/** The list of participants in the call. */
participants?: CommunicationIdentifier[];
participants?: CallParticipant[];
/** kind of this event. */
kind: "ParticipantsUpdated";
}
Expand Down

0 comments on commit 208f9b8

Please sign in to comment.