@itwin/core-mobile 4.1.0-dev.7 → 4.1.0-dev.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/backend/MobileHost.js +2 -2
- package/lib/cjs/backend/MobileHost.js.map +1 -1
- package/lib/cjs/common/MobileAppChannel.d.ts +4 -3
- package/lib/cjs/common/MobileAppChannel.d.ts.map +1 -1
- package/lib/cjs/common/MobileAppChannel.js +5 -4
- package/lib/cjs/common/MobileAppChannel.js.map +1 -1
- package/lib/cjs/frontend/MobileApp.js +2 -2
- package/lib/cjs/frontend/MobileApp.js.map +1 -1
- package/package.json +10 -10
|
@@ -40,7 +40,7 @@ class MobileDevice {
|
|
|
40
40
|
}
|
|
41
41
|
exports.MobileDevice = MobileDevice;
|
|
42
42
|
class MobileAppHandler extends core_backend_1.IpcHandler {
|
|
43
|
-
get channelName() { return MobileAppChannel_1.mobileAppChannel; }
|
|
43
|
+
get channelName() { return MobileAppChannel_1.mobileAppStrings.mobileAppChannel; }
|
|
44
44
|
async reconnect(connection) {
|
|
45
45
|
MobileHost.reconnect(connection);
|
|
46
46
|
}
|
|
@@ -55,7 +55,7 @@ class MobileHost {
|
|
|
55
55
|
static get device() { return this._device; }
|
|
56
56
|
/** Send a notification to the MobileApp connected to this MobileHost. */
|
|
57
57
|
static notifyMobileFrontend(methodName, ...args) {
|
|
58
|
-
return core_backend_1.IpcHost.send(MobileAppChannel_1.mobileAppNotify, methodName, ...args);
|
|
58
|
+
return core_backend_1.IpcHost.send(MobileAppChannel_1.mobileAppStrings.mobileAppNotify, methodName, ...args);
|
|
59
59
|
}
|
|
60
60
|
/** @internal */
|
|
61
61
|
static reconnect(connection) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileHost.js","sourceRoot":"","sources":["../../../src/backend/MobileHost.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAA4E;AAC5E,sDAAsF;AACtF,oD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EAAE,CAAC;QAE3F,MAAM,UAAU,GAAG,GAAG,EAAE,UAAU,IAAI,EAAE,CAAC;QACzC,UAAU,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QACrD,MAAM,yBAAU,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;QAEjD,IAAI,sBAAO,CAAC,OAAO;YACjB,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAE9B,MAAM,aAAa,GAAG,GAAG,EAAE,UAAU,EAAE,aAAa,IAAI,EAAE,CAAC;QAE3D,mCAAgB,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IACjD,CAAC;;AA1GsB,0BAAe,GAAG,IAAI,sBAAO,EAAE,CAAC;AAChC,+BAAoB,GAAG,IAAI,sBAAO,EAAE,CAAC;AACrC,4BAAiB,GAAG,IAAI,sBAAO,EAAE,CAAC;AAClC,4BAAiB,GAAG,IAAI,sBAAO,EAAE,CAAC;AAClC,0BAAe,GAAG,IAAI,sBAAO,EAAE,CAAC;AAChC,mCAAwB,GAAG,IAAI,sBAAO,EAAiF,CAAC;AARpI,gCAAU","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { AccessToken, BeEvent, BriefcaseStatus } from \"@itwin/core-bentley\";\r\nimport { IpcHandler, IpcHost, NativeHost, NativeHostOpts } from \"@itwin/core-backend\";\r\nimport { IpcWebSocketBackend, RpcInterfaceDefinition } from \"@itwin/core-common\";\r\nimport { CancelRequest, DownloadFailed, UserCancelledError } from \"./MobileFileHandler\";\r\nimport { ProgressCallback } from \"./Request\";\r\nimport { mobileAppChannel, mobileAppNotify } from \"../common/MobileAppChannel\";\r\nimport { BatteryState, DeviceEvents, MobileAppFunctions, MobileNotifications, Orientation } from \"../common/MobileAppProps\";\r\nimport { MobileRpcManager } from \"../common/MobileRpcManager\";\r\nimport { MobileAuthorizationBackend } from \"./MobileAuthorizationBackend\";\r\nimport { setupMobileRpc } from \"./MobileRpcServer\";\r\n\r\n/** @beta */\r\nexport type MobileCompletionCallback = (downloadUrl: string, downloadFileUrl: string, cancelled: boolean, err?: string) => void;\r\n/** @beta */\r\nexport type MobileProgressCallback = (bytesWritten: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => void;\r\n/** @beta */\r\nexport type MobileCancelCallback = () => boolean;\r\n\r\n/** @beta */\r\nexport interface DownloadTask {\r\n url: string;\r\n downloadPath: string;\r\n isDetached: boolean;\r\n isRunning: boolean;\r\n totalBytes?: number;\r\n doneBytes?: number;\r\n cancelId?: number;\r\n isBackground?: boolean;\r\n cancel?: MobileCancelCallback;\r\n toBackground: () => boolean;\r\n toForeground: () => boolean;\r\n}\r\n\r\n/** @beta */\r\nexport abstract class MobileDevice {\r\n public emit(eventName: DeviceEvents, ...args: any[]) {\r\n switch (eventName) {\r\n case \"memoryWarning\":\r\n MobileHost.onMemoryWarning.raiseEvent(...args);\r\n break;\r\n case \"orientationChanged\":\r\n MobileHost.onOrientationChanged.raiseEvent(...args);\r\n break;\r\n case \"enterForeground\":\r\n MobileHost.onEnterForeground.raiseEvent(...args);\r\n break;\r\n case \"enterBackground\":\r\n MobileHost.onEnterBackground.raiseEvent(...args);\r\n break;\r\n case \"willTerminate\":\r\n MobileHost.onWillTerminate.raiseEvent(...args);\r\n break;\r\n case \"authAccessTokenChanged\":\r\n MobileHost.onAuthAccessTokenChanged.raiseEvent(args[0], args[1]);\r\n break;\r\n }\r\n }\r\n\r\n public abstract getOrientation(): Orientation;\r\n public abstract getBatteryState(): BatteryState;\r\n public abstract getBatteryLevel(): number;\r\n public abstract createDownloadTask(downloadUrl: string, isBackground: boolean, downloadTo: string, completion: MobileCompletionCallback, progress?: MobileProgressCallback): number;\r\n public abstract cancelDownloadTask(cancelId: number): boolean;\r\n public abstract getDownloadTasks(): DownloadTask[];\r\n public abstract resumeDownloadInForeground(requestId: number): boolean;\r\n public abstract resumeDownloadInBackground(requestId: number): boolean;\r\n public abstract reconnect(connection: number): void;\r\n public abstract authGetAccessToken(callback: (accessToken?: string, expirationDate?: string, err?: string) => void): void;\r\n}\r\n\r\nclass MobileAppHandler extends IpcHandler implements MobileAppFunctions {\r\n public get channelName() { return mobileAppChannel; }\r\n public async reconnect(connection: number) {\r\n MobileHost.reconnect(connection);\r\n }\r\n public async getAccessToken() {\r\n return MobileHost.authGetAccessToken();\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport interface MobileHostOpts extends NativeHostOpts {\r\n mobileHost?: {\r\n device?: MobileDevice;\r\n /** list of RPC interface definitions to register */\r\n rpcInterfaces?: RpcInterfaceDefinition[];\r\n };\r\n}\r\n\r\n/**\r\n * @beta\r\n */\r\nexport class MobileHost {\r\n private static _device?: MobileDevice;\r\n public static get device() { return this._device!; }\r\n public static readonly onMemoryWarning = new BeEvent();\r\n public static readonly onOrientationChanged = new BeEvent();\r\n public static readonly onEnterForeground = new BeEvent();\r\n public static readonly onEnterBackground = new BeEvent();\r\n public static readonly onWillTerminate = new BeEvent();\r\n public static readonly onAuthAccessTokenChanged = new BeEvent<(accessToken: string | undefined, expirationDate: string | undefined) => void>();\r\n\r\n /** Send a notification to the MobileApp connected to this MobileHost. */\r\n public static notifyMobileFrontend<T extends keyof MobileNotifications>(methodName: T, ...args: Parameters<MobileNotifications[T]>) {\r\n return IpcHost.send(mobileAppNotify, methodName, ...args);\r\n }\r\n\r\n /** @internal */\r\n public static reconnect(connection: number) {\r\n this.device.reconnect(connection);\r\n }\r\n\r\n /** @internal */\r\n public static async authGetAccessToken() {\r\n return new Promise<[AccessToken, string]>((resolve, reject) => {\r\n this.device.authGetAccessToken((tokenString?: AccessToken, expirationDate?: string, error?: string) => {\r\n if (error) {\r\n reject(error);\r\n } else {\r\n resolve([tokenString ?? \"\", expirationDate ?? \"\"]);\r\n }\r\n });\r\n });\r\n }\r\n\r\n /** @internal */\r\n public static async downloadFile(downloadUrl: string, downloadTo: string, progress?: ProgressCallback, cancelRequest?: CancelRequest): Promise<void> {\r\n return new Promise<void>((resolve, reject) => {\r\n\r\n let progressCb: MobileProgressCallback | undefined;\r\n let lastReportedOn = Date.now();\r\n const minTimeBeforeReportingProgress = 1000;\r\n if (progress) {\r\n progressCb = (_bytesWritten: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => {\r\n const currentTime = Date.now();\r\n const timeSinceLastEvent = currentTime - lastReportedOn;\r\n // report all event for last 5 Mbs so we never miss 100% progress event\r\n const lastEvent = (totalBytesExpectedToWrite - totalBytesWritten) < 1024 * 1024 * 5;\r\n if (timeSinceLastEvent < minTimeBeforeReportingProgress && !lastEvent)\r\n return;\r\n\r\n lastReportedOn = currentTime;\r\n const percent = Number((100 * (totalBytesWritten / totalBytesExpectedToWrite)).toFixed(2));\r\n progress({ total: totalBytesExpectedToWrite, loaded: totalBytesWritten, percent });\r\n };\r\n }\r\n const requestId = this.device.createDownloadTask(downloadUrl, false, downloadTo, (_downloadUrl: string, _downloadFileUrl: string, cancelled: boolean, err?: string) => {\r\n if (cancelled)\r\n reject(new UserCancelledError(BriefcaseStatus.DownloadCancelled, \"User cancelled download\"));\r\n else if (err)\r\n reject(new DownloadFailed(400, \"Download failed\"));\r\n else\r\n resolve();\r\n }, progressCb);\r\n if (cancelRequest) {\r\n // eslint-disable-next-line @typescript-eslint/unbound-method\r\n cancelRequest.cancel = () => this.device.cancelDownloadTask(requestId);\r\n }\r\n });\r\n }\r\n\r\n public static get isValid() { return undefined !== this._device; }\r\n\r\n /** Start the backend of a mobile app. */\r\n public static async startup(opt?: MobileHostOpts): Promise<void> {\r\n const authorizationClient = new MobileAuthorizationBackend();\r\n if (!this.isValid) {\r\n this._device = opt?.mobileHost?.device ?? new (MobileDevice as any)();\r\n // set global device interface.\r\n (global as any).__iTwinJsNativeBridge = this._device;\r\n this.onMemoryWarning.addListener(() => {\r\n MobileHost.notifyMobileFrontend(\"notifyMemoryWarning\");\r\n });\r\n this.onOrientationChanged.addListener(() => {\r\n MobileHost.notifyMobileFrontend(\"notifyOrientationChanged\");\r\n });\r\n this.onWillTerminate.addListener(() => {\r\n MobileHost.notifyMobileFrontend(\"notifyWillTerminate\");\r\n });\r\n this.onAuthAccessTokenChanged.addListener((accessToken: string | undefined, expirationDate: string | undefined) => {\r\n authorizationClient.setAccessToken(accessToken, expirationDate);\r\n MobileHost.notifyMobileFrontend(\"notifyAuthAccessTokenChanged\", accessToken, expirationDate);\r\n });\r\n\r\n // following will provide impl for device specific api.\r\n setupMobileRpc();\r\n }\r\n\r\n const socket = opt?.ipcHost?.socket ?? new IpcWebSocketBackend();\r\n opt = { ...opt, mobileHost: { ...opt?.mobileHost }, ipcHost: { ...opt?.ipcHost, socket } };\r\n\r\n const iModelHost = opt?.iModelHost ?? {};\r\n iModelHost.authorizationClient = authorizationClient;\r\n await NativeHost.startup({ ...opt, iModelHost });\r\n\r\n if (IpcHost.isValid)\r\n MobileAppHandler.register();\r\n\r\n const rpcInterfaces = opt?.mobileHost?.rpcInterfaces ?? [];\r\n\r\n MobileRpcManager.initializeImpl(rpcInterfaces);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"MobileHost.js","sourceRoot":"","sources":["../../../src/backend/MobileHost.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAA4E;AAC5E,sDAAsF;AACtF,oDAAiF;AACjF,2DAAwF;AAExF,iEAA8D;AAE9D,iEAA8D;AAC9D,6EAA0E;AAC1E,uDAAmD;AAwBnD,YAAY;AACZ,MAAsB,YAAY;IACzB,IAAI,CAAC,SAAuB,EAAE,GAAG,IAAW;QACjD,QAAQ,SAAS,EAAE;YACjB,KAAK,eAAe;gBAClB,UAAU,CAAC,eAAe,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;gBAC/C,MAAM;YACR,KAAK,oBAAoB;gBACvB,UAAU,CAAC,oBAAoB,CAAC,UAAU,CAAC,GAAG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,aAAa,IAAI,EAAE,CAAC;QAE3D,mCAAgB,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IACjD,CAAC;;AA1GsB,0BAAe,GAAG,IAAI,sBAAO,EAAE,CAAC;AAChC,+BAAoB,GAAG,IAAI,sBAAO,EAAE,CAAC;AACrC,4BAAiB,GAAG,IAAI,sBAAO,EAAE,CAAC;AAClC,4BAAiB,GAAG,IAAI,sBAAO,EAAE,CAAC;AAClC,0BAAe,GAAG,IAAI,sBAAO,EAAE,CAAC;AAChC,mCAAwB,GAAG,IAAI,sBAAO,EAAiF,CAAC;AARpI,gCAAU","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { AccessToken, BeEvent, BriefcaseStatus } from \"@itwin/core-bentley\";\r\nimport { IpcHandler, IpcHost, NativeHost, NativeHostOpts } from \"@itwin/core-backend\";\r\nimport { IpcWebSocketBackend, RpcInterfaceDefinition } from \"@itwin/core-common\";\r\nimport { CancelRequest, DownloadFailed, UserCancelledError } from \"./MobileFileHandler\";\r\nimport { ProgressCallback } from \"./Request\";\r\nimport { mobileAppStrings } from \"../common/MobileAppChannel\";\r\nimport { BatteryState, DeviceEvents, MobileAppFunctions, MobileNotifications, Orientation } from \"../common/MobileAppProps\";\r\nimport { MobileRpcManager } from \"../common/MobileRpcManager\";\r\nimport { MobileAuthorizationBackend } from \"./MobileAuthorizationBackend\";\r\nimport { setupMobileRpc } from \"./MobileRpcServer\";\r\n\r\n/** @beta */\r\nexport type MobileCompletionCallback = (downloadUrl: string, downloadFileUrl: string, cancelled: boolean, err?: string) => void;\r\n/** @beta */\r\nexport type MobileProgressCallback = (bytesWritten: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => void;\r\n/** @beta */\r\nexport type MobileCancelCallback = () => boolean;\r\n\r\n/** @beta */\r\nexport interface DownloadTask {\r\n url: string;\r\n downloadPath: string;\r\n isDetached: boolean;\r\n isRunning: boolean;\r\n totalBytes?: number;\r\n doneBytes?: number;\r\n cancelId?: number;\r\n isBackground?: boolean;\r\n cancel?: MobileCancelCallback;\r\n toBackground: () => boolean;\r\n toForeground: () => boolean;\r\n}\r\n\r\n/** @beta */\r\nexport abstract class MobileDevice {\r\n public emit(eventName: DeviceEvents, ...args: any[]) {\r\n switch (eventName) {\r\n case \"memoryWarning\":\r\n MobileHost.onMemoryWarning.raiseEvent(...args);\r\n break;\r\n case \"orientationChanged\":\r\n MobileHost.onOrientationChanged.raiseEvent(...args);\r\n break;\r\n case \"enterForeground\":\r\n MobileHost.onEnterForeground.raiseEvent(...args);\r\n break;\r\n case \"enterBackground\":\r\n MobileHost.onEnterBackground.raiseEvent(...args);\r\n break;\r\n case \"willTerminate\":\r\n MobileHost.onWillTerminate.raiseEvent(...args);\r\n break;\r\n case \"authAccessTokenChanged\":\r\n MobileHost.onAuthAccessTokenChanged.raiseEvent(args[0], args[1]);\r\n break;\r\n }\r\n }\r\n\r\n public abstract getOrientation(): Orientation;\r\n public abstract getBatteryState(): BatteryState;\r\n public abstract getBatteryLevel(): number;\r\n public abstract createDownloadTask(downloadUrl: string, isBackground: boolean, downloadTo: string, completion: MobileCompletionCallback, progress?: MobileProgressCallback): number;\r\n public abstract cancelDownloadTask(cancelId: number): boolean;\r\n public abstract getDownloadTasks(): DownloadTask[];\r\n public abstract resumeDownloadInForeground(requestId: number): boolean;\r\n public abstract resumeDownloadInBackground(requestId: number): boolean;\r\n public abstract reconnect(connection: number): void;\r\n public abstract authGetAccessToken(callback: (accessToken?: string, expirationDate?: string, err?: string) => void): void;\r\n}\r\n\r\nclass MobileAppHandler extends IpcHandler implements MobileAppFunctions {\r\n public get channelName() { return mobileAppStrings.mobileAppChannel; }\r\n public async reconnect(connection: number) {\r\n MobileHost.reconnect(connection);\r\n }\r\n public async getAccessToken() {\r\n return MobileHost.authGetAccessToken();\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport interface MobileHostOpts extends NativeHostOpts {\r\n mobileHost?: {\r\n device?: MobileDevice;\r\n /** list of RPC interface definitions to register */\r\n rpcInterfaces?: RpcInterfaceDefinition[];\r\n };\r\n}\r\n\r\n/**\r\n * @beta\r\n */\r\nexport class MobileHost {\r\n private static _device?: MobileDevice;\r\n public static get device() { return this._device!; }\r\n public static readonly onMemoryWarning = new BeEvent();\r\n public static readonly onOrientationChanged = new BeEvent();\r\n public static readonly onEnterForeground = new BeEvent();\r\n public static readonly onEnterBackground = new BeEvent();\r\n public static readonly onWillTerminate = new BeEvent();\r\n public static readonly onAuthAccessTokenChanged = new BeEvent<(accessToken: string | undefined, expirationDate: string | undefined) => void>();\r\n\r\n /** Send a notification to the MobileApp connected to this MobileHost. */\r\n public static notifyMobileFrontend<T extends keyof MobileNotifications>(methodName: T, ...args: Parameters<MobileNotifications[T]>) {\r\n return IpcHost.send(mobileAppStrings.mobileAppNotify, methodName, ...args);\r\n }\r\n\r\n /** @internal */\r\n public static reconnect(connection: number) {\r\n this.device.reconnect(connection);\r\n }\r\n\r\n /** @internal */\r\n public static async authGetAccessToken() {\r\n return new Promise<[AccessToken, string]>((resolve, reject) => {\r\n this.device.authGetAccessToken((tokenString?: AccessToken, expirationDate?: string, error?: string) => {\r\n if (error) {\r\n reject(error);\r\n } else {\r\n resolve([tokenString ?? \"\", expirationDate ?? \"\"]);\r\n }\r\n });\r\n });\r\n }\r\n\r\n /** @internal */\r\n public static async downloadFile(downloadUrl: string, downloadTo: string, progress?: ProgressCallback, cancelRequest?: CancelRequest): Promise<void> {\r\n return new Promise<void>((resolve, reject) => {\r\n\r\n let progressCb: MobileProgressCallback | undefined;\r\n let lastReportedOn = Date.now();\r\n const minTimeBeforeReportingProgress = 1000;\r\n if (progress) {\r\n progressCb = (_bytesWritten: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => {\r\n const currentTime = Date.now();\r\n const timeSinceLastEvent = currentTime - lastReportedOn;\r\n // report all event for last 5 Mbs so we never miss 100% progress event\r\n const lastEvent = (totalBytesExpectedToWrite - totalBytesWritten) < 1024 * 1024 * 5;\r\n if (timeSinceLastEvent < minTimeBeforeReportingProgress && !lastEvent)\r\n return;\r\n\r\n lastReportedOn = currentTime;\r\n const percent = Number((100 * (totalBytesWritten / totalBytesExpectedToWrite)).toFixed(2));\r\n progress({ total: totalBytesExpectedToWrite, loaded: totalBytesWritten, percent });\r\n };\r\n }\r\n const requestId = this.device.createDownloadTask(downloadUrl, false, downloadTo, (_downloadUrl: string, _downloadFileUrl: string, cancelled: boolean, err?: string) => {\r\n if (cancelled)\r\n reject(new UserCancelledError(BriefcaseStatus.DownloadCancelled, \"User cancelled download\"));\r\n else if (err)\r\n reject(new DownloadFailed(400, \"Download failed\"));\r\n else\r\n resolve();\r\n }, progressCb);\r\n if (cancelRequest) {\r\n // eslint-disable-next-line @typescript-eslint/unbound-method\r\n cancelRequest.cancel = () => this.device.cancelDownloadTask(requestId);\r\n }\r\n });\r\n }\r\n\r\n public static get isValid() { return undefined !== this._device; }\r\n\r\n /** Start the backend of a mobile app. */\r\n public static async startup(opt?: MobileHostOpts): Promise<void> {\r\n const authorizationClient = new MobileAuthorizationBackend();\r\n if (!this.isValid) {\r\n this._device = opt?.mobileHost?.device ?? new (MobileDevice as any)();\r\n // set global device interface.\r\n (global as any).__iTwinJsNativeBridge = this._device;\r\n this.onMemoryWarning.addListener(() => {\r\n MobileHost.notifyMobileFrontend(\"notifyMemoryWarning\");\r\n });\r\n this.onOrientationChanged.addListener(() => {\r\n MobileHost.notifyMobileFrontend(\"notifyOrientationChanged\");\r\n });\r\n this.onWillTerminate.addListener(() => {\r\n MobileHost.notifyMobileFrontend(\"notifyWillTerminate\");\r\n });\r\n this.onAuthAccessTokenChanged.addListener((accessToken: string | undefined, expirationDate: string | undefined) => {\r\n authorizationClient.setAccessToken(accessToken, expirationDate);\r\n MobileHost.notifyMobileFrontend(\"notifyAuthAccessTokenChanged\", accessToken, expirationDate);\r\n });\r\n\r\n // following will provide impl for device specific api.\r\n setupMobileRpc();\r\n }\r\n\r\n const socket = opt?.ipcHost?.socket ?? new IpcWebSocketBackend();\r\n opt = { ...opt, mobileHost: { ...opt?.mobileHost }, ipcHost: { ...opt?.ipcHost, socket } };\r\n\r\n const iModelHost = opt?.iModelHost ?? {};\r\n iModelHost.authorizationClient = authorizationClient;\r\n await NativeHost.startup({ ...opt, iModelHost });\r\n\r\n if (IpcHost.isValid)\r\n MobileAppHandler.register();\r\n\r\n const rpcInterfaces = opt?.mobileHost?.rpcInterfaces ?? [];\r\n\r\n MobileRpcManager.initializeImpl(rpcInterfaces);\r\n }\r\n}\r\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare const mobileAppStrings: {
|
|
3
|
+
readonly mobileAppChannel: "itwinjs-core/mobileApp";
|
|
4
|
+
readonly mobileAppNotify: "itwinjs-core/mobileApp-notify";
|
|
5
|
+
};
|
|
5
6
|
//# sourceMappingURL=MobileAppChannel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileAppChannel.d.ts","sourceRoot":"","sources":["../../../src/common/MobileAppChannel.ts"],"names":[],"mappings":"AAKA,gBAAgB;AAChB,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"MobileAppChannel.d.ts","sourceRoot":"","sources":["../../../src/common/MobileAppChannel.ts"],"names":[],"mappings":"AAKA,gBAAgB;AAChB,eAAO,MAAM,gBAAgB;;;CAGnB,CAAC"}
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
7
|
+
exports.mobileAppStrings = void 0;
|
|
8
8
|
/** @internal */
|
|
9
|
-
exports.
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
exports.mobileAppStrings = {
|
|
10
|
+
mobileAppChannel: "itwinjs-core/mobileApp",
|
|
11
|
+
mobileAppNotify: "itwinjs-core/mobileApp-notify",
|
|
12
|
+
};
|
|
12
13
|
//# sourceMappingURL=MobileAppChannel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileAppChannel.js","sourceRoot":"","sources":["../../../src/common/MobileAppChannel.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,gBAAgB;AACH,QAAA,gBAAgB,GAAG,
|
|
1
|
+
{"version":3,"file":"MobileAppChannel.js","sourceRoot":"","sources":["../../../src/common/MobileAppChannel.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,gBAAgB;AACH,QAAA,gBAAgB,GAAG;IAC9B,gBAAgB,EAAE,wBAAwB;IAC1C,eAAe,EAAE,+BAA+B;CACxC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @internal */\r\nexport const mobileAppStrings = {\r\n mobileAppChannel: \"itwinjs-core/mobileApp\",\r\n mobileAppNotify: \"itwinjs-core/mobileApp-notify\",\r\n} as const;\r\n"]}
|
|
@@ -13,7 +13,7 @@ const MobileRpcManager_1 = require("../common/MobileRpcManager");
|
|
|
13
13
|
const MobileAuthorizationFrontend_1 = require("./MobileAuthorizationFrontend");
|
|
14
14
|
/** receive notifications from backend */
|
|
15
15
|
class MobileAppNotifyHandler extends core_frontend_1.NotificationHandler {
|
|
16
|
-
get channelName() { return MobileAppChannel_1.mobileAppNotify; }
|
|
16
|
+
get channelName() { return MobileAppChannel_1.mobileAppStrings.mobileAppNotify; }
|
|
17
17
|
notifyMemoryWarning() {
|
|
18
18
|
core_bentley_1.Logger.logWarning("mobileApp", "Low memory warning");
|
|
19
19
|
if (MobileApp.onMemoryWarning.numberOfListeners === 0) {
|
|
@@ -30,7 +30,7 @@ class MobileAppNotifyHandler extends core_frontend_1.NotificationHandler {
|
|
|
30
30
|
/** @beta */
|
|
31
31
|
class MobileApp {
|
|
32
32
|
static async callBackend(methodName, ...args) {
|
|
33
|
-
return core_frontend_1.IpcApp.callIpcChannel(MobileAppChannel_1.mobileAppChannel, methodName, ...args);
|
|
33
|
+
return core_frontend_1.IpcApp.callIpcChannel(MobileAppChannel_1.mobileAppStrings.mobileAppChannel, methodName, ...args);
|
|
34
34
|
}
|
|
35
35
|
static get isValid() { return this._isValid; }
|
|
36
36
|
/** @beta */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileApp.js","sourceRoot":"","sources":["../../../src/frontend/MobileApp.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAAyF;AACzF,oDAA0G;AAC1G,wDAA+G;AAC/G,
|
|
1
|
+
{"version":3,"file":"MobileApp.js","sourceRoot":"","sources":["../../../src/frontend/MobileApp.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAAyF;AACzF,oDAA0G;AAC1G,wDAA+G;AAC/G,iEAA8D;AAE9D,iEAA8D;AAC9D,+EAA4E;AAK5E,yCAAyC;AACzC,MAAM,sBAAuB,SAAQ,mCAAmB;IACtD,IAAW,WAAW,KAAK,OAAO,mCAAgB,CAAC,eAAe,CAAC,CAAC,CAAC;IAE9D,mBAAmB;QACxB,qBAAM,CAAC,UAAU,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;QACrD,IAAI,SAAS,CAAC,eAAe,CAAC,iBAAiB,KAAK,CAAC,EAAE;YACrD,KAAK,CAAC,oBAAoB,CAAC,CAAC;SAC7B;QACD,SAAS,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC;IACzC,CAAC;IACM,wBAAwB,KAAK,SAAS,CAAC,oBAAoB,CAAC,UAAU,EAAE,CAAC,CAAC,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E,CAAC,CAAC,aAAa;QACxD,MAAM,yBAAS,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAC;QAEvE,sBAAsB,CAAC,QAAQ,EAAE,CAAC,CAAC,sCAAsC;IAC3E,CAAC;;AApCa,yBAAe,GAAG,IAAI,sBAAO,EAAc,CAAC;AAC5C,8BAAoB,GAAG,IAAI,sBAAO,EAAc,CAAC;AACjD,2BAAiB,GAAG,IAAI,sBAAO,EAAc,CAAC;AAC9C,2BAAiB,GAAG,IAAI,sBAAO,EAAc,CAAC;AAC9C,yBAAe,GAAG,IAAI,sBAAO,EAAc,CAAC;AAC5C,kCAAwB,GAAG,IAAI,sBAAO,EAAiF,CAAC;AAKvH,kBAAQ,GAAG,KAAK,CAAC;AAXrB,8BAAS;AAwCtB;;;;EAIE;AACF,SAAS,0BAA0B;IAChC,MAAc,CAAC,uBAAuB,GAAG,CAAC,GAAyB,EAAE,EAAE;QACtE,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,SAAS,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAC;SAC1C;aAAM,IAAI,GAAG,KAAK,QAAQ,EAAE;YAC3B,SAAS,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAC;SAC1C;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { AsyncMethodsOf, BeEvent, Logger, PromiseReturnType } from \"@itwin/core-bentley\";\r\nimport { IModelReadRpcInterface, IModelTileRpcInterface, IpcWebSocketFrontend } from \"@itwin/core-common\";\r\nimport { IModelAppOptions, IpcApp, NativeApp, NativeAppOpts, NotificationHandler } from \"@itwin/core-frontend\";\r\nimport { mobileAppStrings } from \"../common/MobileAppChannel\";\r\nimport { MobileAppFunctions, MobileNotifications } from \"../common/MobileAppProps\";\r\nimport { MobileRpcManager } from \"../common/MobileRpcManager\";\r\nimport { MobileAuthorizationFrontend } from \"./MobileAuthorizationFrontend\";\r\n\r\n/** @beta */\r\nexport type MobileAppOpts = NativeAppOpts & { iModelApp: { authorizationClient?: never } };\r\n\r\n/** receive notifications from backend */\r\nclass MobileAppNotifyHandler extends NotificationHandler implements MobileNotifications {\r\n public get channelName() { return mobileAppStrings.mobileAppNotify; }\r\n\r\n public notifyMemoryWarning() {\r\n Logger.logWarning(\"mobileApp\", \"Low memory warning\");\r\n if (MobileApp.onMemoryWarning.numberOfListeners === 0) {\r\n alert(\"Low memory warning\");\r\n }\r\n MobileApp.onMemoryWarning.raiseEvent();\r\n }\r\n public notifyOrientationChanged() { MobileApp.onOrientationChanged.raiseEvent(); }\r\n public notifyWillTerminate() { MobileApp.onWillTerminate.raiseEvent(); }\r\n public notifyAuthAccessTokenChanged(accessToken: string | undefined, expirationDate: string | undefined) {\r\n MobileApp.onAuthAccessTokenChanged.raiseEvent(accessToken, expirationDate);\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport class MobileApp {\r\n public static onMemoryWarning = new BeEvent<() => void>();\r\n public static onOrientationChanged = new BeEvent<() => void>();\r\n public static onEnterForeground = new BeEvent<() => void>();\r\n public static onEnterBackground = new BeEvent<() => void>();\r\n public static onWillTerminate = new BeEvent<() => void>();\r\n public static onAuthAccessTokenChanged = new BeEvent<(accessToken: string | undefined, expirationDate: string | undefined) => void>();\r\n public static async callBackend<T extends AsyncMethodsOf<MobileAppFunctions>>(methodName: T, ...args: Parameters<MobileAppFunctions[T]>) {\r\n return IpcApp.callIpcChannel(mobileAppStrings.mobileAppChannel, methodName, ...args) as PromiseReturnType<MobileAppFunctions[T]>;\r\n }\r\n\r\n private static _isValid = false;\r\n public static get isValid() { return this._isValid; }\r\n /** @beta */\r\n public static async startup(opts?: MobileAppOpts) {\r\n attachDirectEventCallbacks();\r\n\r\n const iModelAppOpts: IModelAppOptions = {\r\n ...opts?.iModelApp,\r\n };\r\n const authorizationClient = new MobileAuthorizationFrontend();\r\n iModelAppOpts.authorizationClient = authorizationClient;\r\n\r\n if (!this._isValid) {\r\n this.onAuthAccessTokenChanged.addListener((accessToken: string | undefined, expirationDate: string | undefined) => {\r\n authorizationClient.setAccessToken(accessToken, expirationDate);\r\n });\r\n\r\n const rpcInterfaces = opts?.iModelApp?.rpcInterfaces ?? [IModelReadRpcInterface, IModelTileRpcInterface]; // eslint-disable-line deprecation/deprecation\r\n MobileRpcManager.initializeClient(rpcInterfaces);\r\n this._isValid = true;\r\n }\r\n\r\n const socket = new IpcWebSocketFrontend(); // needs work\r\n await NativeApp.startup(socket, { ...opts, iModelApp: iModelAppOpts });\r\n\r\n MobileAppNotifyHandler.register(); // receives notifications from backend\r\n }\r\n}\r\n\r\n/*\r\n The suspend/resume lifecycle events cannot be reliably sent from the backend due to timing issues that arise when\r\n inter-operating with the actual suspend and resume behavior on the native side.\r\n Instead, they are sent directly to the browser here from platform-specific code.\r\n*/\r\nfunction attachDirectEventCallbacks() {\r\n (window as any)._imodeljs_rpc_lifecycle = (evt: \"suspend\" | \"resume\") => {\r\n if (evt === \"suspend\") {\r\n MobileApp.onEnterBackground.raiseEvent();\r\n } else if (evt === \"resume\") {\r\n MobileApp.onEnterForeground.raiseEvent();\r\n }\r\n };\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-mobile",
|
|
3
|
-
"version": "4.1.0-dev.
|
|
3
|
+
"version": "4.1.0-dev.8",
|
|
4
4
|
"description": "iTwin.js MobileHost and MobileApp",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"url": "http://www.bentley.com"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@itwin/core-backend": "^4.1.0-dev.
|
|
26
|
-
"@itwin/core-bentley": "^4.1.0-dev.
|
|
27
|
-
"@itwin/core-common": "^4.1.0-dev.
|
|
28
|
-
"@itwin/core-frontend": "^4.1.0-dev.
|
|
25
|
+
"@itwin/core-backend": "^4.1.0-dev.8",
|
|
26
|
+
"@itwin/core-bentley": "^4.1.0-dev.8",
|
|
27
|
+
"@itwin/core-common": "^4.1.0-dev.8",
|
|
28
|
+
"@itwin/core-frontend": "^4.1.0-dev.8"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"lodash": "^4.17.10",
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
"mocha": "^10.0.0",
|
|
50
50
|
"rimraf": "^3.0.2",
|
|
51
51
|
"typescript": "~5.0.2",
|
|
52
|
-
"@itwin/
|
|
53
|
-
"@itwin/
|
|
54
|
-
"@itwin/core-
|
|
55
|
-
"@itwin/core-
|
|
56
|
-
"@itwin/core-
|
|
52
|
+
"@itwin/core-backend": "4.1.0-dev.8",
|
|
53
|
+
"@itwin/build-tools": "4.1.0-dev.8",
|
|
54
|
+
"@itwin/core-bentley": "4.1.0-dev.8",
|
|
55
|
+
"@itwin/core-frontend": "4.1.0-dev.8",
|
|
56
|
+
"@itwin/core-common": "4.1.0-dev.8"
|
|
57
57
|
},
|
|
58
58
|
"eslintConfig": {
|
|
59
59
|
"plugins": [
|