From 88eb71574a46e69e677ae15f308adead69ae3591 Mon Sep 17 00:00:00 2001 From: reenulnu Date: Wed, 7 Aug 2024 16:41:18 +0530 Subject: [PATCH 1/2] added offline capability --- .../src/components/OfflineAPIs.tsx | 56 +++++++++++++++++++ apps/teams-test-app/src/pages/TestApp.tsx | 2 + packages/teams-js/src/internal/telemetry.ts | 1 + packages/teams-js/src/public/index.ts | 1 + packages/teams-js/src/public/offline.ts | 55 ++++++++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 apps/teams-test-app/src/components/OfflineAPIs.tsx create mode 100644 packages/teams-js/src/public/offline.ts diff --git a/apps/teams-test-app/src/components/OfflineAPIs.tsx b/apps/teams-test-app/src/components/OfflineAPIs.tsx new file mode 100644 index 0000000000..8dd451d738 --- /dev/null +++ b/apps/teams-test-app/src/components/OfflineAPIs.tsx @@ -0,0 +1,56 @@ +import { offline, SdkError } from '@microsoft/teams-js'; +import React, { ReactElement } from 'react'; + +import { ApiWithoutInput, ApiWithTextInput } from './utils'; +import { ModuleWrapper } from './utils/ModuleWrapper'; +import { off } from 'process'; + +const CheckOfflineCapability = (): React.ReactElement => + ApiWithoutInput({ + name: 'CheckOfflineCapability', + title: 'Check offline Capability', + onClick: async () => `offline ${offline.isSupported() ? 'is' : 'is not'} supported`, + }); + + const EnableOfflineMode = (): React.ReactElement => + ApiWithTextInput({ + name: 'CheckOfflineCapability', + title: 'CheckOfflineCapability', + onClick: { + validateInput: (input) => { + if (!input.invalidationUrl) { + throw new Error('invalidationurl is needed'); + } + }, + submit: { + withPromise: async (input) => { + await offline.enableOfflineMode(input); + return 'opened'; + }, + withCallback: (input, setResult) => { + const callback = (error?: SdkError): void => { + if (error) { + setResult(JSON.stringify(error)); + } + }; + // remove after updating e2e tests + offline + .enableOfflineMode(input) + .then() + .catch((error) => callback(error)); + }, + }, + }, + defaultInput: '"https://www.microsoft.com"', + }); + + + +const OfflineAPIs = (): ReactElement => ( + + + + +); + +export default OfflineAPIs; \ No newline at end of file diff --git a/apps/teams-test-app/src/pages/TestApp.tsx b/apps/teams-test-app/src/pages/TestApp.tsx index 78ef804a75..94c131e774 100644 --- a/apps/teams-test-app/src/pages/TestApp.tsx +++ b/apps/teams-test-app/src/pages/TestApp.tsx @@ -62,6 +62,7 @@ import Version from '../components/Version'; import VideoAPIs from '../components/VideoEffectsApis'; import VisualMediaAPIs from '../components/VisualMediaAPIs'; import WebStorageAPIs from '../components/WebStorageAPIs'; +import OfflineAPIs from '../components/OfflineAPIs'; export const TestApp: React.FC = () => { const dialogWindowRef = React.useRef(null); @@ -129,6 +130,7 @@ export const TestApp: React.FC = () => { + diff --git a/packages/teams-js/src/internal/telemetry.ts b/packages/teams-js/src/internal/telemetry.ts index d7049ec8d5..557f21b286 100644 --- a/packages/teams-js/src/internal/telemetry.ts +++ b/packages/teams-js/src/internal/telemetry.ts @@ -297,6 +297,7 @@ export const enum ApiName { Sharing_History_GetContent = 'sharing.history.getContent', Sharing_ShareWebContent = 'sharing.shareWebContent', StageView_Open = 'stageView.open', + Offline_enableOfflineMode = 'offline.enableOfflineMode', Tasks_StartTask = 'tasks.startTask', Tasks_SubmitTask = 'tasks.submitTask', Tasks_UpdateTask = 'tasks.updateTask', diff --git a/packages/teams-js/src/public/index.ts b/packages/teams-js/src/public/index.ts index c496cbef71..76a984ac24 100644 --- a/packages/teams-js/src/public/index.ts +++ b/packages/teams-js/src/public/index.ts @@ -75,6 +75,7 @@ export { stageView } from './stageView'; export { version } from './version'; export { visualMedia } from './visualMedia'; export { webStorage } from './webStorage'; +export { offline } from './offline'; export { call } from './call'; export { appInitialization } from './appInitialization'; export { thirdPartyCloudStorage } from './thirdPartyCloudStorage'; diff --git a/packages/teams-js/src/public/offline.ts b/packages/teams-js/src/public/offline.ts new file mode 100644 index 0000000000..2fdd0e29b5 --- /dev/null +++ b/packages/teams-js/src/public/offline.ts @@ -0,0 +1,55 @@ +import { sendAndHandleSdkError } from '../internal/communication'; +import { ensureInitialized } from '../internal/internalAPIs'; +import { ApiName, ApiVersionNumber, getApiVersionTag } from '../internal/telemetry'; +import { errorNotSupportedOnPlatform, FrameContexts } from './constants'; +import { runtime } from './runtime'; + +/** + * Namespace to interact with the stage view specific part of the SDK. + * + * @beta + */ +export namespace offline { + /** + * Parameters to open a stage view. + */ + export interface OfflineParams { + /** + * The ID of the Teams application to be opened. + */ + invalidationUrl: string; + } + + /** + * + * Opens a stage view to display a Teams application + * @beta + * @param stageViewParams - The parameters to pass into the stage view. + * @returns Promise that resolves or rejects with an error once the stage view is closed. + */ + export function enableOfflineMode(offlineParams: OfflineParams): Promise { + return new Promise((resolve) => { + ensureInitialized(runtime); + + if (!isSupported()) { + throw errorNotSupportedOnPlatform; + } + + if (!offlineParams) { + throw new Error('[offline.enableOfflineMode] Offline params cannot be null'); + } + + resolve( + sendAndHandleSdkError( + getApiVersionTag(ApiVersionNumber.V_2, ApiName.Offline_enableOfflineMode), + 'offline.enableOfflineMode', + offlineParams, + ), + ); + }); + } + + export function isSupported(): boolean { + return ensureInitialized(runtime) && runtime.supports.offline ? true : false; + } +} From bc50c50c3c476de5e0fbe7d9c84763711445d7e4 Mon Sep 17 00:00:00 2001 From: reenulnu Date: Thu, 8 Aug 2024 14:28:22 +0530 Subject: [PATCH 2/2] name changes --- .../src/components/OfflineAPIs.tsx | 10 ++++---- packages/teams-js/src/public/offline.ts | 24 +++++++++---------- packages/teams-js/src/public/runtime.ts | 5 ++++ 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/apps/teams-test-app/src/components/OfflineAPIs.tsx b/apps/teams-test-app/src/components/OfflineAPIs.tsx index 8dd451d738..6c3a1957d7 100644 --- a/apps/teams-test-app/src/components/OfflineAPIs.tsx +++ b/apps/teams-test-app/src/components/OfflineAPIs.tsx @@ -13,7 +13,7 @@ const CheckOfflineCapability = (): React.ReactElement => }); const EnableOfflineMode = (): React.ReactElement => - ApiWithTextInput({ + ApiWithTextInput({ name: 'CheckOfflineCapability', title: 'CheckOfflineCapability', onClick: { @@ -24,8 +24,8 @@ const CheckOfflineCapability = (): React.ReactElement => }, submit: { withPromise: async (input) => { - await offline.enableOfflineMode(input); - return 'opened'; + await offline.enableOfflineMode(input); + return 'enabled'; }, withCallback: (input, setResult) => { const callback = (error?: SdkError): void => { @@ -33,7 +33,6 @@ const CheckOfflineCapability = (): React.ReactElement => setResult(JSON.stringify(error)); } }; - // remove after updating e2e tests offline .enableOfflineMode(input) .then() @@ -41,7 +40,8 @@ const CheckOfflineCapability = (): React.ReactElement => }, }, }, - defaultInput: '"https://www.microsoft.com"', + defaultInput: JSON.stringify({ + invalidationUrl: 'https://localhost:4000'}), }); diff --git a/packages/teams-js/src/public/offline.ts b/packages/teams-js/src/public/offline.ts index 2fdd0e29b5..b1bfeef105 100644 --- a/packages/teams-js/src/public/offline.ts +++ b/packages/teams-js/src/public/offline.ts @@ -1,33 +1,33 @@ import { sendAndHandleSdkError } from '../internal/communication'; import { ensureInitialized } from '../internal/internalAPIs'; import { ApiName, ApiVersionNumber, getApiVersionTag } from '../internal/telemetry'; -import { errorNotSupportedOnPlatform, FrameContexts } from './constants'; +import { errorNotSupportedOnPlatform } from './constants'; import { runtime } from './runtime'; /** - * Namespace to interact with the stage view specific part of the SDK. + * Namespace to interact with the offline specific part of the SDK. * * @beta */ export namespace offline { /** - * Parameters to open a stage view. + * Parameters to enable offline mode. */ - export interface OfflineParams { + export interface OfflineModeParams { /** - * The ID of the Teams application to be opened. + * The invalidation URL for the app. */ invalidationUrl: string; } /** * - * Opens a stage view to display a Teams application + * Enabled offline mode for the app * @beta - * @param stageViewParams - The parameters to pass into the stage view. - * @returns Promise that resolves or rejects with an error once the stage view is closed. + * @param offlineModeParams - The parameters to pass into the enable offline mode. + * @returns Promise that resolves or rejects with an error once the is closed. */ - export function enableOfflineMode(offlineParams: OfflineParams): Promise { + export function enableOfflineMode(offlineModeParams: OfflineModeParams): Promise { return new Promise((resolve) => { ensureInitialized(runtime); @@ -35,15 +35,15 @@ export namespace offline { throw errorNotSupportedOnPlatform; } - if (!offlineParams) { + if (!offlineModeParams) { throw new Error('[offline.enableOfflineMode] Offline params cannot be null'); } - + resolve( sendAndHandleSdkError( getApiVersionTag(ApiVersionNumber.V_2, ApiName.Offline_enableOfflineMode), 'offline.enableOfflineMode', - offlineParams, + offlineModeParams, ), ); }); diff --git a/packages/teams-js/src/public/runtime.ts b/packages/teams-js/src/public/runtime.ts index 5eb8918197..2f3a8ff383 100644 --- a/packages/teams-js/src/public/runtime.ts +++ b/packages/teams-js/src/public/runtime.ts @@ -78,6 +78,7 @@ interface IRuntimeV1 extends IBaseRuntime { readonly sharedFrame?: {}; }; readonly webStorage?: {}; + readonly offline?: {}; }; } @@ -142,6 +143,7 @@ interface IRuntimeV2 extends IBaseRuntime { readonly sharedFrame?: {}; }; readonly webStorage?: {}; + readonly offline?: {}; }; } @@ -214,6 +216,7 @@ interface IRuntimeV3 extends IBaseRuntime { readonly image?: {}; }; readonly webStorage?: {}; + readonly offline?: {}; }; } @@ -295,6 +298,7 @@ interface IRuntimeV4 extends IBaseRuntime { readonly image?: {}; }; readonly webStorage?: {}; + readonly offline?: {}; }; } // Constant used to set the runtime configuration @@ -370,6 +374,7 @@ export const versionAndPlatformAgnosticTeamsRuntimeConfig: Runtime = { video: { sharedFrame: {}, }, + offline: {}, }, };