Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Do not review]Offline capability support #2456

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions apps/teams-test-app/src/components/OfflineAPIs.tsx
Original file line number Diff line number Diff line change
@@ -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<offline.OfflineModeParams>({
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 'enabled';
},
withCallback: (input, setResult) => {
const callback = (error?: SdkError): void => {
if (error) {
setResult(JSON.stringify(error));
}
};
offline
.enableOfflineMode(input)
.then()
.catch((error) => callback(error));
},
},
},
defaultInput: JSON.stringify({
invalidationUrl: 'https://localhost:4000'}),
});



const OfflineAPIs = (): ReactElement => (
<ModuleWrapper title="Offline">
<CheckOfflineCapability />
<EnableOfflineMode />
</ModuleWrapper>
);

export default OfflineAPIs;
2 changes: 2 additions & 0 deletions apps/teams-test-app/src/pages/TestApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IAppWindow | null>(null);
Expand Down Expand Up @@ -129,6 +130,7 @@ export const TestApp: React.FC = () => {
<VideoAPIs />
<VideoExAPIs />
<VisualMediaAPIs />
<OfflineAPIs />
</div>
<Version />
</>
Expand Down
1 change: 1 addition & 0 deletions packages/teams-js/src/internal/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions packages/teams-js/src/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
55 changes: 55 additions & 0 deletions packages/teams-js/src/public/offline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { sendAndHandleSdkError } from '../internal/communication';
import { ensureInitialized } from '../internal/internalAPIs';
import { ApiName, ApiVersionNumber, getApiVersionTag } from '../internal/telemetry';
import { errorNotSupportedOnPlatform } from './constants';
import { runtime } from './runtime';

/**
* Namespace to interact with the offline specific part of the SDK.
*
* @beta
*/
export namespace offline {
/**
* Parameters to enable offline mode.
*/
export interface OfflineModeParams {
/**
* The invalidation URL for the app.
*/
invalidationUrl: string;
}

/**
*
* Enabled offline mode for the app
* @beta
* @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(offlineModeParams: OfflineModeParams): Promise<void> {
return new Promise((resolve) => {
ensureInitialized(runtime);

if (!isSupported()) {
throw errorNotSupportedOnPlatform;
}

if (!offlineModeParams) {
throw new Error('[offline.enableOfflineMode] Offline params cannot be null');
}

resolve(
sendAndHandleSdkError(
getApiVersionTag(ApiVersionNumber.V_2, ApiName.Offline_enableOfflineMode),
'offline.enableOfflineMode',
offlineModeParams,
),
);
});
}

export function isSupported(): boolean {
return ensureInitialized(runtime) && runtime.supports.offline ? true : false;
}
}
5 changes: 5 additions & 0 deletions packages/teams-js/src/public/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ interface IRuntimeV1 extends IBaseRuntime {
readonly sharedFrame?: {};
};
readonly webStorage?: {};
readonly offline?: {};
};
}

Expand Down Expand Up @@ -142,6 +143,7 @@ interface IRuntimeV2 extends IBaseRuntime {
readonly sharedFrame?: {};
};
readonly webStorage?: {};
readonly offline?: {};
};
}

Expand Down Expand Up @@ -214,6 +216,7 @@ interface IRuntimeV3 extends IBaseRuntime {
readonly image?: {};
};
readonly webStorage?: {};
readonly offline?: {};
};
}

Expand Down Expand Up @@ -295,6 +298,7 @@ interface IRuntimeV4 extends IBaseRuntime {
readonly image?: {};
};
readonly webStorage?: {};
readonly offline?: {};
};
}
// Constant used to set the runtime configuration
Expand Down Expand Up @@ -370,6 +374,7 @@ export const versionAndPlatformAgnosticTeamsRuntimeConfig: Runtime = {
video: {
sharedFrame: {},
},
offline: {},
},
};

Expand Down