From ac16f3f2480d57bc0c064bdfd6a5b47d82b889f5 Mon Sep 17 00:00:00 2001 From: Zihan Zhang Date: Thu, 5 Aug 2021 22:17:17 -0700 Subject: [PATCH] Add CallingServer SDK project. --- common/config/rush/pnpm-lock.yaml | 55 ++ rush.json | 5 + sdk/communication/ci.yml | 2 + .../communication-callingserver/.gitignore | 1 + .../communication-callingserver/.nycrc | 10 + .../communication-callingserver/LICENSE | 21 + .../communication-callingserver/README.md | 106 +++ .../api-extractor.json | 31 + .../communication-callingserver/package.json | 152 ++++ .../review/communication-callingserver.api.md | 98 +++ .../rollup.base.config.js | 146 ++++ .../rollup.config.js | 13 + .../rollup.test.config.js | 3 + .../samples-dev/simpleSetUp.ts | 36 + .../src/callConnection.ts | 46 + .../src/callingServerClient.ts | 184 ++++ .../src/constants.ts | 4 + .../generated/src/callingServerApiClient.ts | 30 + .../src/callingServerApiClientContext.ts | 54 ++ .../src/generated/src/index.ts | 11 + .../src/generated/src/models/index.ts | 557 ++++++++++++ .../src/generated/src/models/mappers.ts | 794 ++++++++++++++++++ .../src/generated/src/models/parameters.ts | 143 ++++ .../src/operations/callConnections.ts | 367 ++++++++ .../src/generated/src/operations/index.ts | 10 + .../generated/src/operations/serverCalls.ts | 550 ++++++++++++ .../communication-callingserver/src/index.ts | 6 + .../communication-callingserver/src/logger.ts | 6 + .../communication-callingserver/src/models.ts | 61 ++ .../src/serverCall.ts | 66 ++ .../src/tracing.ts | 13 + .../communication-callingserver/src/uuid.ts | 12 + .../swagger/README.md | 23 + .../test/README.md | 19 + .../test/public/utils/mockHttpClients.ts | 24 + .../communication-callingserver/tsconfig.json | 11 + 36 files changed, 3670 insertions(+) create mode 100644 sdk/communication/communication-callingserver/.gitignore create mode 100644 sdk/communication/communication-callingserver/.nycrc create mode 100644 sdk/communication/communication-callingserver/LICENSE create mode 100644 sdk/communication/communication-callingserver/README.md create mode 100644 sdk/communication/communication-callingserver/api-extractor.json create mode 100644 sdk/communication/communication-callingserver/package.json create mode 100644 sdk/communication/communication-callingserver/review/communication-callingserver.api.md create mode 100644 sdk/communication/communication-callingserver/rollup.base.config.js create mode 100644 sdk/communication/communication-callingserver/rollup.config.js create mode 100644 sdk/communication/communication-callingserver/rollup.test.config.js create mode 100644 sdk/communication/communication-callingserver/samples-dev/simpleSetUp.ts create mode 100644 sdk/communication/communication-callingserver/src/callConnection.ts create mode 100644 sdk/communication/communication-callingserver/src/callingServerClient.ts create mode 100644 sdk/communication/communication-callingserver/src/constants.ts create mode 100644 sdk/communication/communication-callingserver/src/generated/src/callingServerApiClient.ts create mode 100644 sdk/communication/communication-callingserver/src/generated/src/callingServerApiClientContext.ts create mode 100644 sdk/communication/communication-callingserver/src/generated/src/index.ts create mode 100644 sdk/communication/communication-callingserver/src/generated/src/models/index.ts create mode 100644 sdk/communication/communication-callingserver/src/generated/src/models/mappers.ts create mode 100644 sdk/communication/communication-callingserver/src/generated/src/models/parameters.ts create mode 100644 sdk/communication/communication-callingserver/src/generated/src/operations/callConnections.ts create mode 100644 sdk/communication/communication-callingserver/src/generated/src/operations/index.ts create mode 100644 sdk/communication/communication-callingserver/src/generated/src/operations/serverCalls.ts create mode 100644 sdk/communication/communication-callingserver/src/index.ts create mode 100644 sdk/communication/communication-callingserver/src/logger.ts create mode 100644 sdk/communication/communication-callingserver/src/models.ts create mode 100644 sdk/communication/communication-callingserver/src/serverCall.ts create mode 100644 sdk/communication/communication-callingserver/src/tracing.ts create mode 100644 sdk/communication/communication-callingserver/src/uuid.ts create mode 100644 sdk/communication/communication-callingserver/swagger/README.md create mode 100644 sdk/communication/communication-callingserver/test/README.md create mode 100644 sdk/communication/communication-callingserver/test/public/utils/mockHttpClients.ts create mode 100644 sdk/communication/communication-callingserver/tsconfig.json diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 9c3b306cb1f0..c37f988311c2 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -18,6 +18,7 @@ dependencies: '@rush-temp/arm-storage': file:projects/arm-storage.tgz '@rush-temp/arm-webpubsub': file:projects/arm-webpubsub.tgz '@rush-temp/attestation': file:projects/attestation.tgz + '@rush-temp/communication-callingserver': file:projects/communication-callingserver.tgz '@rush-temp/communication-chat': file:projects/communication-chat.tgz '@rush-temp/communication-common': file:projects/communication-common.tgz '@rush-temp/communication-identity': file:projects/communication-identity.tgz @@ -8857,6 +8858,59 @@ packages: integrity: sha512-SMEs3He6zgbcQEmu1zXcG2Id88IkSCyR1hNRF7Xk/EdHk+BxeXlXL5AxGPC+MANwG28tjvPnSHhxbcxh1ZzuBA== tarball: file:projects/attestation.tgz version: 0.0.0 + file:projects/communication-callingserver.tgz: + dependencies: + '@azure/communication-identity': 1.0.0 + '@azure/core-tracing': 1.0.0-preview.13 + '@microsoft/api-extractor': 7.7.11 + '@rollup/plugin-commonjs': 11.0.2_rollup@1.32.1 + '@rollup/plugin-json': 4.1.0_rollup@1.32.1 + '@rollup/plugin-multi-entry': 3.0.1_rollup@1.32.1 + '@rollup/plugin-node-resolve': 8.4.0_rollup@1.32.1 + '@rollup/plugin-replace': 2.4.2_rollup@1.32.1 + '@types/chai': 4.2.21 + '@types/mocha': 7.0.2 + '@types/node': 12.20.16 + '@types/sinon': 9.0.11 + assert: 1.5.0 + chai: 4.3.4 + cross-env: 7.0.3 + dotenv: 8.6.0 + eslint: 7.31.0 + events: 3.3.0 + inherits: 2.0.4 + karma: 6.3.4 + karma-chrome-launcher: 3.1.0 + karma-coverage: 2.0.3 + karma-edge-launcher: 0.4.2_karma@6.3.4 + karma-env-preprocessor: 0.1.1 + karma-firefox-launcher: 1.3.0 + karma-ie-launcher: 1.0.0_karma@6.3.4 + karma-junit-reporter: 2.0.1_karma@6.3.4 + karma-mocha: 2.0.1 + karma-mocha-reporter: 2.2.5_karma@6.3.4 + karma-sourcemap-loader: 0.3.8 + mocha: 7.2.0 + mocha-junit-reporter: 1.23.3_mocha@7.2.0 + nyc: 14.1.1 + prettier: 1.19.1 + rimraf: 3.0.2 + rollup: 1.32.1 + rollup-plugin-shim: 1.0.0 + rollup-plugin-sourcemaps: 0.4.2_rollup@1.32.1 + rollup-plugin-terser: 5.3.1_rollup@1.32.1 + rollup-plugin-visualizer: 4.2.2_rollup@1.32.1 + sinon: 9.2.4 + tslib: 2.3.0 + typedoc: 0.15.2 + typescript: 4.2.4 + util: 0.12.4 + dev: false + name: '@rush-temp/communication-callingserver' + resolution: + integrity: sha512-R1QQQ4GiDO6EQYjLIRZ3RwlmNrFzk2OS36IhHQSiKkdDUCTSxMonR1K8os6sBfC7q7gPBPSVTqQSlm1WS0iBhQ== + tarball: file:projects/communication-callingserver.tgz + version: 0.0.0 file:projects/communication-chat.tgz: dependencies: '@azure/communication-identity': 1.0.0 @@ -12478,6 +12532,7 @@ specifiers: '@rush-temp/arm-storage': file:./projects/arm-storage.tgz '@rush-temp/arm-webpubsub': file:./projects/arm-webpubsub.tgz '@rush-temp/attestation': file:./projects/attestation.tgz + '@rush-temp/communication-callingserver': file:./projects/communication-callingserver.tgz '@rush-temp/communication-chat': file:./projects/communication-chat.tgz '@rush-temp/communication-common': file:./projects/communication-common.tgz '@rush-temp/communication-identity': file:./projects/communication-identity.tgz diff --git a/rush.json b/rush.json index 7c1156bd5052..247898640b0a 100644 --- a/rush.json +++ b/rush.json @@ -391,6 +391,11 @@ "projectFolder": "sdk/quantum/quantum-jobs", "versionPolicyName": "client" }, + { + "packageName": "@azure/communication-callingserver", + "projectFolder": "sdk/communication/communication-callingserver", + "versionPolicyName": "client" + }, { "packageName": "@azure/communication-chat", "projectFolder": "sdk/communication/communication-chat", diff --git a/sdk/communication/ci.yml b/sdk/communication/ci.yml index 0a47278faf45..be39c0a2b16d 100644 --- a/sdk/communication/ci.yml +++ b/sdk/communication/ci.yml @@ -26,6 +26,8 @@ extends: parameters: ServiceDirectory: communication Artifacts: + - name: azure-communication-callingserver + safeName: azurecommunicationcallingserver - name: azure-communication-common safeName: azurecommunicationcommon - name: azure-communication-sms diff --git a/sdk/communication/communication-callingserver/.gitignore b/sdk/communication/communication-callingserver/.gitignore new file mode 100644 index 000000000000..e35e6c4bbeb0 --- /dev/null +++ b/sdk/communication/communication-callingserver/.gitignore @@ -0,0 +1 @@ +/**/code-model-v* \ No newline at end of file diff --git a/sdk/communication/communication-callingserver/.nycrc b/sdk/communication/communication-callingserver/.nycrc new file mode 100644 index 000000000000..29174b423579 --- /dev/null +++ b/sdk/communication/communication-callingserver/.nycrc @@ -0,0 +1,10 @@ +{ + "include": ["dist-esm/src/**/*.js"], + "exclude": ["**/*.d.ts", "dist-esm/src/generated/*"], + "reporter": ["text-summary", "html", "cobertura"], + "exclude-after-remap": false, + "sourceMap": true, + "produce-source-map": true, + "instrument": true, + "all": true +} diff --git a/sdk/communication/communication-callingserver/LICENSE b/sdk/communication/communication-callingserver/LICENSE new file mode 100644 index 000000000000..ea8fb1516028 --- /dev/null +++ b/sdk/communication/communication-callingserver/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/sdk/communication/communication-callingserver/README.md b/sdk/communication/communication-callingserver/README.md new file mode 100644 index 000000000000..8d45a043a84d --- /dev/null +++ b/sdk/communication/communication-callingserver/README.md @@ -0,0 +1,106 @@ +# Azure Communication CallingServer client library for JavaScript + +This package contains a JavaScript SDK for Azure Communication Services for CallingServer. +Read more about Azure Communication Services [here](https://docs.microsoft.com/azure/communication-services/overview) + +[Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-callingserver) + +## Getting started + +### Prerequisites + +- An [Azure subscription][azure_sub]. +- An existing Communication Services resource. If you need to create the resource, you can use the [Azure Portal][azure_portal], the [Azure PowerShell][azure_powershell], or the [Azure CLI][azure_cli]. + +- A deployed Communication Services resource. You can use the [Azure Portal](https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp) or the [Azure PowerShell](https://docs.microsoft.com/powershell/module/az.communication/new-azcommunicationservice) to set it up. +- You must have a phone number configured that is associated with an Azure subscription + +### Installing +```bash +npm install @azure/communication-callingserver +``` + +### Browser support + +#### JavaScript Bundle + +To use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling). +In `rollup.config.js`, add following customized name exports in `cjs` plugin. + +```JavaScript + +cjs({ + namedExports: { + events: ["EventEmitter"], + "@azure/communication-signaling": ["CommunicationSignalingClient", "SignalingClient"], + "@opentelemetry/api": ["CanonicalCode", "SpanKind", "TraceFlags"] + } +}) + +``` + +## Key concepts + +`CallingServerClient` provides the functionality to make call connection, join call connection or initialize a server call. + +## Examples + +The following section provides several code snippets covering some of the most common Azure Communication Services tasks, including: + +- [Client Initialization](#client-initialization) +- [Make a call to a phone number recipient](#make-a-call-to-a-phone-number-recipient) + +### Client Initialization + +To initialize the CallingServer Client, the connection string can be used to instantiate. + +```typescript +import { CallingServerClient } from "@azure/communication-callingserver"; + +const connectionString = `endpoint=https://.communication.azure.com/;accessKey=`; +const client = new CallingServerClient(connectionString); +``` + +### Make a call to a phone number recipient + +Once the client is initialized, the `createCallConnection` method can be invoked: + +```typescript +import { CreateCallOptions } from "@azure/communication-callingserver"; + +const createCallResponse = callingserver_client.createCallConnection( + source="", + targets="", + createCallOptions=Something +); + +``` + +- `from_`: Something. +- `to`: Something. +- `createCallOptions`: Something. + +## Troubleshooting + +Running into issues? This section should contain details as to what to do there. + +## Next steps + +More sample code should go [here](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/communication/azure-communication-callingserver/samples), along with links out to the appropriate example tests. + +## Provide Feedback + +If you encounter any bugs or have suggestions, please file an issue in the [Issues](https://github.com/Azure/azure-sdk-for-js/issues) section of the project + +## Contributing + +This project welcomes contributions and suggestions. Most contributions require you to agree to a +Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com. + +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the +PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + + diff --git a/sdk/communication/communication-callingserver/api-extractor.json b/sdk/communication/communication-callingserver/api-extractor.json new file mode 100644 index 000000000000..c479b032b1a4 --- /dev/null +++ b/sdk/communication/communication-callingserver/api-extractor.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + "mainEntryPointFilePath": "types/src/index.d.ts", + "docModel": { + "enabled": true + }, + "apiReport": { + "enabled": true, + "reportFolder": "./review" + }, + "dtsRollup": { + "enabled": true, + "untrimmedFilePath": "", + "publicTrimmedFilePath": "./types/communication-callingserver.d.ts" + }, + "messages": { + "tsdocMessageReporting": { + "default": { + "logLevel": "none" + } + }, + "extractorMessageReporting": { + "ae-missing-release-tag": { + "logLevel": "none" + }, + "ae-unresolved-link": { + "logLevel": "none" + } + } + } +} diff --git a/sdk/communication/communication-callingserver/package.json b/sdk/communication/communication-callingserver/package.json new file mode 100644 index 000000000000..213b15511b9e --- /dev/null +++ b/sdk/communication/communication-callingserver/package.json @@ -0,0 +1,152 @@ +{ + "name": "@azure/communication-callingserver", + "version": "1.0.0-beta.1", + "description": "SDK for Azure Communication CallingServer service.", + "sdk-type": "client", + "main": "dist/index.js", + "module": "dist-esm/src/index.js", + "browser": { + "stream": "./node_modules/stream-browserify/index.js", + "./dist-esm/src/credentials/cryptoUtils.js": "./dist-esm/src/credentials/cryptoUtils.browser.js" + }, + "types": "types/communication-callingserver.d.ts", + "scripts": { + "audit": "node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit", + "build:autorest": "autorest ./swagger/README.md --typescript --v3 && rushx format", + "build:browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1", + "build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", + "build:samples": "dev-tool samples publish --force", + "build:test": "tsc -p . && rollup -c rollup.test.config.js 2>&1", + "build": "tsc -p . && rollup -c 2>&1 && api-extractor run --local", + "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", + "clean": "rimraf dist dist-* temp types *.tgz *.log", + "execute:samples": "dev-tool samples run samples-dev", + "extract-api": "tsc -p . && api-extractor run --local", + "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", + "integration-test:browser": "karma start --single-run", + "integration-test:node": "nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000 \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"", + "integration-test": "npm run integration-test:node && npm run integration-test:browser", + "lint:fix": "eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]", + "lint": "eslint package.json api-extractor.json src test --ext .ts", + "pack": "npm pack 2>&1", + "prebuild": "npm run clean", + "test:browser": "npm run build:test && npm run unit-test:browser && npm run integration-test:browser", + "test:node": "npm run build:test && npm run unit-test:node && npm run integration-test:node", + "test": "npm run build:test && npm run unit-test && npm run integration-test", + "unit-test:browser": "karma start --single-run", + "unit-test:node": "mocha --reporter ../../../common/tools/mocha-multi-reporter.js dist-test/index.node.js", + "unit-test": "npm run unit-test:node && npm run unit-test:browser", + "docs": "typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src" + }, + "files": [ + "dist/", + "dist-esm/src", + "types/communication-callingserver.d.ts", + "README.md", + "LICENSE" + ], + "repository": "github:Azure/azure-sdk-for-js", + "keywords": [ + "azure", + "cloud", + "Azure", + "communication", + "callingserver" + ], + "author": "Microsoft Corporation", + "license": "MIT", + "bugs": { + "url": "https://github.com/Azure/azure-sdk-for-js/issues" + }, + "engines": { + "node": ">=12.0.0" + }, + "homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-callingserver/", + "sideEffects": false, + "prettier": "@azure/eslint-plugin-azure-sdk/prettier.json", + "dependencies": { + "@azure/abort-controller": "^1.0.0", + "@azure/communication-common": "^1.1.0", + "@azure/core-auth": "^1.3.0", + "@azure/core-http": "^2.0.0", + "@azure/core-tracing": "1.0.0-preview.13", + "@azure/logger": "^1.0.0", + "events": "^3.0.0", + "tslib": "^2.2.0" + }, + "devDependencies": { + "@azure/communication-identity": "^1.0.0", + "@azure/dev-tool": "^1.0.0", + "@azure/eslint-plugin-azure-sdk": "^3.0.0", + "@azure/identity": "2.0.0-beta.5", + "@azure/test-utils": "^1.0.0", + "@azure/test-utils-recorder": "^1.0.0", + "@microsoft/api-extractor": "7.7.11", + "@rollup/plugin-commonjs": "11.0.2", + "@rollup/plugin-json": "^4.0.0", + "@rollup/plugin-multi-entry": "^3.0.0", + "@rollup/plugin-node-resolve": "^8.0.0", + "@rollup/plugin-replace": "^2.2.0", + "@types/chai": "^4.1.6", + "@types/mocha": "^7.0.2", + "@types/node": "^12.0.0", + "@types/sinon": "^9.0.4", + "assert": "^1.4.1", + "chai": "^4.2.0", + "cross-env": "^7.0.2", + "dotenv": "^8.2.0", + "eslint": "^7.15.0", + "inherits": "^2.0.3", + "karma-chrome-launcher": "^3.0.0", + "karma-coverage": "^2.0.0", + "karma-edge-launcher": "^0.4.2", + "karma-env-preprocessor": "^0.1.1", + "karma-firefox-launcher": "^1.1.0", + "karma-ie-launcher": "^1.0.0", + "karma-junit-reporter": "^2.0.1", + "karma-mocha-reporter": "^2.2.5", + "karma-mocha": "^2.0.1", + "karma-sourcemap-loader": "^0.3.8", + "karma": "^6.2.0", + "mocha-junit-reporter": "^1.18.0", + "mocha": "^7.1.1", + "nyc": "^14.0.0", + "prettier": "^1.16.4", + "rimraf": "^3.0.0", + "rollup-plugin-sourcemaps": "^0.4.2", + "rollup-plugin-terser": "^5.1.1", + "rollup-plugin-visualizer": "^4.0.4", + "rollup-plugin-shim": "^1.0.0", + "rollup": "^1.16.3", + "sinon": "^9.0.2", + "typescript": "~4.2.0", + "util": "^0.12.1", + "typedoc": "0.15.2" + }, + "//metadata": { + "constantPaths": [ + { + "path": "src/generated/src/callingserverApiClientContext.ts", + "prefix": "packageVersion" + }, + { + "path": "src/constants.ts", + "prefix": "SDK_VERSION" + }, + { + "path": "swagger/README.md", + "prefix": "package-version" + } + ] + }, + "//sampleConfiguration": { + "productName": "Azure Communication Services - CallingServer", + "productSlugs": [ + "azure", + "azure-communication-services" + ], + "requiredResources": { + "Azure Communication Services account": "https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource" + } + } +} diff --git a/sdk/communication/communication-callingserver/review/communication-callingserver.api.md b/sdk/communication/communication-callingserver/review/communication-callingserver.api.md new file mode 100644 index 000000000000..62cb20405474 --- /dev/null +++ b/sdk/communication/communication-callingserver/review/communication-callingserver.api.md @@ -0,0 +1,98 @@ +## API Report File for "@azure/communication-callingserver" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +import { CommunicationIdentifier } from '@azure/communication-common'; +import * as coreHttp from '@azure/core-http'; +import { OperationOptions } from '@azure/core-http'; +import { PhoneNumberIdentifier } from '@azure/communication-common'; +import { PipelineOptions } from '@azure/core-http'; + +// @public +export class CallConnection { + // Warning: (ae-forgotten-export) The symbol "CallConnections" needs to be exported by the entry point index.d.ts + constructor(callConnectionId: string, callConnectionRestClient: CallConnections); + // (undocumented) + hangUp(options?: HangUpOptions): Promise; +} + +// @public +export class CallingServerClient { + constructor(connectionString: string, options?: CallingServerClientOptions); + // (undocumented) + createCallConnection(source: CommunicationIdentifier, targets: CommunicationIdentifier[], options: CreateCallConnectionOptions): Promise; + // (undocumented) + getCallConnection(callConnectionId: string): CallConnection; + // (undocumented) + initializeServerCall(serverCallId: string): ServerCall; + // (undocumented) + joinCall(serverCallId: string, source: CommunicationIdentifier, options: JoinCallOptions): Promise; + } + +// @public +export interface CallingServerClientOptions extends PipelineOptions { +} + +// @public +export interface CreateCallConnectionOptions extends OperationOptions { + alternateCallerId?: PhoneNumberIdentifier; + callbackUri: string; + requestedCallEvents: EventSubscriptionType[]; + requestedMediaTypes: MediaType[]; + subject?: string; +} + +// @public +export const enum EventSubscriptionType { + // (undocumented) + DtmfReceived = "dtmfReceived", + // (undocumented) + ParticipantsUpdated = "participantsUpdated" +} + +// @public +export type HangUpOptions = OperationOptions; + +// @public +export interface JoinCallOptions extends OperationOptions { + callbackUri: string; + requestedCallEvents?: EventSubscriptionType[]; + requestedMediaTypes?: MediaType[]; + subject?: string; +} + +// @public +export const enum MediaType { + // (undocumented) + Audio = "audio", + // (undocumented) + Video = "video" +} + +// @public +export type PlayAudioOptions = OperationOptions; + +// @public +export interface PlayAudioResult { + operationContext?: string; + operationId?: string; + // Warning: (ae-forgotten-export) The symbol "ResultInfo" needs to be exported by the entry point index.d.ts + resultInfo?: ResultInfo; + // Warning: (ae-forgotten-export) The symbol "OperationStatus" needs to be exported by the entry point index.d.ts + status: OperationStatus; +} + +// @public +export class ServerCall { + // Warning: (ae-forgotten-export) The symbol "ServerCalls" needs to be exported by the entry point index.d.ts + constructor(serverCallId: string, serverCallRestClient: ServerCalls); + // (undocumented) + playAudio(audioFileUri: string, audioFileId: string, callbackUri: string, operationContext?: string, options?: PlayAudioOptions): Promise; + } + + +// (No @packageDocumentation comment for this package) + +``` diff --git a/sdk/communication/communication-callingserver/rollup.base.config.js b/sdk/communication/communication-callingserver/rollup.base.config.js new file mode 100644 index 000000000000..e320c930e6a2 --- /dev/null +++ b/sdk/communication/communication-callingserver/rollup.base.config.js @@ -0,0 +1,146 @@ +import path from "path"; +import nodeResolve from "@rollup/plugin-node-resolve"; +import multiEntry from "@rollup/plugin-multi-entry"; +import cjs from "@rollup/plugin-commonjs"; +import json from "@rollup/plugin-json"; +import replace from "@rollup/plugin-replace"; +import { terser } from "rollup-plugin-terser"; +import sourcemaps from "rollup-plugin-sourcemaps"; +import viz from "rollup-plugin-visualizer"; +import shim from "rollup-plugin-shim"; +import { openTelemetryCommonJs } from "@azure/dev-tool/shared-config/rollup"; + +const pkg = require("./package.json"); +const depNames = Object.keys(pkg.dependencies); +const devDepNames = Object.keys(pkg.devDependencies); +const input = "dist-esm/src/index.js"; +const production = process.env.NODE_ENV === "production"; + +export function nodeConfig(test = false) { + const externalNodeBuiltins = ["events", "crypto"]; + const baseConfig = { + input: input, + external: depNames.concat(externalNodeBuiltins), + output: { file: "dist/index.js", format: "cjs", sourcemap: true }, + preserveSymlinks: false, + plugins: [ + sourcemaps(), + replace({ + delimiters: ["", ""], + values: { + // replace dynamic checks with if (true) since this is for node only. + // Allows rollup's dead code elimination to be more aggressive. + "if (isNode)": "if (true)" + } + }), + nodeResolve({ preferBuiltins: true }), + json(), + cjs() + ] + }; + + if (test) { + // Entry points - test files under the `test` folder(common for both browser and node), node specific test files + baseConfig.input = [ + "dist-esm/test/public/*.spec.js", + "dist-esm/test/internal/*.spec.js", + "dist-esm/test/public/node/*.spec.js", + "dist-esm/test/internal/node/*.spec.js" + ]; + baseConfig.plugins.unshift(multiEntry({ exports: false })); + + // different output file + baseConfig.output.file = "dist-test/index.node.js"; + + // mark assert as external + baseConfig.external.push("assert", ...devDepNames); + + // Disable tree-shaking of test code. In rollup-plugin-node-resolve@5.0.0, rollup started respecting + // the "sideEffects" field in package.json. Since our package.json sets "sideEffects=false", this also + // applies to test code, which causes all tests to be removed by tree-shaking. + baseConfig.treeshake = false; + } else if (production) { + baseConfig.plugins.push(terser()); + } + + return baseConfig; +} + +export function browserConfig(test = false) { + const baseConfig = { + input: input, + external: ["crypto", "fs-extra"], + output: { + file: "dist-browser/azure-communication-callingserver.js", + format: "umd", + name: "Azure.Communication.CallingServer", + sourcemap: true, + globals: { "@azure/core-http": "Azure.Core.HTTP" } + }, + preserveSymlinks: false, + plugins: [ + sourcemaps(), + replace({ + delimiters: ["", ""], + values: { + // replace dynamic checks with if (false) since this is for + // browser only. Rollup's dead code elimination will remove + // any code guarded by if (isNode) { ... } + "if (isNode)": "if (false)" + } + }), + shim({ + constants: `export default {}`, + fs: `export default {}`, + os: `export default {}`, + dotenv: `export function config() { }`, + path: `export default {}` + }), + nodeResolve({ + mainFields: ["module", "browser"], + preferBuiltins: false + }), + json(), + cjs({ + namedExports: { + chai: ["assert"], + events: ["EventEmitter"], + "@azure/communication-signaling": ["CommunicationSignalingClient", "SignalingClient"], + ...openTelemetryCommonJs() + } + }), + viz({ filename: "dist-browser/browser-stats.html", sourcemap: false }) + ] + }; + + if (test) { + // Entry points - test files under the `test` folder(common for both browser and node), browser specific test files + baseConfig.input = [ + "dist-esm/test/public/*.spec.js", + "dist-esm/test/internal/*.spec.js", + "dist-esm/test/public/browser/*.spec.js", + "dist-esm/test/internal/browser/*.spec.js" + ]; + baseConfig.plugins.unshift(multiEntry({ exports: false })); + baseConfig.output.file = "dist-test/index.browser.js"; + + baseConfig.onwarn = (warning) => { + if ( + warning.code === "CIRCULAR_DEPENDENCY" && + warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0) + ) { + // Chai contains circular references, but they are not fatal and can be ignored. + return; + } + + console.error(`(!) ${warning.message}`); + }; + + // Disable tree-shaking of test code. In rollup-plugin-node-resolve@5.0.0, rollup started respecting + // the "sideEffects" field in package.json. Since our package.json sets "sideEffects=false", this also + // applies to test code, which causes all tests to be removed by tree-shaking. + baseConfig.treeshake = false; + } + + return baseConfig; +} diff --git a/sdk/communication/communication-callingserver/rollup.config.js b/sdk/communication/communication-callingserver/rollup.config.js new file mode 100644 index 000000000000..14652aa67ed8 --- /dev/null +++ b/sdk/communication/communication-callingserver/rollup.config.js @@ -0,0 +1,13 @@ +import * as base from "./rollup.base.config"; + +const inputs = []; + +if (!process.env.ONLY_BROWSER) { + inputs.push(base.nodeConfig()); +} + +if (!process.env.ONLY_NODE) { + inputs.push(base.browserConfig()); +} + +export default inputs; diff --git a/sdk/communication/communication-callingserver/rollup.test.config.js b/sdk/communication/communication-callingserver/rollup.test.config.js new file mode 100644 index 000000000000..925a4421a53e --- /dev/null +++ b/sdk/communication/communication-callingserver/rollup.test.config.js @@ -0,0 +1,3 @@ +import * as base from "./rollup.base.config"; + +export default [base.nodeConfig(true), base.browserConfig(true)]; diff --git a/sdk/communication/communication-callingserver/samples-dev/simpleSetUp.ts b/sdk/communication/communication-callingserver/samples-dev/simpleSetUp.ts new file mode 100644 index 000000000000..0cab22df2247 --- /dev/null +++ b/sdk/communication/communication-callingserver/samples-dev/simpleSetUp.ts @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * @summary Issue a new Relay configuration + */ + +import { CallingServerClient } from "@azure/communication-callingserver"; + +// Load the .env file if it exists +import * as dotenv from "dotenv"; +dotenv.config(); + +// You will need to set this environment variables or edit the following values +const connectionString = + process.env["COMMUNICATION_CONNECTION_STRING"] || ""; + +export async function main() { + console.log("\n== Get Relay configuration Sample ==\n"); + + // Create user + console.log("Creating User"); + + const client = new CallingServerClient(connectionString); + console.log("Getting relay configuration"); + + const config = await client.getCallConnection("test"); + console.log("RelayConfig", config); +} + +main().catch((error) => { + console.error("Encountered an error while issuing relay configuration: "); + console.error("Request: \n", error.request); + console.error("\nResponse: \n", error.response); + console.error(error); +}); diff --git a/sdk/communication/communication-callingserver/src/callConnection.ts b/sdk/communication/communication-callingserver/src/callConnection.ts new file mode 100644 index 000000000000..f48766abc366 --- /dev/null +++ b/sdk/communication/communication-callingserver/src/callConnection.ts @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +/// + +import { CallConnections } from "./generated/src/operations"; +import { HangUpOptions } from "./models"; +import { createSpan } from "./tracing"; +import { + operationOptionsToRequestOptionsBase +} from "@azure/core-http"; +import { SpanStatusCode } from "@azure/core-tracing"; + +/** + * The client to do call connection operations + */ +export class CallConnection { + private readonly callConnectionId: string; + private readonly callConnectionRestClient: CallConnections; + + constructor( + callConnectionId: string, + callConnectionRestClient: CallConnections, + ) { + this.callConnectionId = callConnectionId; + this.callConnectionRestClient = callConnectionRestClient; + } + + public async hangUp(options: HangUpOptions = {}): Promise { + const { span, updatedOptions } = createSpan("CallConnectionRestClient-HangUp", options); + + try { + await this.callConnectionRestClient.hangupCall( + this.callConnectionId, + operationOptionsToRequestOptionsBase(updatedOptions) + ); + } catch (e) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: e.message + }); + throw e; + } finally { + span.end(); + } + } +} diff --git a/sdk/communication/communication-callingserver/src/callingServerClient.ts b/sdk/communication/communication-callingserver/src/callingServerClient.ts new file mode 100644 index 000000000000..25a5d42d1c1b --- /dev/null +++ b/sdk/communication/communication-callingserver/src/callingServerClient.ts @@ -0,0 +1,184 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +/// + +import { CallConnection } from "."; +import { ServerCall } from "."; +import { CreateCallConnectionOptions, JoinCallOptions } from "./models"; +import { CallConnections, ServerCalls } from "./generated/src/operations"; +import { CreateCallRequest, JoinCallRequest } from "./generated/src/models"; + +import { + CommunicationIdentifier, + serializeCommunicationIdentifier +} from "@azure/communication-common"; + +import { + parseClientArguments, + isKeyCredential, + createCommunicationAuthPolicy +} from "@azure/communication-common"; +import { + PipelineOptions, + InternalPipelineOptions, + createPipelineFromOptions, + operationOptionsToRequestOptionsBase +} from "@azure/core-http"; +import { SpanStatusCode } from "@azure/core-tracing"; +import { CallingServerApiClient } from "./generated/src/callingServerApiClient"; +import { SDK_VERSION } from "./constants"; +import { createSpan } from "./tracing"; +import { logger } from "./logger"; + +/** + * Client options used to configure CallingServer Client API requests. + */ + export interface CallingServerClientOptions extends PipelineOptions {} + + + /** + * Checks whether the type of a value is CallingServerClientOptions or not. + * + * @param options - The value being checked. + */ +const isCallingServerClientOptions = (options: any): options is CallingServerClientOptions => +!!options && !isKeyCredential(options); + +/** + * A CallingServerClient represents a Client to the Azure Communication CallingServer service. + */ +export class CallingServerClient { + private readonly callingServerServiceClient: CallingServerApiClient; + private readonly callConnectionRestClient: CallConnections; + private readonly serverCallRestClient: ServerCalls; + + /** + * Initializes a new instance of the CallingServerClient class. + * @param connectionString - Connection string to connect to an Azure Communication Service resource. + * Example: "endpoint=https://contoso.eastus.communications.azure.net/;accesskey=secret"; + * @param options - Optional. Options to configure the HTTP pipeline. + */ + constructor(connectionString: string, options?: CallingServerClientOptions); + + constructor( + connectionString: string, + options?: CallingServerClientOptions, + maybeOptions: CallingServerClientOptions = {} + ) { + const { url, credential } = parseClientArguments(connectionString, options); + options = isCallingServerClientOptions(options) ? options : maybeOptions; + + const libInfo = `azsdk-js-communication-callingserver/${SDK_VERSION}`; + + if (!options?.userAgentOptions) { + options.userAgentOptions = {}; + } + + if (options?.userAgentOptions?.userAgentPrefix) { + options.userAgentOptions.userAgentPrefix = `${options.userAgentOptions.userAgentPrefix} ${libInfo}`; + } else { + options.userAgentOptions.userAgentPrefix = libInfo; + } + + const internalPipelineOptions: InternalPipelineOptions = { + ...options, + ...{ + loggingOptions: { + logger: logger.info + } + } + }; + + const authPolicy = createCommunicationAuthPolicy(credential); + const pipeline = createPipelineFromOptions(internalPipelineOptions, authPolicy); + this.callingServerServiceClient = new CallingServerApiClient(url, pipeline); + this.callConnectionRestClient = this.callingServerServiceClient.callConnections; + this.serverCallRestClient = this.callingServerServiceClient.serverCalls; + } + + public getCallConnection(callConnectionId: string): CallConnection { + return new CallConnection(callConnectionId, this.callConnectionRestClient); + } + + public initializeServerCall(serverCallId: string): ServerCall { + return new ServerCall(serverCallId, this.serverCallRestClient); + } + + public async createCallConnection( + source: CommunicationIdentifier, + targets: CommunicationIdentifier[], + options: CreateCallConnectionOptions + ): Promise { + const { span, updatedOptions } = createSpan("CallConnectionRestClient-CreateCallConnection", options); + + const request: CreateCallRequest = { + source: serializeCommunicationIdentifier(source), + targets: targets.map(m => serializeCommunicationIdentifier(m)), + callbackUri: options.callbackUri, + requestedMediaTypes: options.requestedMediaTypes, + requestedCallEvents: options.requestedCallEvents, + alternateCallerId: options.alternateCallerId == null ? undefined : {value: options.alternateCallerId.phoneNumber}, + subject: options.subject + }; + + try { + const response = await this.callConnectionRestClient.createCall( + request, + operationOptionsToRequestOptionsBase(updatedOptions) + ); + + if (response.callConnectionId) { + return new CallConnection(response.callConnectionId, this.callConnectionRestClient); + } else { + throw 'callConnectionId is missing in createCall response'; + } + } catch (e) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: e.message + }); + throw e; + } finally { + span.end(); + } + } + + public async joinCall( + serverCallId: string, + source: CommunicationIdentifier, + options: JoinCallOptions, + ): Promise { + const { span, updatedOptions } = createSpan("ServerCallRestClient-JoinCall", options); + + const request: JoinCallRequest = { + source: serializeCommunicationIdentifier(source), + callbackUri: options.callbackUri, + requestedMediaTypes: options.requestedMediaTypes, + requestedCallEvents: options.requestedCallEvents, + subject: undefined + }; + + + try { + const response = await this.serverCallRestClient.joinCall( + serverCallId, + request, + operationOptionsToRequestOptionsBase(updatedOptions) + ); + + if (response.callConnectionId) { + return new CallConnection(response.callConnectionId, this.callConnectionRestClient); + } else { + throw 'callConnectionId is missing in joinCall response'; + } + } catch (e) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: e.message + }); + throw e; + } finally { + span.end(); + } + } +} diff --git a/sdk/communication/communication-callingserver/src/constants.ts b/sdk/communication/communication-callingserver/src/constants.ts new file mode 100644 index 000000000000..47dc16dd0f7c --- /dev/null +++ b/sdk/communication/communication-callingserver/src/constants.ts @@ -0,0 +1,4 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +export const SDK_VERSION: string = "1.0.0-beta.1"; diff --git a/sdk/communication/communication-callingserver/src/generated/src/callingServerApiClient.ts b/sdk/communication/communication-callingserver/src/generated/src/callingServerApiClient.ts new file mode 100644 index 000000000000..24ee49683594 --- /dev/null +++ b/sdk/communication/communication-callingserver/src/generated/src/callingServerApiClient.ts @@ -0,0 +1,30 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { CallConnections, ServerCalls } from "./operations"; +import { CallingServerApiClientContext } from "./callingServerApiClientContext"; +import { CallingServerApiClientOptionalParams } from "./models"; + +export class CallingServerApiClient extends CallingServerApiClientContext { + /** + * Initializes a new instance of the CallingServerApiClient class. + * @param endpoint The endpoint of the Azure Communication resource. + * @param options The parameter options + */ + constructor( + endpoint: string, + options?: CallingServerApiClientOptionalParams + ) { + super(endpoint, options); + this.callConnections = new CallConnections(this); + this.serverCalls = new ServerCalls(this); + } + + callConnections: CallConnections; + serverCalls: ServerCalls; +} diff --git a/sdk/communication/communication-callingserver/src/generated/src/callingServerApiClientContext.ts b/sdk/communication/communication-callingserver/src/generated/src/callingServerApiClientContext.ts new file mode 100644 index 000000000000..81fd67cb3b9d --- /dev/null +++ b/sdk/communication/communication-callingserver/src/generated/src/callingServerApiClientContext.ts @@ -0,0 +1,54 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as coreHttp from "@azure/core-http"; +import { CallingServerApiClientOptionalParams } from "./models"; + +const packageName = "azure-communication-callingserver"; +const packageVersion = "1.0.0-beta.1"; + +export class CallingServerApiClientContext extends coreHttp.ServiceClient { + endpoint: string; + apiVersion: string; + + /** + * Initializes a new instance of the CallingServerApiClientContext class. + * @param endpoint The endpoint of the Azure Communication resource. + * @param options The parameter options + */ + constructor( + endpoint: string, + options?: CallingServerApiClientOptionalParams + ) { + if (endpoint === undefined) { + throw new Error("'endpoint' cannot be null"); + } + + // Initializing default values for options + if (!options) { + options = {}; + } + + if (!options.userAgent) { + const defaultUserAgent = coreHttp.getDefaultUserAgentValue(); + options.userAgent = `${packageName}/${packageVersion} ${defaultUserAgent}`; + } + + super(undefined, options); + + this.requestContentType = "application/json; charset=utf-8"; + + this.baseUri = options.endpoint || "{endpoint}"; + + // Parameter assignments + this.endpoint = endpoint; + + // Assigning values to Constant parameters + this.apiVersion = options.apiVersion || "2021-06-15-preview"; + } +} diff --git a/sdk/communication/communication-callingserver/src/generated/src/index.ts b/sdk/communication/communication-callingserver/src/generated/src/index.ts new file mode 100644 index 000000000000..3eefcc63d80e --- /dev/null +++ b/sdk/communication/communication-callingserver/src/generated/src/index.ts @@ -0,0 +1,11 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +export * from "./models"; +export { CallingServerApiClient } from "./callingServerApiClient"; +export { CallingServerApiClientContext } from "./callingServerApiClientContext"; diff --git a/sdk/communication/communication-callingserver/src/generated/src/models/index.ts b/sdk/communication/communication-callingserver/src/generated/src/models/index.ts new file mode 100644 index 000000000000..a8d2ca8d742e --- /dev/null +++ b/sdk/communication/communication-callingserver/src/generated/src/models/index.ts @@ -0,0 +1,557 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as coreHttp from "@azure/core-http"; + +/** The request payload for create call. */ +export interface CreateCallRequest { + /** The alternate identity of the source of the call if dialing out to a pstn number */ + alternateCallerId?: PhoneNumberIdentifierModel; + /** The targets of the call. */ + targets: CommunicationIdentifierModel[]; + /** The source of the call. */ + source: CommunicationIdentifierModel; + /** The subject. */ + subject?: string; + /** The callback URI. */ + callbackUri: string; + /** The requested modalities. */ + requestedMediaTypes?: MediaType[]; + /** The requested call events to subscribe to. */ + requestedCallEvents?: EventSubscriptionType[]; +} + +/** A phone number. */ +export interface PhoneNumberIdentifierModel { + /** The phone number in E.164 format. */ + value: string; +} + +/** Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure communication user. This model must be interpreted as a union: Apart from rawId, at most one further property may be set. */ +export interface CommunicationIdentifierModel { + /** Raw Id of the identifier. Optional in requests, required in responses. */ + rawId?: string; + /** The communication user. */ + communicationUser?: CommunicationUserIdentifierModel; + /** The phone number. */ + phoneNumber?: PhoneNumberIdentifierModel; + /** The Microsoft Teams user. */ + microsoftTeamsUser?: MicrosoftTeamsUserIdentifierModel; +} + +/** A user that got created with an Azure Communication Services resource. */ +export interface CommunicationUserIdentifierModel { + /** The Id of the communication user. */ + id: string; +} + +/** A Microsoft Teams user. */ +export interface MicrosoftTeamsUserIdentifierModel { + /** The Id of the Microsoft Teams user. If not anonymous, this is the AAD object Id of the user. */ + userId: string; + /** True if the Microsoft Teams user is anonymous. By default false if missing. */ + isAnonymous?: boolean; + /** The cloud that the Microsoft Teams user belongs to. By default 'public' if missing. */ + cloud?: CommunicationCloudEnvironmentModel; +} + +/** The response payload of the create call operation. */ +export interface CreateCallResult { + /** The call connection id. */ + callConnectionId?: string; +} + +/** The Communication Services error. */ +export interface CommunicationErrorResponse { + /** The Communication Services error. */ + error: CommunicationError; +} + +/** The Communication Services error. */ +export interface CommunicationError { + /** The error code. */ + code: string; + /** The error message. */ + message: string; + /** + * The error target. + * NOTE: This property will not be serialized. It can only be populated by the server. + */ + readonly target?: string; + /** + * Further details about specific errors that led to this error. + * NOTE: This property will not be serialized. It can only be populated by the server. + */ + readonly details?: CommunicationError[]; + /** + * The inner error if any. + * NOTE: This property will not be serialized. It can only be populated by the server. + */ + readonly innerError?: CommunicationError; +} + +/** The request payload for playing audio. */ +export interface PlayAudioRequest { + /** + * The media resource uri of the play audio request. + * Currently only Wave file (.wav) format audio prompts are supported. + * More specifically, the audio content in the wave file must be mono (single-channel), + * 16-bit samples with a 16,000 (16KHz) sampling rate. + */ + audioFileUri?: string; + /** The flag indicating whether audio file needs to be played in loop or not. */ + loop?: boolean; + /** The value to identify context of the operation. */ + operationContext?: string; + /** An id for the media in the AudioFileUri, using which we cache the media resource. */ + audioFileId?: string; + /** The callback Uri to receive PlayAudio status notifications. */ + callbackUri?: string; +} + +/** The response payload for play audio operation. */ +export interface PlayAudioResult { + /** The operation id. */ + operationId?: string; + /** The status of the operation */ + status: OperationStatus; + /** The operation context provided by client. */ + operationContext?: string; + /** The result info for the operation. */ + resultInfo?: ResultInfo; +} + +/** Result info class to be used to report result status for actions/operations. */ +export interface ResultInfo { + /** The result code associated with the operation. */ + code: number; + /** The subcode that further classifies the result. */ + subcode: number; + /** The message is a detail explanation of subcode. */ + message?: string; +} + +/** The request payload for cancel all media operations */ +export interface CancelAllMediaOperationsRequest { + /** The context for this operation. */ + operationContext?: string; +} + +/** The response payload of the cancel all media operations. */ +export interface CancelAllMediaOperationsResult { + /** The operation id. */ + operationId?: string; + /** The status of the operation */ + status: OperationStatus; + /** The operation context provided by client. */ + operationContext?: string; + /** The result info for the operation. */ + resultInfo?: ResultInfo; +} + +/** The add participant request. */ +export interface AddParticipantRequest { + /** The alternate identity of source participant. */ + alternateCallerId?: PhoneNumberIdentifierModel; + /** The participant to be added to the call. */ + participant?: CommunicationIdentifierModel; + /** The operation context. */ + operationContext?: string; + /** The callback URI. */ + callbackUri?: string; +} + +/** The add participant result */ +export interface AddParticipantResult { + /** The id of the added participant. */ + participantId?: string; +} + +/** The request payload start call recording operation. */ +export interface StartCallRecordingRequest { + /** The uri to send notifications to. */ + recordingStateCallbackUri?: string; +} + +/** The response payload of start call recording operation. */ +export interface StartCallRecordingResult { + /** The recording id of the started recording */ + recordingId?: string; +} + +/** The response payload of get call recording properties operation. */ +export interface CallRecordingProperties { + /** The state of the recording */ + recordingState: CallRecordingState; +} + +/** The request payload for join call. */ +export interface JoinCallRequest { + /** The source of the call. */ + source: CommunicationIdentifierModel; + /** The subject. */ + subject?: string; + /** The callback URI. */ + callbackUri: string; + /** The requested modalities. */ + requestedMediaTypes?: MediaType[]; + /** The requested call events to subscribe to. */ + requestedCallEvents?: EventSubscriptionType[]; +} + +/** The response payload of the join call operation. */ +export interface JoinCallResult { + /** The call connection id. */ + callConnectionId?: string; +} + +/** The call connection state changed event. */ +export interface CallConnectionStateChangedEvent { + /** The server call.id. */ + serverCallId?: string; + /** The call connection id. */ + callConnectionId?: string; + /** The call connection state. */ + callConnectionState: CallConnectionState; +} + +/** The call recording state change event. */ +export interface CallRecordingStateChangeEvent { + /** The call recording id */ + recordingId?: string; + /** The state of the recording */ + state: CallRecordingState; + /** The time of the recording started */ + startDateTime: Date; + /** The server call.id. */ + serverCallId?: string; +} + +export interface AddParticipantResultEvent { + /** The result details. */ + resultInfo?: ResultInfo; + /** The operation context. */ + operationContext?: string; + /** The status of the operation */ + status: OperationStatus; +} + +/** The participant update event */ +export interface ParticipantsUpdatedEvent { + /** The call connection id. */ + callConnectionId?: string; + /** The list of participants. */ + participants?: CallParticipant[]; +} + +/** A participant in a call. */ +export interface CallParticipant { + /** Communication identifier of the participant */ + identifier?: CommunicationIdentifierModel; + /** Participant id */ + participantId?: string; + /** Is participant muted */ + isMuted: boolean; +} + +/** The play audio result event. */ +export interface PlayAudioResultEvent { + /** The result details. */ + resultInfo?: ResultInfo; + /** The operation context. */ + operationContext?: string; + /** The status of the operation */ + status: OperationStatus; +} + +/** The subscribe to tone event */ +export interface ToneReceivedEvent { + /** The tone info. */ + toneInfo: ToneInfo; + /** The call connection id. */ + callConnectionId?: string; +} + +/** The information about the tone. */ +export interface ToneInfo { + /** The sequence id which can be used to determine if the same tone was played multiple times or if any tones were missed. */ + sequenceId: number; + /** The tone value. */ + tone: ToneValue; +} + +/** Known values of {@link CommunicationCloudEnvironmentModel} that the service accepts. */ +export const enum KnownCommunicationCloudEnvironmentModel { + Public = "public", + Dod = "dod", + Gcch = "gcch" +} + +/** + * Defines values for CommunicationCloudEnvironmentModel. \ + * {@link KnownCommunicationCloudEnvironmentModel} can be used interchangeably with CommunicationCloudEnvironmentModel, + * this enum contains the known values that the service supports. + * ### Know values supported by the service + * **public** \ + * **dod** \ + * **gcch** + */ +export type CommunicationCloudEnvironmentModel = string; + +/** Known values of {@link MediaType} that the service accepts. */ +export const enum KnownMediaType { + Audio = "audio", + Video = "video" +} + +/** + * Defines values for MediaType. \ + * {@link KnownMediaType} can be used interchangeably with MediaType, + * this enum contains the known values that the service supports. + * ### Know values supported by the service + * **audio** \ + * **video** + */ +export type MediaType = string; + +/** Known values of {@link EventSubscriptionType} that the service accepts. */ +export const enum KnownEventSubscriptionType { + ParticipantsUpdated = "participantsUpdated", + DtmfReceived = "dtmfReceived" +} + +/** + * Defines values for EventSubscriptionType. \ + * {@link KnownEventSubscriptionType} can be used interchangeably with EventSubscriptionType, + * this enum contains the known values that the service supports. + * ### Know values supported by the service + * **participantsUpdated** \ + * **dtmfReceived** + */ +export type EventSubscriptionType = string; + +/** Known values of {@link OperationStatus} that the service accepts. */ +export const enum KnownOperationStatus { + NotStarted = "notStarted", + Running = "running", + Completed = "completed", + Failed = "failed" +} + +/** + * Defines values for OperationStatus. \ + * {@link KnownOperationStatus} can be used interchangeably with OperationStatus, + * this enum contains the known values that the service supports. + * ### Know values supported by the service + * **notStarted** \ + * **running** \ + * **completed** \ + * **failed** + */ +export type OperationStatus = string; + +/** Known values of {@link CallRecordingState} that the service accepts. */ +export const enum KnownCallRecordingState { + Active = "active", + Inactive = "inactive" +} + +/** + * Defines values for CallRecordingState. \ + * {@link KnownCallRecordingState} can be used interchangeably with CallRecordingState, + * this enum contains the known values that the service supports. + * ### Know values supported by the service + * **active** \ + * **inactive** + */ +export type CallRecordingState = string; + +/** Known values of {@link CallConnectionState} that the service accepts. */ +export const enum KnownCallConnectionState { + Incoming = "incoming", + Connecting = "connecting", + Connected = "connected", + Disconnecting = "disconnecting", + Disconnected = "disconnected" +} + +/** + * Defines values for CallConnectionState. \ + * {@link KnownCallConnectionState} can be used interchangeably with CallConnectionState, + * this enum contains the known values that the service supports. + * ### Know values supported by the service + * **incoming** \ + * **connecting** \ + * **connected** \ + * **disconnecting** \ + * **disconnected** + */ +export type CallConnectionState = string; + +/** Known values of {@link ToneValue} that the service accepts. */ +export const enum KnownToneValue { + Tone0 = "tone0", + Tone1 = "tone1", + Tone2 = "tone2", + Tone3 = "tone3", + Tone4 = "tone4", + Tone5 = "tone5", + Tone6 = "tone6", + Tone7 = "tone7", + Tone8 = "tone8", + Tone9 = "tone9", + Star = "star", + Pound = "pound", + A = "a", + B = "b", + C = "c", + D = "d", + Flash = "flash" +} + +/** + * Defines values for ToneValue. \ + * {@link KnownToneValue} can be used interchangeably with ToneValue, + * this enum contains the known values that the service supports. + * ### Know values supported by the service + * **tone0** \ + * **tone1** \ + * **tone2** \ + * **tone3** \ + * **tone4** \ + * **tone5** \ + * **tone6** \ + * **tone7** \ + * **tone8** \ + * **tone9** \ + * **star** \ + * **pound** \ + * **a** \ + * **b** \ + * **c** \ + * **d** \ + * **flash** + */ +export type ToneValue = string; + +/** Contains response data for the createCall operation. */ +export type CallConnectionsCreateCallResponse = CreateCallResult & { + /** The underlying HTTP response. */ + _response: coreHttp.HttpResponse & { + /** The response body as text (string format) */ + bodyAsText: string; + + /** The response body as parsed JSON or XML */ + parsedBody: CreateCallResult; + }; +}; + +/** Contains response data for the playAudio operation. */ +export type CallConnectionsPlayAudioResponse = PlayAudioResult & { + /** The underlying HTTP response. */ + _response: coreHttp.HttpResponse & { + /** The response body as text (string format) */ + bodyAsText: string; + + /** The response body as parsed JSON or XML */ + parsedBody: PlayAudioResult; + }; +}; + +/** Contains response data for the cancelAllMediaOperations operation. */ +export type CallConnectionsCancelAllMediaOperationsResponse = CancelAllMediaOperationsResult & { + /** The underlying HTTP response. */ + _response: coreHttp.HttpResponse & { + /** The response body as text (string format) */ + bodyAsText: string; + + /** The response body as parsed JSON or XML */ + parsedBody: CancelAllMediaOperationsResult; + }; +}; + +/** Contains response data for the addParticipant operation. */ +export type CallConnectionsAddParticipantResponse = AddParticipantResult & { + /** The underlying HTTP response. */ + _response: coreHttp.HttpResponse & { + /** The response body as text (string format) */ + bodyAsText: string; + + /** The response body as parsed JSON or XML */ + parsedBody: AddParticipantResult; + }; +}; + +/** Contains response data for the addParticipant operation. */ +export type ServerCallsAddParticipantResponse = AddParticipantResult & { + /** The underlying HTTP response. */ + _response: coreHttp.HttpResponse & { + /** The response body as text (string format) */ + bodyAsText: string; + + /** The response body as parsed JSON or XML */ + parsedBody: AddParticipantResult; + }; +}; + +/** Contains response data for the startRecording operation. */ +export type ServerCallsStartRecordingResponse = StartCallRecordingResult & { + /** The underlying HTTP response. */ + _response: coreHttp.HttpResponse & { + /** The response body as text (string format) */ + bodyAsText: string; + + /** The response body as parsed JSON or XML */ + parsedBody: StartCallRecordingResult; + }; +}; + +/** Contains response data for the getRecordingProperties operation. */ +export type ServerCallsGetRecordingPropertiesResponse = CallRecordingProperties & { + /** The underlying HTTP response. */ + _response: coreHttp.HttpResponse & { + /** The response body as text (string format) */ + bodyAsText: string; + + /** The response body as parsed JSON or XML */ + parsedBody: CallRecordingProperties; + }; +}; + +/** Contains response data for the joinCall operation. */ +export type ServerCallsJoinCallResponse = JoinCallResult & { + /** The underlying HTTP response. */ + _response: coreHttp.HttpResponse & { + /** The response body as text (string format) */ + bodyAsText: string; + + /** The response body as parsed JSON or XML */ + parsedBody: JoinCallResult; + }; +}; + +/** Contains response data for the playAudio operation. */ +export type ServerCallsPlayAudioResponse = PlayAudioResult & { + /** The underlying HTTP response. */ + _response: coreHttp.HttpResponse & { + /** The response body as text (string format) */ + bodyAsText: string; + + /** The response body as parsed JSON or XML */ + parsedBody: PlayAudioResult; + }; +}; + +/** Optional parameters. */ +export interface CallingServerApiClientOptionalParams + extends coreHttp.ServiceClientOptions { + /** Api Version */ + apiVersion?: string; + /** Overrides client endpoint. */ + endpoint?: string; +} diff --git a/sdk/communication/communication-callingserver/src/generated/src/models/mappers.ts b/sdk/communication/communication-callingserver/src/generated/src/models/mappers.ts new file mode 100644 index 000000000000..a36c1955fa1f --- /dev/null +++ b/sdk/communication/communication-callingserver/src/generated/src/models/mappers.ts @@ -0,0 +1,794 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as coreHttp from "@azure/core-http"; + +export const CreateCallRequest: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "CreateCallRequest", + modelProperties: { + alternateCallerId: { + serializedName: "alternateCallerId", + type: { + name: "Composite", + className: "PhoneNumberIdentifierModel" + } + }, + targets: { + serializedName: "targets", + required: true, + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "CommunicationIdentifierModel" + } + } + } + }, + source: { + serializedName: "source", + type: { + name: "Composite", + className: "CommunicationIdentifierModel" + } + }, + subject: { + serializedName: "subject", + type: { + name: "String" + } + }, + callbackUri: { + serializedName: "callbackUri", + required: true, + type: { + name: "String" + } + }, + requestedMediaTypes: { + serializedName: "requestedMediaTypes", + type: { + name: "Sequence", + element: { + type: { + name: "String" + } + } + } + }, + requestedCallEvents: { + serializedName: "requestedCallEvents", + type: { + name: "Sequence", + element: { + type: { + name: "String" + } + } + } + } + } + } +}; + +export const PhoneNumberIdentifierModel: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "PhoneNumberIdentifierModel", + modelProperties: { + value: { + serializedName: "value", + required: true, + type: { + name: "String" + } + } + } + } +}; + +export const CommunicationIdentifierModel: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "CommunicationIdentifierModel", + modelProperties: { + rawId: { + serializedName: "rawId", + type: { + name: "String" + } + }, + communicationUser: { + serializedName: "communicationUser", + type: { + name: "Composite", + className: "CommunicationUserIdentifierModel" + } + }, + phoneNumber: { + serializedName: "phoneNumber", + type: { + name: "Composite", + className: "PhoneNumberIdentifierModel" + } + }, + microsoftTeamsUser: { + serializedName: "microsoftTeamsUser", + type: { + name: "Composite", + className: "MicrosoftTeamsUserIdentifierModel" + } + } + } + } +}; + +export const CommunicationUserIdentifierModel: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "CommunicationUserIdentifierModel", + modelProperties: { + id: { + serializedName: "id", + required: true, + type: { + name: "String" + } + } + } + } +}; + +export const MicrosoftTeamsUserIdentifierModel: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "MicrosoftTeamsUserIdentifierModel", + modelProperties: { + userId: { + serializedName: "userId", + required: true, + type: { + name: "String" + } + }, + isAnonymous: { + serializedName: "isAnonymous", + type: { + name: "Boolean" + } + }, + cloud: { + serializedName: "cloud", + type: { + name: "String" + } + } + } + } +}; + +export const CreateCallResult: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "CreateCallResult", + modelProperties: { + callConnectionId: { + serializedName: "callConnectionId", + type: { + name: "String" + } + } + } + } +}; + +export const CommunicationErrorResponse: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "CommunicationErrorResponse", + modelProperties: { + error: { + serializedName: "error", + type: { + name: "Composite", + className: "CommunicationError" + } + } + } + } +}; + +export const CommunicationError: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "CommunicationError", + modelProperties: { + code: { + serializedName: "code", + required: true, + type: { + name: "String" + } + }, + message: { + serializedName: "message", + required: true, + type: { + name: "String" + } + }, + target: { + serializedName: "target", + readOnly: true, + type: { + name: "String" + } + }, + details: { + serializedName: "details", + readOnly: true, + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "CommunicationError" + } + } + } + }, + innerError: { + serializedName: "innererror", + type: { + name: "Composite", + className: "CommunicationError" + } + } + } + } +}; + +export const PlayAudioRequest: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "PlayAudioRequest", + modelProperties: { + audioFileUri: { + serializedName: "audioFileUri", + type: { + name: "String" + } + }, + loop: { + serializedName: "loop", + type: { + name: "Boolean" + } + }, + operationContext: { + serializedName: "operationContext", + type: { + name: "String" + } + }, + audioFileId: { + serializedName: "audioFileId", + type: { + name: "String" + } + }, + callbackUri: { + serializedName: "callbackUri", + type: { + name: "String" + } + } + } + } +}; + +export const PlayAudioResult: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "PlayAudioResult", + modelProperties: { + operationId: { + serializedName: "operationId", + type: { + name: "String" + } + }, + status: { + serializedName: "status", + required: true, + type: { + name: "String" + } + }, + operationContext: { + serializedName: "operationContext", + type: { + name: "String" + } + }, + resultInfo: { + serializedName: "resultInfo", + type: { + name: "Composite", + className: "ResultInfo" + } + } + } + } +}; + +export const ResultInfo: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "ResultInfo", + modelProperties: { + code: { + serializedName: "code", + required: true, + type: { + name: "Number" + } + }, + subcode: { + serializedName: "subcode", + required: true, + type: { + name: "Number" + } + }, + message: { + serializedName: "message", + type: { + name: "String" + } + } + } + } +}; + +export const CancelAllMediaOperationsRequest: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "CancelAllMediaOperationsRequest", + modelProperties: { + operationContext: { + serializedName: "operationContext", + type: { + name: "String" + } + } + } + } +}; + +export const CancelAllMediaOperationsResult: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "CancelAllMediaOperationsResult", + modelProperties: { + operationId: { + serializedName: "operationId", + type: { + name: "String" + } + }, + status: { + serializedName: "status", + required: true, + type: { + name: "String" + } + }, + operationContext: { + serializedName: "operationContext", + type: { + name: "String" + } + }, + resultInfo: { + serializedName: "resultInfo", + type: { + name: "Composite", + className: "ResultInfo" + } + } + } + } +}; + +export const AddParticipantRequest: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "AddParticipantRequest", + modelProperties: { + alternateCallerId: { + serializedName: "alternateCallerId", + type: { + name: "Composite", + className: "PhoneNumberIdentifierModel" + } + }, + participant: { + serializedName: "participant", + type: { + name: "Composite", + className: "CommunicationIdentifierModel" + } + }, + operationContext: { + serializedName: "operationContext", + type: { + name: "String" + } + }, + callbackUri: { + serializedName: "callbackUri", + type: { + name: "String" + } + } + } + } +}; + +export const AddParticipantResult: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "AddParticipantResult", + modelProperties: { + participantId: { + serializedName: "participantId", + type: { + name: "String" + } + } + } + } +}; + +export const StartCallRecordingRequest: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "StartCallRecordingRequest", + modelProperties: { + recordingStateCallbackUri: { + serializedName: "recordingStateCallbackUri", + type: { + name: "String" + } + } + } + } +}; + +export const StartCallRecordingResult: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "StartCallRecordingResult", + modelProperties: { + recordingId: { + serializedName: "recordingId", + type: { + name: "String" + } + } + } + } +}; + +export const CallRecordingProperties: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "CallRecordingProperties", + modelProperties: { + recordingState: { + serializedName: "recordingState", + required: true, + type: { + name: "String" + } + } + } + } +}; + +export const JoinCallRequest: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "JoinCallRequest", + modelProperties: { + source: { + serializedName: "source", + type: { + name: "Composite", + className: "CommunicationIdentifierModel" + } + }, + subject: { + serializedName: "subject", + type: { + name: "String" + } + }, + callbackUri: { + serializedName: "callbackUri", + required: true, + type: { + name: "String" + } + }, + requestedMediaTypes: { + serializedName: "requestedMediaTypes", + type: { + name: "Sequence", + element: { + type: { + name: "String" + } + } + } + }, + requestedCallEvents: { + serializedName: "requestedCallEvents", + type: { + name: "Sequence", + element: { + type: { + name: "String" + } + } + } + } + } + } +}; + +export const JoinCallResult: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "JoinCallResult", + modelProperties: { + callConnectionId: { + serializedName: "callConnectionId", + type: { + name: "String" + } + } + } + } +}; + +export const CallConnectionStateChangedEvent: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "CallConnectionStateChangedEvent", + modelProperties: { + serverCallId: { + serializedName: "serverCallId", + type: { + name: "String" + } + }, + callConnectionId: { + serializedName: "callConnectionId", + type: { + name: "String" + } + }, + callConnectionState: { + serializedName: "callConnectionState", + required: true, + type: { + name: "String" + } + } + } + } +}; + +export const CallRecordingStateChangeEvent: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "CallRecordingStateChangeEvent", + modelProperties: { + recordingId: { + serializedName: "recordingId", + type: { + name: "String" + } + }, + state: { + serializedName: "state", + required: true, + type: { + name: "String" + } + }, + startDateTime: { + serializedName: "startDateTime", + required: true, + type: { + name: "DateTime" + } + }, + serverCallId: { + serializedName: "serverCallId", + type: { + name: "String" + } + } + } + } +}; + +export const AddParticipantResultEvent: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "AddParticipantResultEvent", + modelProperties: { + resultInfo: { + serializedName: "resultInfo", + type: { + name: "Composite", + className: "ResultInfo" + } + }, + operationContext: { + serializedName: "operationContext", + type: { + name: "String" + } + }, + status: { + serializedName: "status", + required: true, + type: { + name: "String" + } + } + } + } +}; + +export const ParticipantsUpdatedEvent: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "ParticipantsUpdatedEvent", + modelProperties: { + callConnectionId: { + serializedName: "callConnectionId", + type: { + name: "String" + } + }, + participants: { + serializedName: "participants", + type: { + name: "Sequence", + element: { + type: { + name: "Composite", + className: "CallParticipant" + } + } + } + } + } + } +}; + +export const CallParticipant: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "CallParticipant", + modelProperties: { + identifier: { + serializedName: "identifier", + type: { + name: "Composite", + className: "CommunicationIdentifierModel" + } + }, + participantId: { + serializedName: "participantId", + type: { + name: "String" + } + }, + isMuted: { + serializedName: "isMuted", + required: true, + type: { + name: "Boolean" + } + } + } + } +}; + +export const PlayAudioResultEvent: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "PlayAudioResultEvent", + modelProperties: { + resultInfo: { + serializedName: "resultInfo", + type: { + name: "Composite", + className: "ResultInfo" + } + }, + operationContext: { + serializedName: "operationContext", + type: { + name: "String" + } + }, + status: { + serializedName: "status", + required: true, + type: { + name: "String" + } + } + } + } +}; + +export const ToneReceivedEvent: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "ToneReceivedEvent", + modelProperties: { + toneInfo: { + serializedName: "toneInfo", + type: { + name: "Composite", + className: "ToneInfo" + } + }, + callConnectionId: { + serializedName: "callConnectionId", + type: { + name: "String" + } + } + } + } +}; + +export const ToneInfo: coreHttp.CompositeMapper = { + type: { + name: "Composite", + className: "ToneInfo", + modelProperties: { + sequenceId: { + serializedName: "sequenceId", + required: true, + type: { + name: "Number" + } + }, + tone: { + serializedName: "tone", + required: true, + type: { + name: "String" + } + } + } + } +}; diff --git a/sdk/communication/communication-callingserver/src/generated/src/models/parameters.ts b/sdk/communication/communication-callingserver/src/generated/src/models/parameters.ts new file mode 100644 index 000000000000..e6a47498c447 --- /dev/null +++ b/sdk/communication/communication-callingserver/src/generated/src/models/parameters.ts @@ -0,0 +1,143 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import { + OperationParameter, + OperationURLParameter, + OperationQueryParameter +} from "@azure/core-http"; +import { + CreateCallRequest as CreateCallRequestMapper, + PlayAudioRequest as PlayAudioRequestMapper, + CancelAllMediaOperationsRequest as CancelAllMediaOperationsRequestMapper, + AddParticipantRequest as AddParticipantRequestMapper, + StartCallRecordingRequest as StartCallRecordingRequestMapper, + JoinCallRequest as JoinCallRequestMapper +} from "../models/mappers"; + +export const contentType: OperationParameter = { + parameterPath: ["options", "contentType"], + mapper: { + defaultValue: "application/json", + isConstant: true, + serializedName: "Content-Type", + type: { + name: "String" + } + } +}; + +export const callRequest: OperationParameter = { + parameterPath: "callRequest", + mapper: CreateCallRequestMapper +}; + +export const accept: OperationParameter = { + parameterPath: "accept", + mapper: { + defaultValue: "application/json", + isConstant: true, + serializedName: "Accept", + type: { + name: "String" + } + } +}; + +export const endpoint: OperationURLParameter = { + parameterPath: "endpoint", + mapper: { + serializedName: "endpoint", + required: true, + type: { + name: "String" + } + }, + skipEncoding: true +}; + +export const apiVersion: OperationQueryParameter = { + parameterPath: "apiVersion", + mapper: { + defaultValue: "2021-06-15-preview", + isConstant: true, + serializedName: "api-version", + type: { + name: "String" + } + } +}; + +export const callConnectionId: OperationURLParameter = { + parameterPath: "callConnectionId", + mapper: { + serializedName: "callConnectionId", + required: true, + type: { + name: "String" + } + } +}; + +export const request: OperationParameter = { + parameterPath: "request", + mapper: PlayAudioRequestMapper +}; + +export const cancelAllMediaOperationRequest: OperationParameter = { + parameterPath: "cancelAllMediaOperationRequest", + mapper: CancelAllMediaOperationsRequestMapper +}; + +export const addParticipantRequest: OperationParameter = { + parameterPath: "addParticipantRequest", + mapper: AddParticipantRequestMapper +}; + +export const participantId: OperationURLParameter = { + parameterPath: "participantId", + mapper: { + serializedName: "participantId", + required: true, + type: { + name: "String" + } + } +}; + +export const serverCallId: OperationURLParameter = { + parameterPath: "serverCallId", + mapper: { + serializedName: "serverCallId", + required: true, + type: { + name: "String" + } + } +}; + +export const request1: OperationParameter = { + parameterPath: "request", + mapper: StartCallRecordingRequestMapper +}; + +export const recordingId: OperationURLParameter = { + parameterPath: "recordingId", + mapper: { + serializedName: "recordingId", + required: true, + type: { + name: "String" + } + } +}; + +export const callRequest1: OperationParameter = { + parameterPath: "callRequest", + mapper: JoinCallRequestMapper +}; diff --git a/sdk/communication/communication-callingserver/src/generated/src/operations/callConnections.ts b/sdk/communication/communication-callingserver/src/generated/src/operations/callConnections.ts new file mode 100644 index 000000000000..0f4125420d62 --- /dev/null +++ b/sdk/communication/communication-callingserver/src/generated/src/operations/callConnections.ts @@ -0,0 +1,367 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as coreHttp from "@azure/core-http"; +import * as Mappers from "../models/mappers"; +import * as Parameters from "../models/parameters"; +import { CallingServerApiClientContext } from "../callingServerApiClientContext"; +import { + CreateCallRequest, + CallConnectionsCreateCallResponse, + PlayAudioRequest, + CallConnectionsPlayAudioResponse, + CancelAllMediaOperationsRequest, + CallConnectionsCancelAllMediaOperationsResponse, + AddParticipantRequest, + CallConnectionsAddParticipantResponse +} from "../models"; + +/** Class representing a CallConnections. */ +export class CallConnections { + private readonly client: CallingServerApiClientContext; + + /** + * Initialize a new instance of the class CallConnections class. + * @param client Reference to the service client + */ + constructor(client: CallingServerApiClientContext) { + this.client = client; + } + + /** + * Create a new call. + * @param callRequest Create call request. + * @param options The options parameters. + */ + createCall( + callRequest: CreateCallRequest, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + callRequest, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + createCallOperationSpec + ) as Promise; + } + + /** + * Hangup the call. + * @param callConnectionId The call connection id. + * @param options The options parameters. + */ + hangupCall( + callConnectionId: string, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + callConnectionId, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + hangupCallOperationSpec + ) as Promise; + } + + /** + * Play audio in the call. + * @param callConnectionId The call connection id. + * @param request Play audio request. + * @param options The options parameters. + */ + playAudio( + callConnectionId: string, + request: PlayAudioRequest, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + callConnectionId, + request, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + playAudioOperationSpec + ) as Promise; + } + + /** + * Cancel all media operations. + * @param callConnectionId The call connection id + * @param cancelAllMediaOperationRequest The cancel all media operations context. + * @param options The options parameters. + */ + cancelAllMediaOperations( + callConnectionId: string, + cancelAllMediaOperationRequest: CancelAllMediaOperationsRequest, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + callConnectionId, + cancelAllMediaOperationRequest, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + cancelAllMediaOperationsOperationSpec + ) as Promise; + } + + /** + * Add a participant to the call. + * @param callConnectionId The call connection id. + * @param addParticipantRequest Add participant request. + * @param options The options parameters. + */ + addParticipant( + callConnectionId: string, + addParticipantRequest: AddParticipantRequest, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + callConnectionId, + addParticipantRequest, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + addParticipantOperationSpec + ) as Promise; + } + + /** + * Remove a participant from the call. + * @param callConnectionId The call connection id. + * @param participantId The participant id. + * @param options The options parameters. + */ + removeParticipant( + callConnectionId: string, + participantId: string, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + callConnectionId, + participantId, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + removeParticipantOperationSpec + ) as Promise; + } +} +// Operation Specifications +const serializer = new coreHttp.Serializer(Mappers, /* isXml */ false); + +const createCallOperationSpec: coreHttp.OperationSpec = { + path: "/calling/callConnections", + httpMethod: "POST", + responses: { + 201: { + bodyMapper: Mappers.CreateCallResult + }, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + requestBody: Parameters.callRequest, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint], + headerParameters: [Parameters.contentType, Parameters.accept], + mediaType: "json", + serializer +}; +const hangupCallOperationSpec: coreHttp.OperationSpec = { + path: "/calling/callConnections/{callConnectionId}/:hangup", + httpMethod: "POST", + responses: { + 202: {}, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 404: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint, Parameters.callConnectionId], + headerParameters: [Parameters.accept], + serializer +}; +const playAudioOperationSpec: coreHttp.OperationSpec = { + path: "/calling/callConnections/{callConnectionId}/:playAudio", + httpMethod: "POST", + responses: { + 202: { + bodyMapper: Mappers.PlayAudioResult + }, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 404: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + requestBody: Parameters.request, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint, Parameters.callConnectionId], + headerParameters: [Parameters.contentType, Parameters.accept], + mediaType: "json", + serializer +}; +const cancelAllMediaOperationsOperationSpec: coreHttp.OperationSpec = { + path: "/calling/callConnections/{callConnectionId}/:cancelAllMediaOperations", + httpMethod: "POST", + responses: { + 200: { + bodyMapper: Mappers.CancelAllMediaOperationsResult + }, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 404: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + requestBody: Parameters.cancelAllMediaOperationRequest, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint, Parameters.callConnectionId], + headerParameters: [Parameters.contentType, Parameters.accept], + mediaType: "json", + serializer +}; +const addParticipantOperationSpec: coreHttp.OperationSpec = { + path: "/calling/callConnections/{callConnectionId}/participants", + httpMethod: "POST", + responses: { + 202: { + bodyMapper: Mappers.AddParticipantResult + }, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 404: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + requestBody: Parameters.addParticipantRequest, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint, Parameters.callConnectionId], + headerParameters: [Parameters.contentType, Parameters.accept], + mediaType: "json", + serializer +}; +const removeParticipantOperationSpec: coreHttp.OperationSpec = { + path: + "/calling/callConnections/{callConnectionId}/participants/{participantId}", + httpMethod: "DELETE", + responses: { + 202: {}, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 404: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [ + Parameters.endpoint, + Parameters.callConnectionId, + Parameters.participantId + ], + headerParameters: [Parameters.accept], + serializer +}; diff --git a/sdk/communication/communication-callingserver/src/generated/src/operations/index.ts b/sdk/communication/communication-callingserver/src/generated/src/operations/index.ts new file mode 100644 index 000000000000..404a44c57f54 --- /dev/null +++ b/sdk/communication/communication-callingserver/src/generated/src/operations/index.ts @@ -0,0 +1,10 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +export * from "./callConnections"; +export * from "./serverCalls"; diff --git a/sdk/communication/communication-callingserver/src/generated/src/operations/serverCalls.ts b/sdk/communication/communication-callingserver/src/generated/src/operations/serverCalls.ts new file mode 100644 index 000000000000..bf84b818dcd4 --- /dev/null +++ b/sdk/communication/communication-callingserver/src/generated/src/operations/serverCalls.ts @@ -0,0 +1,550 @@ +/* + * Copyright (c) Microsoft Corporation. + * Licensed under the MIT License. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * Changes may cause incorrect behavior and will be lost if the code is regenerated. + */ + +import * as coreHttp from "@azure/core-http"; +import * as Mappers from "../models/mappers"; +import * as Parameters from "../models/parameters"; +import { CallingServerApiClientContext } from "../callingServerApiClientContext"; +import { + AddParticipantRequest, + ServerCallsAddParticipantResponse, + StartCallRecordingRequest, + ServerCallsStartRecordingResponse, + ServerCallsGetRecordingPropertiesResponse, + JoinCallRequest, + ServerCallsJoinCallResponse, + PlayAudioRequest, + ServerCallsPlayAudioResponse +} from "../models"; + +/** Class representing a ServerCalls. */ +export class ServerCalls { + private readonly client: CallingServerApiClientContext; + + /** + * Initialize a new instance of the class ServerCalls class. + * @param client Reference to the service client + */ + constructor(client: CallingServerApiClientContext) { + this.client = client; + } + + /** + * Add a participant to the call. + * @param serverCallId The server call id. + * @param addParticipantRequest The add participant request. + * @param options The options parameters. + */ + addParticipant( + serverCallId: string, + addParticipantRequest: AddParticipantRequest, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + serverCallId, + addParticipantRequest, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + addParticipantOperationSpec + ) as Promise; + } + + /** + * Remove participant from the call. + * @param serverCallId Server call id. + * @param participantId Participant id. + * @param options The options parameters. + */ + removeParticipant( + serverCallId: string, + participantId: string, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + serverCallId, + participantId, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + removeParticipantOperationSpec + ) as Promise; + } + + /** + * Start recording of the call. + * @param serverCallId The server call id. + * @param request The request body of start call recording request. + * @param options The options parameters. + */ + startRecording( + serverCallId: string, + request: StartCallRecordingRequest, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + serverCallId, + request, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + startRecordingOperationSpec + ) as Promise; + } + + /** + * Get call recording properties. + * @param serverCallId The server call id. + * @param recordingId The recording id. + * @param options The options parameters. + */ + getRecordingProperties( + serverCallId: string, + recordingId: string, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + serverCallId, + recordingId, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + getRecordingPropertiesOperationSpec + ) as Promise; + } + + /** + * Stop recording the call. + * @param serverCallId The server call id. + * @param recordingId The recording id. + * @param options The options parameters. + */ + stopRecording( + serverCallId: string, + recordingId: string, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + serverCallId, + recordingId, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + stopRecordingOperationSpec + ) as Promise; + } + + /** + * Pause recording the call. + * @param serverCallId The server call id. + * @param recordingId The recording id. + * @param options The options parameters. + */ + pauseRecording( + serverCallId: string, + recordingId: string, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + serverCallId, + recordingId, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + pauseRecordingOperationSpec + ) as Promise; + } + + /** + * Resume recording the call. + * @param serverCallId The server call id. + * @param recordingId The recording id. + * @param options The options parameters. + */ + resumeRecording( + serverCallId: string, + recordingId: string, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + serverCallId, + recordingId, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + resumeRecordingOperationSpec + ) as Promise; + } + + /** + * Join a call. + * @param serverCallId The server call id. + * @param callRequest The join call request. + * @param options The options parameters. + */ + joinCall( + serverCallId: string, + callRequest: JoinCallRequest, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + serverCallId, + callRequest, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + joinCallOperationSpec + ) as Promise; + } + + /** + * Play audio in the call. + * @param serverCallId The server call id. + * @param request Play audio request. + * @param options The options parameters. + */ + playAudio( + serverCallId: string, + request: PlayAudioRequest, + options?: coreHttp.OperationOptions + ): Promise { + const operationArguments: coreHttp.OperationArguments = { + serverCallId, + request, + options: coreHttp.operationOptionsToRequestOptionsBase(options || {}) + }; + return this.client.sendOperationRequest( + operationArguments, + playAudioOperationSpec + ) as Promise; + } +} +// Operation Specifications +const serializer = new coreHttp.Serializer(Mappers, /* isXml */ false); + +const addParticipantOperationSpec: coreHttp.OperationSpec = { + path: "/calling/serverCalls/{serverCallId}/participants", + httpMethod: "POST", + responses: { + 202: { + bodyMapper: Mappers.AddParticipantResult + }, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 404: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + requestBody: Parameters.addParticipantRequest, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint, Parameters.serverCallId], + headerParameters: [Parameters.contentType, Parameters.accept], + mediaType: "json", + serializer +}; +const removeParticipantOperationSpec: coreHttp.OperationSpec = { + path: "/calling/serverCalls/{serverCallId}/participants/{participantId}", + httpMethod: "DELETE", + responses: { + 202: {}, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 404: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [ + Parameters.endpoint, + Parameters.participantId, + Parameters.serverCallId + ], + headerParameters: [Parameters.accept], + serializer +}; +const startRecordingOperationSpec: coreHttp.OperationSpec = { + path: "/calling/serverCalls/{serverCallId}/recordings", + httpMethod: "POST", + responses: { + 200: { + bodyMapper: Mappers.StartCallRecordingResult + }, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 404: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + requestBody: Parameters.request1, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint, Parameters.serverCallId], + headerParameters: [Parameters.contentType, Parameters.accept], + mediaType: "json", + serializer +}; +const getRecordingPropertiesOperationSpec: coreHttp.OperationSpec = { + path: "/calling/serverCalls/{serverCallId}/recordings/{recordingId}", + httpMethod: "GET", + responses: { + 200: { + bodyMapper: Mappers.CallRecordingProperties + }, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 404: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [ + Parameters.endpoint, + Parameters.serverCallId, + Parameters.recordingId + ], + headerParameters: [Parameters.accept], + serializer +}; +const stopRecordingOperationSpec: coreHttp.OperationSpec = { + path: "/calling/serverCalls/{serverCallId}/recordings/{recordingId}", + httpMethod: "DELETE", + responses: { + 200: {}, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 404: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [ + Parameters.endpoint, + Parameters.serverCallId, + Parameters.recordingId + ], + headerParameters: [Parameters.accept], + serializer +}; +const pauseRecordingOperationSpec: coreHttp.OperationSpec = { + path: "/calling/serverCalls/{serverCallId}/recordings/{recordingId}/:pause", + httpMethod: "POST", + responses: { + 200: {}, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 404: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [ + Parameters.endpoint, + Parameters.serverCallId, + Parameters.recordingId + ], + headerParameters: [Parameters.accept], + serializer +}; +const resumeRecordingOperationSpec: coreHttp.OperationSpec = { + path: "/calling/serverCalls/{serverCallId}/recordings/{recordingId}/:resume", + httpMethod: "POST", + responses: { + 200: {}, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 404: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + queryParameters: [Parameters.apiVersion], + urlParameters: [ + Parameters.endpoint, + Parameters.serverCallId, + Parameters.recordingId + ], + headerParameters: [Parameters.accept], + serializer +}; +const joinCallOperationSpec: coreHttp.OperationSpec = { + path: "/calling/serverCalls/{serverCallId}/:join", + httpMethod: "POST", + responses: { + 202: { + bodyMapper: Mappers.JoinCallResult + }, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + requestBody: Parameters.callRequest1, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint, Parameters.serverCallId], + headerParameters: [Parameters.contentType, Parameters.accept], + mediaType: "json", + serializer +}; +const playAudioOperationSpec: coreHttp.OperationSpec = { + path: "/calling/serverCalls/{serverCallId}/:playAudio", + httpMethod: "POST", + responses: { + 202: { + bodyMapper: Mappers.PlayAudioResult + }, + 400: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 401: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 403: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 404: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + }, + 500: { + bodyMapper: Mappers.CommunicationErrorResponse, + isError: true + } + }, + requestBody: Parameters.request, + queryParameters: [Parameters.apiVersion], + urlParameters: [Parameters.endpoint, Parameters.serverCallId], + headerParameters: [Parameters.contentType, Parameters.accept], + mediaType: "json", + serializer +}; diff --git a/sdk/communication/communication-callingserver/src/index.ts b/sdk/communication/communication-callingserver/src/index.ts new file mode 100644 index 000000000000..b7892bd86178 --- /dev/null +++ b/sdk/communication/communication-callingserver/src/index.ts @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +export * from "./models"; +export * from "./callingServerClient"; +export * from "./callConnection"; +export * from "./serverCall"; diff --git a/sdk/communication/communication-callingserver/src/logger.ts b/sdk/communication/communication-callingserver/src/logger.ts new file mode 100644 index 000000000000..5d182d948f87 --- /dev/null +++ b/sdk/communication/communication-callingserver/src/logger.ts @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { createClientLogger } from "@azure/logger"; + +export const logger = createClientLogger("communication-callingserver"); diff --git a/sdk/communication/communication-callingserver/src/models.ts b/sdk/communication/communication-callingserver/src/models.ts new file mode 100644 index 000000000000..3875a3d5082e --- /dev/null +++ b/sdk/communication/communication-callingserver/src/models.ts @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +import { OperationOptions } from "@azure/core-http"; +import { PhoneNumberIdentifier } from "@azure/communication-common"; + +export { + PlayAudioResult +} from "./generated/src/models"; + + +/** Known values of {@link MediaType} that the service accepts. */ +export const enum MediaType { + Audio = "audio", + Video = "video" +} + +/** Known values of {@link EventSubscriptionType} that the service accepts. */ +export const enum EventSubscriptionType { + ParticipantsUpdated = "participantsUpdated", + DtmfReceived = "dtmfReceived" +} + +/** + * Options to create a call. + */ +export interface CreateCallConnectionOptions extends OperationOptions { + /** The alternate identity of the source of the call if dialing out to a pstn number */ + alternateCallerId?: PhoneNumberIdentifier; + /** The subject. */ + subject?: string; + /** The callback URI. */ + callbackUri: string; + /** The requested modalities. */ + requestedMediaTypes: MediaType[]; + /** The requested call events to subscribe to. */ + requestedCallEvents: EventSubscriptionType[]; +} + +/** + * Options to join a call. + */ +export interface JoinCallOptions extends OperationOptions { + /** The subject. */ + subject?: string; + /** The callback URI. */ + callbackUri: string; + /** The requested modalities. */ + requestedMediaTypes?: MediaType[]; + /** The requested call events to subscribe to. */ + requestedCallEvents?: EventSubscriptionType[]; +} + +/** + * Options to hang up a call. + */ +export type HangUpOptions = OperationOptions; + +/** + * Options to play audio. + */ +export type PlayAudioOptions = OperationOptions; diff --git a/sdk/communication/communication-callingserver/src/serverCall.ts b/sdk/communication/communication-callingserver/src/serverCall.ts new file mode 100644 index 000000000000..de1b5777d406 --- /dev/null +++ b/sdk/communication/communication-callingserver/src/serverCall.ts @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. +/// + +import { ServerCalls } from "./generated/src/operations"; +import { PlayAudioOptions } from "./models"; +import { PlayAudioRequest } from "./generated/src/models"; +import { + PlayAudioResult +} from "./models"; +import { createSpan } from "./tracing"; +import { + operationOptionsToRequestOptionsBase +} from "@azure/core-http"; +import { SpanStatusCode } from "@azure/core-tracing"; + +/** + * The client to do call connection operations + */ + export class ServerCall { + private readonly serverCallId: string; + private readonly serverCallRestClient: ServerCalls; + + constructor( + serverCallId: string, + serverCallRestClient: ServerCalls + ) { + this.serverCallId = serverCallId; + this.serverCallRestClient = serverCallRestClient; + } + + public async playAudio( + audioFileUri: string, + audioFileId: string, + callbackUri: string, + operationContext?: string, + options: PlayAudioOptions = {} + ): Promise { + const { span, updatedOptions } = createSpan("ServerCallRestClient-PlayAudio", options); + + const request: PlayAudioRequest = { + audioFileUri: audioFileUri, + audioFileId: audioFileId, + callbackUri: callbackUri, + operationContext: operationContext, + }; + + try { + const result = await this.serverCallRestClient.playAudio( + this.serverCallId, + request, + operationOptionsToRequestOptionsBase(updatedOptions) + ); + return result; + + } catch (e) { + span.setStatus({ + code: SpanStatusCode.ERROR, + message: e.message + }); + throw e; + } finally { + span.end(); + } + } +} diff --git a/sdk/communication/communication-callingserver/src/tracing.ts b/sdk/communication/communication-callingserver/src/tracing.ts new file mode 100644 index 000000000000..88aa261c1114 --- /dev/null +++ b/sdk/communication/communication-callingserver/src/tracing.ts @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { createSpanFunction } from "@azure/core-tracing"; + +/** + * Creates a span using the global tracer. + * @internal + */ +export const createSpan = createSpanFunction({ + packagePrefix: "Azure.Communication", + namespace: "Microsoft.Communication" +}); diff --git a/sdk/communication/communication-callingserver/src/uuid.ts b/sdk/communication/communication-callingserver/src/uuid.ts new file mode 100644 index 000000000000..c6cf92396ce3 --- /dev/null +++ b/sdk/communication/communication-callingserver/src/uuid.ts @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { generateUuid } from "@azure/core-http"; + +// This is used as a workaround to be able to stub generateUuid +// during testing. +export class Uuid { + public static generateUuid(): string { + return generateUuid(); + } +} diff --git a/sdk/communication/communication-callingserver/swagger/README.md b/sdk/communication/communication-callingserver/swagger/README.md new file mode 100644 index 000000000000..3b55175a352e --- /dev/null +++ b/sdk/communication/communication-callingserver/swagger/README.md @@ -0,0 +1,23 @@ +# Azure Communication Services CallingServer Protocol Layer + +> see [https://aka.ms/autorest](https://aka.ms/autorest) + +## Configuration + +```yaml +package-name: azure-communication-callingserver +title: CallingServerApiClient +description: CallingServer Client +generate-metadata: false +license-header: MICROSOFT_MIT_NO_VERSION +output-folder: ../src/generated +tag: package-2021-06-15-preview +require: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/472ed65c628500835be420732be07728118d3563/specification/communication/data-plane/CallingServer/readme.md +model-date-time-as-string: false +optional-response-headers: true +use-extension: + "@autorest/typescript": "6.0.0-dev.20210217.1" +azure-arm: false +add-credentials: false +package-version: 1.0.0-beta.1 +``` diff --git a/sdk/communication/communication-callingserver/test/README.md b/sdk/communication/communication-callingserver/test/README.md new file mode 100644 index 000000000000..f3a54253ada2 --- /dev/null +++ b/sdk/communication/communication-callingserver/test/README.md @@ -0,0 +1,19 @@ +# Testing + +To test this project, make sure to build it by following our [building instructions](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md#building), then follow the [testing instructions](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md#testing). + +You can use existing Azure resources for the live tests, or generate new ones by using our [New-TestResources.ps1](https://github.com/Azure/azure-sdk-for-js/blob/main/eng/common/TestResources/New-TestResources.ps1) script, which will use an [ARM template](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/communication/test-resources.json) that already has all of the the necessary configurations. + +The Azure resource that is used by the tests in this project is: + +- An existing Communication Services resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli]. + +To run the live tests, you will need to set the below environment variables: + +- `TEST_MODE`: Should have `live` assigned if you want to run live without recording. Assign `record` to run live with recording. +- `COMMUNICATION_LIVETEST_DYNAMIC_CONNECTION_STRING`: The primary connection string of the Communication Services resource in your account. + +[azure_sub]: https://azure.microsoft.com/free/ +[azure_portal]: https://portal.azure.com + +![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcommunication%2Fcommunication-identity%2FREADME.png) diff --git a/sdk/communication/communication-callingserver/test/public/utils/mockHttpClients.ts b/sdk/communication/communication-callingserver/test/public/utils/mockHttpClients.ts new file mode 100644 index 000000000000..08847892c8e4 --- /dev/null +++ b/sdk/communication/communication-callingserver/test/public/utils/mockHttpClients.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { HttpClient, WebResourceLike, HttpOperationResponse, HttpHeaders } from "@azure/core-http"; + +export const createMockHttpClient = >( + status: number = 200, + parsedBody?: T +): HttpClient => { + return { + async sendRequest(httpRequest: WebResourceLike): Promise { + return { + status, + headers: new HttpHeaders(), + request: httpRequest, + parsedBody + }; + } + }; +}; + +export const baseHttpClient: HttpClient = createMockHttpClient(); + +export const base202HttpClient: HttpClient = createMockHttpClient(202); diff --git a/sdk/communication/communication-callingserver/tsconfig.json b/sdk/communication/communication-callingserver/tsconfig.json new file mode 100644 index 000000000000..7713229ab4b7 --- /dev/null +++ b/sdk/communication/communication-callingserver/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../../../tsconfig.package", + "compilerOptions": { + "outDir": "./dist-esm", + "declarationDir": "./types", + "paths": { + "@azure/communication-callingserver": ["./src/index"] + } + }, + "include": ["src/**/*.ts", "test/**/*.ts", "samples-dev/**/*.ts"] +}