@itwin/core-mobile 5.0.0-dev.32 → 5.0.0-dev.34
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 +33 -33
- package/lib/cjs/backend/MobileHost.js.map +1 -1
- package/lib/cjs/backend/MobileRpcServer.js +8 -8
- package/lib/cjs/backend/MobileRpcServer.js.map +1 -1
- package/lib/cjs/common/MobileEventLoop.js +2 -2
- package/lib/cjs/common/MobileEventLoop.js.map +1 -1
- package/lib/cjs/common/MobileIpc.js +2 -2
- package/lib/cjs/common/MobileIpc.js.map +1 -1
- package/lib/cjs/common/MobileRpcManager.js +5 -5
- package/lib/cjs/common/MobileRpcManager.js.map +1 -1
- package/lib/cjs/frontend/MobileApp.js +7 -7
- package/lib/cjs/frontend/MobileApp.js.map +1 -1
- package/package.json +10 -10
|
@@ -53,6 +53,39 @@ class MobileAppHandler extends core_backend_1.IpcHandler {
|
|
|
53
53
|
*/
|
|
54
54
|
class MobileHost {
|
|
55
55
|
static get device() { return this._device; }
|
|
56
|
+
/**
|
|
57
|
+
* Raised when the mobile OS informs a mobile app that it is running low on memory.
|
|
58
|
+
*
|
|
59
|
+
* @note iOS and iPadOS send this warning so often as to make it not very useful.
|
|
60
|
+
*/
|
|
61
|
+
static { this.onMemoryWarning = new core_bentley_1.BeEvent(); }
|
|
62
|
+
/**
|
|
63
|
+
* Raised when the device orientation changes on a device running a mobile app.
|
|
64
|
+
*/
|
|
65
|
+
static { this.onOrientationChanged = new core_bentley_1.BeEvent(); }
|
|
66
|
+
/**
|
|
67
|
+
* Raised after a mobile app returns to the foreground.
|
|
68
|
+
*/
|
|
69
|
+
static { this.onEnterForeground = new core_bentley_1.BeEvent(); }
|
|
70
|
+
/**
|
|
71
|
+
* Raised when a mobile app is about to enter the background.
|
|
72
|
+
*/
|
|
73
|
+
static { this.onEnterBackground = new core_bentley_1.BeEvent(); }
|
|
74
|
+
/**
|
|
75
|
+
* Raised after a mobile backend connects to the mobile frontend.
|
|
76
|
+
*
|
|
77
|
+
* @note this will be raised at startup, and it will also be raised every time the app returns
|
|
78
|
+
* to the foreground from the background.
|
|
79
|
+
*/
|
|
80
|
+
static { this.onConnected = new core_bentley_1.BeEvent(); }
|
|
81
|
+
/**
|
|
82
|
+
* Raised when a mobile app is about to be terminated by the mobile OS.
|
|
83
|
+
*/
|
|
84
|
+
static { this.onWillTerminate = new core_bentley_1.BeEvent(); }
|
|
85
|
+
/**
|
|
86
|
+
* Raised when the native auth client informs the mobile host that the access token has changed.
|
|
87
|
+
*/
|
|
88
|
+
static { this.onAuthAccessTokenChanged = new core_bentley_1.BeEvent(); }
|
|
56
89
|
/** Send a notification to the MobileApp connected to this MobileHost. */
|
|
57
90
|
static notifyMobileFrontend(methodName, ...args) {
|
|
58
91
|
return core_backend_1.IpcHost.send(MobileAppChannel_1.mobileAppStrings.mobileAppNotify, methodName, ...args);
|
|
@@ -146,37 +179,4 @@ class MobileHost {
|
|
|
146
179
|
}
|
|
147
180
|
}
|
|
148
181
|
exports.MobileHost = MobileHost;
|
|
149
|
-
/**
|
|
150
|
-
* Raised when the mobile OS informs a mobile app that it is running low on memory.
|
|
151
|
-
*
|
|
152
|
-
* @note iOS and iPadOS send this warning so often as to make it not very useful.
|
|
153
|
-
*/
|
|
154
|
-
MobileHost.onMemoryWarning = new core_bentley_1.BeEvent();
|
|
155
|
-
/**
|
|
156
|
-
* Raised when the device orientation changes on a device running a mobile app.
|
|
157
|
-
*/
|
|
158
|
-
MobileHost.onOrientationChanged = new core_bentley_1.BeEvent();
|
|
159
|
-
/**
|
|
160
|
-
* Raised after a mobile app returns to the foreground.
|
|
161
|
-
*/
|
|
162
|
-
MobileHost.onEnterForeground = new core_bentley_1.BeEvent();
|
|
163
|
-
/**
|
|
164
|
-
* Raised when a mobile app is about to enter the background.
|
|
165
|
-
*/
|
|
166
|
-
MobileHost.onEnterBackground = new core_bentley_1.BeEvent();
|
|
167
|
-
/**
|
|
168
|
-
* Raised after a mobile backend connects to the mobile frontend.
|
|
169
|
-
*
|
|
170
|
-
* @note this will be raised at startup, and it will also be raised every time the app returns
|
|
171
|
-
* to the foreground from the background.
|
|
172
|
-
*/
|
|
173
|
-
MobileHost.onConnected = new core_bentley_1.BeEvent();
|
|
174
|
-
/**
|
|
175
|
-
* Raised when a mobile app is about to be terminated by the mobile OS.
|
|
176
|
-
*/
|
|
177
|
-
MobileHost.onWillTerminate = new core_bentley_1.BeEvent();
|
|
178
|
-
/**
|
|
179
|
-
* Raised when the native auth client informs the mobile host that the access token has changed.
|
|
180
|
-
*/
|
|
181
|
-
MobileHost.onAuthAccessTokenChanged = new core_bentley_1.BeEvent();
|
|
182
182
|
//# sourceMappingURL=MobileHost.js.map
|
|
@@ -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,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,CAAC;YAClB,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,IAAI,CAAC,CAAC;gBACpD,MAAM;YACR,KAAK,iBAAiB;gBACpB,UAAU,CAAC,iBAAiB,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;gBACjD,MAAM;YACR,KAAK,iBAAiB;gBACpB,UAAU,CAAC,iBAAiB,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;gBACjD,MAAM;Y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AC,CAAC;IACjD,CAAC;;AA1IH,gCA2IC;AAxIC;;;;GAIG;AACoB,0BAAe,GAAG,IAAI,sBAAO,EAAE,CAAC;AACvD;;GAEG;AACoB,+BAAoB,GAAG,IAAI,sBAAO,EAAE,CAAC;AAC5D;;GAEG;AACoB,4BAAiB,GAAG,IAAI,sBAAO,EAAE,CAAC;AACzD;;GAEG;AACoB,4BAAiB,GAAG,IAAI,sBAAO,EAAE,CAAC;AACzD;;;;;GAKG;AACoB,sBAAW,GAAG,IAAI,sBAAO,EAAE,CAAC;AACnD;;GAEG;AACoB,0BAAe,GAAG,IAAI,sBAAO,EAAE,CAAC;AACvD;;GAEG;AACoB,mCAAwB,GAAG,IAAI,sBAAO,EAAiF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { AccessToken, BeEvent, BriefcaseStatus } from \"@itwin/core-bentley\";\nimport { IpcHandler, IpcHost, NativeHost, NativeHostOpts } from \"@itwin/core-backend\";\nimport { IpcWebSocketBackend, RpcInterfaceDefinition } from \"@itwin/core-common\";\nimport { CancelRequest, DownloadFailed, UserCancelledError } from \"./MobileFileHandler\";\nimport { ProgressCallback } from \"./Request\";\nimport { mobileAppStrings } from \"../common/MobileAppChannel\";\nimport { BatteryState, DeviceEvents, MobileAppFunctions, MobileNotifications, Orientation } from \"../common/MobileAppProps\";\nimport { MobileRpcManager } from \"../common/MobileRpcManager\";\nimport { MobileAuthorizationBackend } from \"./MobileAuthorizationBackend\";\nimport { setupMobileRpc } from \"./MobileRpcServer\";\n\n/** @beta */\nexport type MobileCompletionCallback = (downloadUrl: string, downloadFileUrl: string, cancelled: boolean, err?: string) => void;\n/** @beta */\nexport type MobileProgressCallback = (bytesWritten: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => void;\n/** @beta */\nexport type MobileCancelCallback = () => boolean;\n\n/** @beta */\nexport interface DownloadTask {\n url: string;\n downloadPath: string;\n isDetached: boolean;\n isRunning: boolean;\n totalBytes?: number;\n doneBytes?: number;\n cancelId?: number;\n isBackground?: boolean;\n cancel?: MobileCancelCallback;\n toBackground: () => boolean;\n toForeground: () => boolean;\n}\n\n/** @beta */\nexport abstract class MobileDevice {\n public emit(eventName: DeviceEvents, ...args: any[]) {\n switch (eventName) {\n case \"memoryWarning\":\n MobileHost.onMemoryWarning.raiseEvent(...args);\n break;\n case \"orientationChanged\":\n MobileHost.onOrientationChanged.raiseEvent(...args);\n break;\n case \"enterForeground\":\n MobileHost.onEnterForeground.raiseEvent(...args);\n break;\n case \"enterBackground\":\n MobileHost.onEnterBackground.raiseEvent(...args);\n break;\n case \"willTerminate\":\n MobileHost.onWillTerminate.raiseEvent(...args);\n break;\n case \"authAccessTokenChanged\":\n MobileHost.onAuthAccessTokenChanged.raiseEvent(args[0], args[1]);\n break;\n }\n }\n\n public abstract getOrientation(): Orientation;\n public abstract getBatteryState(): BatteryState;\n public abstract getBatteryLevel(): number;\n public abstract createDownloadTask(downloadUrl: string, isBackground: boolean, downloadTo: string, completion: MobileCompletionCallback, progress?: MobileProgressCallback): number;\n public abstract cancelDownloadTask(cancelId: number): boolean;\n public abstract getDownloadTasks(): DownloadTask[];\n public abstract resumeDownloadInForeground(requestId: number): boolean;\n public abstract resumeDownloadInBackground(requestId: number): boolean;\n public abstract reconnect(connection: number): void;\n public abstract authGetAccessToken(callback: (accessToken?: string, expirationDate?: string, err?: string) => void): void;\n}\n\nclass MobileAppHandler extends IpcHandler implements MobileAppFunctions {\n public get channelName() { return mobileAppStrings.mobileAppChannel; }\n public async reconnect(connection: number) {\n MobileHost.reconnect(connection);\n }\n public async getAccessToken() {\n return MobileHost.authGetAccessToken();\n }\n}\n\n/** @beta */\nexport interface MobileHostOpts extends NativeHostOpts {\n mobileHost?: {\n device?: MobileDevice;\n /** list of RPC interface definitions to register */\n rpcInterfaces?: RpcInterfaceDefinition[];\n };\n}\n\n/**\n * @beta\n */\nexport class MobileHost {\n private static _device?: MobileDevice;\n public static get device() { return this._device!; }\n /**\n * Raised when the mobile OS informs a mobile app that it is running low on memory.\n *\n * @note iOS and iPadOS send this warning so often as to make it not very useful.\n */\n public static readonly onMemoryWarning = new BeEvent();\n /**\n * Raised when the device orientation changes on a device running a mobile app.\n */\n public static readonly onOrientationChanged = new BeEvent();\n /**\n * Raised after a mobile app returns to the foreground.\n */\n public static readonly onEnterForeground = new BeEvent();\n /**\n * Raised when a mobile app is about to enter the background.\n */\n public static readonly onEnterBackground = new BeEvent();\n /**\n * Raised after a mobile backend connects to the mobile frontend.\n *\n * @note this will be raised at startup, and it will also be raised every time the app returns\n * to the foreground from the background.\n */\n public static readonly onConnected = new BeEvent();\n /**\n * Raised when a mobile app is about to be terminated by the mobile OS.\n */\n public static readonly onWillTerminate = new BeEvent();\n /**\n * Raised when the native auth client informs the mobile host that the access token has changed.\n */\n public static readonly onAuthAccessTokenChanged = new BeEvent<(accessToken: string | undefined, expirationDate: string | undefined) => void>();\n\n /** Send a notification to the MobileApp connected to this MobileHost. */\n public static notifyMobileFrontend<T extends keyof MobileNotifications>(methodName: T, ...args: Parameters<MobileNotifications[T]>) {\n return IpcHost.send(mobileAppStrings.mobileAppNotify, methodName, ...args);\n }\n\n /** @internal */\n public static reconnect(connection: number) {\n this.device.reconnect(connection);\n }\n\n /** @internal */\n public static async authGetAccessToken() {\n return new Promise<[AccessToken, string]>((resolve, reject) => {\n this.device.authGetAccessToken((tokenString?: AccessToken, expirationDate?: string, error?: string) => {\n if (error) {\n reject(new Error(error));\n } else {\n resolve([tokenString ?? \"\", expirationDate ?? \"\"]);\n }\n });\n });\n }\n\n /** @internal */\n public static async downloadFile(downloadUrl: string, downloadTo: string, progress?: ProgressCallback, cancelRequest?: CancelRequest): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n\n let progressCb: MobileProgressCallback | undefined;\n let lastReportedOn = Date.now();\n const minTimeBeforeReportingProgress = 1000;\n if (progress) {\n progressCb = (_bytesWritten: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => {\n const currentTime = Date.now();\n const timeSinceLastEvent = currentTime - lastReportedOn;\n // report all event for last 5 Mbs so we never miss 100% progress event\n const lastEvent = (totalBytesExpectedToWrite - totalBytesWritten) < 1024 * 1024 * 5;\n if (timeSinceLastEvent < minTimeBeforeReportingProgress && !lastEvent)\n return;\n\n lastReportedOn = currentTime;\n const percent = Number((100 * (totalBytesWritten / totalBytesExpectedToWrite)).toFixed(2));\n progress({ total: totalBytesExpectedToWrite, loaded: totalBytesWritten, percent });\n };\n }\n const requestId = this.device.createDownloadTask(downloadUrl, false, downloadTo, (_downloadUrl: string, _downloadFileUrl: string, cancelled: boolean, err?: string) => {\n if (cancelled)\n reject(new UserCancelledError(BriefcaseStatus.DownloadCancelled, \"User cancelled download\"));\n else if (err)\n reject(new DownloadFailed(400, \"Download failed\"));\n else\n resolve();\n }, progressCb);\n if (cancelRequest) {\n cancelRequest.cancel = () => this.device.cancelDownloadTask(requestId);\n }\n });\n }\n\n public static get isValid() { return undefined !== this._device; }\n\n /** Start the backend of a mobile app. */\n public static async startup(opt?: MobileHostOpts): Promise<void> {\n const authorizationClient = new MobileAuthorizationBackend();\n if (!this.isValid) {\n this._device = opt?.mobileHost?.device ?? new (MobileDevice as any)();\n // set global device interface.\n // NOTE: __iTwinJsNativeBridge is used by backend native code.\n (global as any).__iTwinJsNativeBridge = this._device;\n this.onMemoryWarning.addListener(() => {\n MobileHost.notifyMobileFrontend(\"notifyMemoryWarning\");\n });\n this.onOrientationChanged.addListener(() => {\n try {\n MobileHost.notifyMobileFrontend(\"notifyOrientationChanged\");\n } catch { } // Ignore: frontend is not currently connected\n });\n this.onWillTerminate.addListener(() => {\n MobileHost.notifyMobileFrontend(\"notifyWillTerminate\");\n });\n this.onAuthAccessTokenChanged.addListener((accessToken: string | undefined, expirationDate: string | undefined) => {\n authorizationClient.setAccessToken(accessToken, expirationDate);\n MobileHost.notifyMobileFrontend(\"notifyAuthAccessTokenChanged\", accessToken, expirationDate);\n });\n\n // following will provide impl for device specific api.\n setupMobileRpc();\n }\n\n const socket = opt?.ipcHost?.socket ?? new IpcWebSocketBackend();\n opt = { ...opt, mobileHost: { ...opt?.mobileHost }, ipcHost: { ...opt?.ipcHost, socket } };\n\n const iModelHost = opt?.iModelHost ?? {};\n iModelHost.authorizationClient = authorizationClient;\n await NativeHost.startup({ ...opt, iModelHost });\n\n if (IpcHost.isValid)\n MobileAppHandler.register();\n\n const rpcInterfaces = opt?.mobileHost?.rpcInterfaces ?? [];\n\n MobileRpcManager.initializeImpl(rpcInterfaces);\n }\n}\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,CAAC;YAClB,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,IAAI,CAAC,CAAC;gBACpD,MAAM;YACR,KAAK,iBAAiB;gBACpB,UAAU,CAAC,iBAAiB,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;gBACjD,MAAM;YACR,KAAK,iBAAiB;gBACpB,UAAU,CAAC,iBAAiB,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;gBACjD,MAAM;YACR,KAAK,eAAe;gBAClB,UAAU,CAAC,eAAe,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,C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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;;AA1IH,gCA2IC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { AccessToken, BeEvent, BriefcaseStatus } from \"@itwin/core-bentley\";\nimport { IpcHandler, IpcHost, NativeHost, NativeHostOpts } from \"@itwin/core-backend\";\nimport { IpcWebSocketBackend, RpcInterfaceDefinition } from \"@itwin/core-common\";\nimport { CancelRequest, DownloadFailed, UserCancelledError } from \"./MobileFileHandler\";\nimport { ProgressCallback } from \"./Request\";\nimport { mobileAppStrings } from \"../common/MobileAppChannel\";\nimport { BatteryState, DeviceEvents, MobileAppFunctions, MobileNotifications, Orientation } from \"../common/MobileAppProps\";\nimport { MobileRpcManager } from \"../common/MobileRpcManager\";\nimport { MobileAuthorizationBackend } from \"./MobileAuthorizationBackend\";\nimport { setupMobileRpc } from \"./MobileRpcServer\";\n\n/** @beta */\nexport type MobileCompletionCallback = (downloadUrl: string, downloadFileUrl: string, cancelled: boolean, err?: string) => void;\n/** @beta */\nexport type MobileProgressCallback = (bytesWritten: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => void;\n/** @beta */\nexport type MobileCancelCallback = () => boolean;\n\n/** @beta */\nexport interface DownloadTask {\n url: string;\n downloadPath: string;\n isDetached: boolean;\n isRunning: boolean;\n totalBytes?: number;\n doneBytes?: number;\n cancelId?: number;\n isBackground?: boolean;\n cancel?: MobileCancelCallback;\n toBackground: () => boolean;\n toForeground: () => boolean;\n}\n\n/** @beta */\nexport abstract class MobileDevice {\n public emit(eventName: DeviceEvents, ...args: any[]) {\n switch (eventName) {\n case \"memoryWarning\":\n MobileHost.onMemoryWarning.raiseEvent(...args);\n break;\n case \"orientationChanged\":\n MobileHost.onOrientationChanged.raiseEvent(...args);\n break;\n case \"enterForeground\":\n MobileHost.onEnterForeground.raiseEvent(...args);\n break;\n case \"enterBackground\":\n MobileHost.onEnterBackground.raiseEvent(...args);\n break;\n case \"willTerminate\":\n MobileHost.onWillTerminate.raiseEvent(...args);\n break;\n case \"authAccessTokenChanged\":\n MobileHost.onAuthAccessTokenChanged.raiseEvent(args[0], args[1]);\n break;\n }\n }\n\n public abstract getOrientation(): Orientation;\n public abstract getBatteryState(): BatteryState;\n public abstract getBatteryLevel(): number;\n public abstract createDownloadTask(downloadUrl: string, isBackground: boolean, downloadTo: string, completion: MobileCompletionCallback, progress?: MobileProgressCallback): number;\n public abstract cancelDownloadTask(cancelId: number): boolean;\n public abstract getDownloadTasks(): DownloadTask[];\n public abstract resumeDownloadInForeground(requestId: number): boolean;\n public abstract resumeDownloadInBackground(requestId: number): boolean;\n public abstract reconnect(connection: number): void;\n public abstract authGetAccessToken(callback: (accessToken?: string, expirationDate?: string, err?: string) => void): void;\n}\n\nclass MobileAppHandler extends IpcHandler implements MobileAppFunctions {\n public get channelName() { return mobileAppStrings.mobileAppChannel; }\n public async reconnect(connection: number) {\n MobileHost.reconnect(connection);\n }\n public async getAccessToken() {\n return MobileHost.authGetAccessToken();\n }\n}\n\n/** @beta */\nexport interface MobileHostOpts extends NativeHostOpts {\n mobileHost?: {\n device?: MobileDevice;\n /** list of RPC interface definitions to register */\n rpcInterfaces?: RpcInterfaceDefinition[];\n };\n}\n\n/**\n * @beta\n */\nexport class MobileHost {\n private static _device?: MobileDevice;\n public static get device() { return this._device!; }\n /**\n * Raised when the mobile OS informs a mobile app that it is running low on memory.\n *\n * @note iOS and iPadOS send this warning so often as to make it not very useful.\n */\n public static readonly onMemoryWarning = new BeEvent();\n /**\n * Raised when the device orientation changes on a device running a mobile app.\n */\n public static readonly onOrientationChanged = new BeEvent();\n /**\n * Raised after a mobile app returns to the foreground.\n */\n public static readonly onEnterForeground = new BeEvent();\n /**\n * Raised when a mobile app is about to enter the background.\n */\n public static readonly onEnterBackground = new BeEvent();\n /**\n * Raised after a mobile backend connects to the mobile frontend.\n *\n * @note this will be raised at startup, and it will also be raised every time the app returns\n * to the foreground from the background.\n */\n public static readonly onConnected = new BeEvent();\n /**\n * Raised when a mobile app is about to be terminated by the mobile OS.\n */\n public static readonly onWillTerminate = new BeEvent();\n /**\n * Raised when the native auth client informs the mobile host that the access token has changed.\n */\n public static readonly onAuthAccessTokenChanged = new BeEvent<(accessToken: string | undefined, expirationDate: string | undefined) => void>();\n\n /** Send a notification to the MobileApp connected to this MobileHost. */\n public static notifyMobileFrontend<T extends keyof MobileNotifications>(methodName: T, ...args: Parameters<MobileNotifications[T]>) {\n return IpcHost.send(mobileAppStrings.mobileAppNotify, methodName, ...args);\n }\n\n /** @internal */\n public static reconnect(connection: number) {\n this.device.reconnect(connection);\n }\n\n /** @internal */\n public static async authGetAccessToken() {\n return new Promise<[AccessToken, string]>((resolve, reject) => {\n this.device.authGetAccessToken((tokenString?: AccessToken, expirationDate?: string, error?: string) => {\n if (error) {\n reject(new Error(error));\n } else {\n resolve([tokenString ?? \"\", expirationDate ?? \"\"]);\n }\n });\n });\n }\n\n /** @internal */\n public static async downloadFile(downloadUrl: string, downloadTo: string, progress?: ProgressCallback, cancelRequest?: CancelRequest): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n\n let progressCb: MobileProgressCallback | undefined;\n let lastReportedOn = Date.now();\n const minTimeBeforeReportingProgress = 1000;\n if (progress) {\n progressCb = (_bytesWritten: number, totalBytesWritten: number, totalBytesExpectedToWrite: number) => {\n const currentTime = Date.now();\n const timeSinceLastEvent = currentTime - lastReportedOn;\n // report all event for last 5 Mbs so we never miss 100% progress event\n const lastEvent = (totalBytesExpectedToWrite - totalBytesWritten) < 1024 * 1024 * 5;\n if (timeSinceLastEvent < minTimeBeforeReportingProgress && !lastEvent)\n return;\n\n lastReportedOn = currentTime;\n const percent = Number((100 * (totalBytesWritten / totalBytesExpectedToWrite)).toFixed(2));\n progress({ total: totalBytesExpectedToWrite, loaded: totalBytesWritten, percent });\n };\n }\n const requestId = this.device.createDownloadTask(downloadUrl, false, downloadTo, (_downloadUrl: string, _downloadFileUrl: string, cancelled: boolean, err?: string) => {\n if (cancelled)\n reject(new UserCancelledError(BriefcaseStatus.DownloadCancelled, \"User cancelled download\"));\n else if (err)\n reject(new DownloadFailed(400, \"Download failed\"));\n else\n resolve();\n }, progressCb);\n if (cancelRequest) {\n cancelRequest.cancel = () => this.device.cancelDownloadTask(requestId);\n }\n });\n }\n\n public static get isValid() { return undefined !== this._device; }\n\n /** Start the backend of a mobile app. */\n public static async startup(opt?: MobileHostOpts): Promise<void> {\n const authorizationClient = new MobileAuthorizationBackend();\n if (!this.isValid) {\n this._device = opt?.mobileHost?.device ?? new (MobileDevice as any)();\n // set global device interface.\n // NOTE: __iTwinJsNativeBridge is used by backend native code.\n (global as any).__iTwinJsNativeBridge = this._device;\n this.onMemoryWarning.addListener(() => {\n MobileHost.notifyMobileFrontend(\"notifyMemoryWarning\");\n });\n this.onOrientationChanged.addListener(() => {\n try {\n MobileHost.notifyMobileFrontend(\"notifyOrientationChanged\");\n } catch { } // Ignore: frontend is not currently connected\n });\n this.onWillTerminate.addListener(() => {\n MobileHost.notifyMobileFrontend(\"notifyWillTerminate\");\n });\n this.onAuthAccessTokenChanged.addListener((accessToken: string | undefined, expirationDate: string | undefined) => {\n authorizationClient.setAccessToken(accessToken, expirationDate);\n MobileHost.notifyMobileFrontend(\"notifyAuthAccessTokenChanged\", accessToken, expirationDate);\n });\n\n // following will provide impl for device specific api.\n setupMobileRpc();\n }\n\n const socket = opt?.ipcHost?.socket ?? new IpcWebSocketBackend();\n opt = { ...opt, mobileHost: { ...opt?.mobileHost }, ipcHost: { ...opt?.ipcHost, socket } };\n\n const iModelHost = opt?.iModelHost ?? {};\n iModelHost.authorizationClient = authorizationClient;\n await NativeHost.startup({ ...opt, iModelHost });\n\n if (IpcHost.isValid)\n MobileAppHandler.register();\n\n const rpcInterfaces = opt?.mobileHost?.rpcInterfaces ?? [];\n\n MobileRpcManager.initializeImpl(rpcInterfaces);\n }\n}\n"]}
|
|
@@ -15,6 +15,14 @@ const core_bentley_1 = require("@itwin/core-bentley");
|
|
|
15
15
|
let addon;
|
|
16
16
|
/** @internal */
|
|
17
17
|
class MobileRpcServer {
|
|
18
|
+
static { this._nextId = -1; }
|
|
19
|
+
static { this.interop = {
|
|
20
|
+
handler: (_payload) => { throw new core_common_1.IModelError(core_common_1.BentleyStatus.ERROR, "Not implemented."); },
|
|
21
|
+
sendString: (_message, _connectionId) => { throw new core_common_1.IModelError(core_common_1.BentleyStatus.ERROR, "No connection."); },
|
|
22
|
+
sendBinary: (_message, _connectionId) => { throw new core_common_1.IModelError(core_common_1.BentleyStatus.ERROR, "No connection."); },
|
|
23
|
+
port: 0,
|
|
24
|
+
connectionId: 0,
|
|
25
|
+
}; }
|
|
18
26
|
constructor(_pendingMessages = undefined) {
|
|
19
27
|
this._pendingMessages = _pendingMessages;
|
|
20
28
|
/* _pingTime is a fix for ios/mobile case where when the app moves into foreground from
|
|
@@ -113,14 +121,6 @@ class MobileRpcServer {
|
|
|
113
121
|
}
|
|
114
122
|
}
|
|
115
123
|
exports.MobileRpcServer = MobileRpcServer;
|
|
116
|
-
MobileRpcServer._nextId = -1;
|
|
117
|
-
MobileRpcServer.interop = {
|
|
118
|
-
handler: (_payload) => { throw new core_common_1.IModelError(core_common_1.BentleyStatus.ERROR, "Not implemented."); },
|
|
119
|
-
sendString: (_message, _connectionId) => { throw new core_common_1.IModelError(core_common_1.BentleyStatus.ERROR, "No connection."); },
|
|
120
|
-
sendBinary: (_message, _connectionId) => { throw new core_common_1.IModelError(core_common_1.BentleyStatus.ERROR, "No connection."); },
|
|
121
|
-
port: 0,
|
|
122
|
-
connectionId: 0,
|
|
123
|
-
};
|
|
124
124
|
let mobileReady = false;
|
|
125
125
|
let hasSuspended = false;
|
|
126
126
|
function setupMobileRpc() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileRpcServer.js","sourceRoot":"","sources":["../../../src/backend/MobileRpcServer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAmJ/F,wCAoEC;AArND,yBAAyB;AACzB,oDAAgE;AAChE,mEAAkF;AAClF,iEAAoE;AACpE,6CAA0C;AAC1C,sDAAsD;AAOtD,IAAI,KAA8B,CAAC;AAEnC,gBAAgB;AAChB,MAAa,eAAe;IAgB1B,YAA2B,mBAA2D,SAAS;QAApE,qBAAgB,GAAhB,gBAAgB,CAAoD;QAC7F;;;;;;;;WAQG;QACH,IAAI,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,GAAG,yCAAsB,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACvD,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;QACnD,IAAI,CAAC,aAAa,GAAG,EAAE,eAAe,CAAC,OAAO,CAAC;QAC/C,eAAe,CAAC,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC;QAC1D,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAEO,YAAY;QAClB,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,WAAW,EAAE,GAAG,EAAE;YAChC,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OA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E,CAAC;YAC1C,aAAa,CAAC,YAAY,CAAC,CAAC;YAC5B,YAAY,GAAG,SAAS,CAAC;QAC3B,CAAC;QAED,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,qCAAiB,CAAC,aAAa,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC;IAChE,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport * as ws from \"ws\";\nimport { BentleyStatus, IModelError } from \"@itwin/core-common\";\nimport { MobileRpcGateway, MobileRpcProtocol } from \"../common/MobileRpcProtocol\";\nimport { MobileRpcConfiguration } from \"../common/MobileRpcManager\";\nimport { MobileHost } from \"./MobileHost\";\nimport { ProcessDetector } from \"@itwin/core-bentley\";\n\ninterface MobileAddon {\n notifyListening: (port: number) => void;\n registerDeviceImpl: () => void;\n}\n\nlet addon: MobileAddon | undefined;\n\n/** @internal */\nexport class MobileRpcServer {\n private static _nextId = -1;\n\n public static interop: MobileRpcGateway = {\n handler: (_payload: ArrayBuffer | string) => { throw new IModelError(BentleyStatus.ERROR, \"Not implemented.\"); },\n sendString: (_message: string, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\n sendBinary: (_message: Uint8Array, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\n port: 0,\n connectionId: 0,\n };\n\n private _server: ws.Server;\n private _connection: ws | undefined;\n private _port: number;\n private _connectionId: number;\n private _pingTimer: NodeJS.Timeout;\n public constructor(private _pendingMessages: Array<string | Uint8Array> | undefined = undefined) {\n /* _pingTime is a fix for ios/mobile case where when the app moves into foreground from\n * background backend restart ws.Server and then notify frontend to reconnect. But ws.Server\n * listening event is not fired as node yield to kevent and wait for some io event to happen.\n * This causes a delay in reconnection which may be as long a 40 secs. To solve the issue we\n * create _pingTimer which causes kevent to yield back to uv poll so timer event can be fired.\n * This allow listening event to go through quickly (max 5ms). Once the listening event occur we\n * clear the timer. Here we use setInterval() just to make sure otherwise setTimeout() could equally\n * be effective\n */\n this._pingTimer = setInterval(() => { }, 5);\n this._port = MobileRpcConfiguration.setup.obtainPort();\n this._server = new ws.Server({ port: this._port });\n this._connectionId = ++MobileRpcServer._nextId;\n MobileRpcServer.interop.connectionId = this._connectionId;\n this._onListening();\n this._onConnection();\n }\n\n private _onListening() {\n this._server.on(\"listening\", () => {\n const address = this._server.address() as ws.AddressInfo;\n this._port = address.port;\n clearInterval(this._pingTimer);\n this._notifyListening();\n });\n }\n\n private _notifyListening() {\n MobileRpcServer.interop.port = this._port;\n\n if (addon) {\n addon.notifyListening(this._port);\n }\n\n if (this._connectionId !== 0) {\n MobileHost.reconnect(this._port);\n }\n }\n\n private _onConnection() {\n this._server.on(\"connection\", (connection) => {\n this._connection = connection;\n this._connection.on(\"message\", (data) => this._onConnectionMessage(data));\n this._createSender();\n this._sendPending();\n (global as any).__iTwinJsRpcReady = true;\n MobileHost.onConnected.raiseEvent();\n });\n }\n\n private _createSender() {\n const sender = (message: string | Uint8Array, connectionId: number) => {\n if (connectionId !== this._connectionId) {\n return;\n }\n\n this._connection!.send(message, (err) => {\n if (err) {\n throw err;\n }\n });\n };\n\n MobileRpcServer.interop.sendString = sender;\n MobileRpcServer.interop.sendBinary = sender;\n }\n\n private _sendPending() {\n if (this._pendingMessages === undefined)\n return;\n\n for (const message of this._pendingMessages) {\n this._connection!.send(message, (err) => {\n if (err) {\n throw err;\n }\n });\n }\n this._pendingMessages.length = 0;\n }\n\n private _onConnectionMessage(data: ws.Data) {\n let message = data;\n if (Array.isArray(message)) {\n throw new IModelError(BentleyStatus.ERROR, \"Unsupported data type\");\n }\n\n if (Buffer.isBuffer(message)) {\n if (message.byteOffset !== 0 || message.byteLength !== message.buffer.byteLength) {\n message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);\n } else {\n message = message.buffer;\n }\n }\n\n MobileRpcServer.interop.handler(message, this._connectionId);\n }\n\n public dispose() {\n clearInterval(this._pingTimer);\n if (this._connection) {\n MobileRpcServer.interop.sendString = () => { };\n MobileRpcServer.interop.sendBinary = () => { };\n this._connection.close();\n }\n\n this._server.close();\n }\n}\n\nlet mobileReady = false;\nlet hasSuspended = false;\n\nexport function setupMobileRpc() {\n if (mobileReady) {\n return;\n }\n\n if (ProcessDetector.isMobileAppBackend) {\n addon = (process as any)._linkedBinding(\"iModelJsMobile\");\n addon?.registerDeviceImpl();\n }\n\n let server: MobileRpcServer | null = new MobileRpcServer();\n\n /* The UV event loop (internal to node) is retained by handles,\n such as those created for setInterval/setTimeout and client/server connections.\n In a simple app, the RPC server may be the only handle retaining the UV loop.\n Thus, we install a temporary timer on suspend to prevent the loop from exiting prematurely.\n */\n let retainUvLoop: NodeJS.Timeout | undefined;\n const pendingMessages: Array<string | Uint8Array> = [];\n\n function usePendingSender() {\n const sender = (message: string | Uint8Array, _connectionId: number) => {\n pendingMessages.push(message);\n };\n MobileRpcServer.interop.sendString = sender;\n MobileRpcServer.interop.sendBinary = sender;\n }\n\n MobileHost.onEnterBackground.addListener(() => {\n hasSuspended = true;\n\n if (server === null) {\n return;\n }\n\n retainUvLoop = setInterval(() => { }, 1000);\n server.dispose();\n usePendingSender();\n server = null;\n (global as any).__iTwinJsRpcReady = false;\n });\n\n MobileHost.onEnterForeground.addListener(() => {\n if (!hasSuspended) {\n return;\n }\n\n server = new MobileRpcServer(pendingMessages);\n clearInterval(retainUvLoop);\n retainUvLoop = undefined;\n });\n\n MobileHost.onWillTerminate.addListener(() => {\n if (typeof (retainUvLoop) !== \"undefined\") {\n clearInterval(retainUvLoop);\n retainUvLoop = undefined;\n }\n\n if (server === null) {\n return;\n }\n\n server.dispose();\n server = null;\n });\n\n MobileRpcProtocol.obtainInterop = () => MobileRpcServer.interop;\n mobileReady = true;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MobileRpcServer.js","sourceRoot":"","sources":["../../../src/backend/MobileRpcServer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAmJ/F,wCAoEC;AArND,yBAAyB;AACzB,oDAAgE;AAChE,mEAAkF;AAClF,iEAAoE;AACpE,6CAA0C;AAC1C,sDAAsD;AAOtD,IAAI,KAA8B,CAAC;AAEnC,gBAAgB;AAChB,MAAa,eAAe;aACX,YAAO,GAAG,CAAC,CAAC,CAAC;aAEd,YAAO,GAAqB;QACxC,OAAO,EAAE,CAAC,QAA8B,EAAE,EAAE,GAAG,MAAM,IAAI,yBAAW,CAAC,2BAAa,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;QAChH,UAAU,EAAE,CAAC,QAAgB,EAAE,aAAqB,EAAE,EAAE,GAAG,MAAM,IAAI,yBAAW,CAAC,2BAAa,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAC1H,UAAU,EAAE,CAAC,QAAoB,EAAE,aAAqB,EAAE,EAAE,GAAG,MAAM,IAAI,yBAAW,CAAC,2BAAa,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAC9H,IAAI,EAAE,CAAC;QACP,YAAY,EAAE,CAAC;KAChB,CAAC;IAOF,YAA2B,mBAA2D,SAAS;QAApE,qBAAgB,GAAhB,gBAAgB,CAAoD;QAC7F;;;;;;;;WAQG;QACH,IAAI,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,GAAG,yCAAsB,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACvD,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,I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AAO,EAAE,CAAC;QACjB,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,qCAAiB,CAAC,aAAa,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC;IAChE,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport * as ws from \"ws\";\nimport { BentleyStatus, IModelError } from \"@itwin/core-common\";\nimport { MobileRpcGateway, MobileRpcProtocol } from \"../common/MobileRpcProtocol\";\nimport { MobileRpcConfiguration } from \"../common/MobileRpcManager\";\nimport { MobileHost } from \"./MobileHost\";\nimport { ProcessDetector } from \"@itwin/core-bentley\";\n\ninterface MobileAddon {\n notifyListening: (port: number) => void;\n registerDeviceImpl: () => void;\n}\n\nlet addon: MobileAddon | undefined;\n\n/** @internal */\nexport class MobileRpcServer {\n private static _nextId = -1;\n\n public static interop: MobileRpcGateway = {\n handler: (_payload: ArrayBuffer | string) => { throw new IModelError(BentleyStatus.ERROR, \"Not implemented.\"); },\n sendString: (_message: string, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\n sendBinary: (_message: Uint8Array, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\n port: 0,\n connectionId: 0,\n };\n\n private _server: ws.Server;\n private _connection: ws | undefined;\n private _port: number;\n private _connectionId: number;\n private _pingTimer: NodeJS.Timeout;\n public constructor(private _pendingMessages: Array<string | Uint8Array> | undefined = undefined) {\n /* _pingTime is a fix for ios/mobile case where when the app moves into foreground from\n * background backend restart ws.Server and then notify frontend to reconnect. But ws.Server\n * listening event is not fired as node yield to kevent and wait for some io event to happen.\n * This causes a delay in reconnection which may be as long a 40 secs. To solve the issue we\n * create _pingTimer which causes kevent to yield back to uv poll so timer event can be fired.\n * This allow listening event to go through quickly (max 5ms). Once the listening event occur we\n * clear the timer. Here we use setInterval() just to make sure otherwise setTimeout() could equally\n * be effective\n */\n this._pingTimer = setInterval(() => { }, 5);\n this._port = MobileRpcConfiguration.setup.obtainPort();\n this._server = new ws.Server({ port: this._port });\n this._connectionId = ++MobileRpcServer._nextId;\n MobileRpcServer.interop.connectionId = this._connectionId;\n this._onListening();\n this._onConnection();\n }\n\n private _onListening() {\n this._server.on(\"listening\", () => {\n const address = this._server.address() as ws.AddressInfo;\n this._port = address.port;\n clearInterval(this._pingTimer);\n this._notifyListening();\n });\n }\n\n private _notifyListening() {\n MobileRpcServer.interop.port = this._port;\n\n if (addon) {\n addon.notifyListening(this._port);\n }\n\n if (this._connectionId !== 0) {\n MobileHost.reconnect(this._port);\n }\n }\n\n private _onConnection() {\n this._server.on(\"connection\", (connection) => {\n this._connection = connection;\n this._connection.on(\"message\", (data) => this._onConnectionMessage(data));\n this._createSender();\n this._sendPending();\n (global as any).__iTwinJsRpcReady = true;\n MobileHost.onConnected.raiseEvent();\n });\n }\n\n private _createSender() {\n const sender = (message: string | Uint8Array, connectionId: number) => {\n if (connectionId !== this._connectionId) {\n return;\n }\n\n this._connection!.send(message, (err) => {\n if (err) {\n throw err;\n }\n });\n };\n\n MobileRpcServer.interop.sendString = sender;\n MobileRpcServer.interop.sendBinary = sender;\n }\n\n private _sendPending() {\n if (this._pendingMessages === undefined)\n return;\n\n for (const message of this._pendingMessages) {\n this._connection!.send(message, (err) => {\n if (err) {\n throw err;\n }\n });\n }\n this._pendingMessages.length = 0;\n }\n\n private _onConnectionMessage(data: ws.Data) {\n let message = data;\n if (Array.isArray(message)) {\n throw new IModelError(BentleyStatus.ERROR, \"Unsupported data type\");\n }\n\n if (Buffer.isBuffer(message)) {\n if (message.byteOffset !== 0 || message.byteLength !== message.buffer.byteLength) {\n message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);\n } else {\n message = message.buffer;\n }\n }\n\n MobileRpcServer.interop.handler(message, this._connectionId);\n }\n\n public dispose() {\n clearInterval(this._pingTimer);\n if (this._connection) {\n MobileRpcServer.interop.sendString = () => { };\n MobileRpcServer.interop.sendBinary = () => { };\n this._connection.close();\n }\n\n this._server.close();\n }\n}\n\nlet mobileReady = false;\nlet hasSuspended = false;\n\nexport function setupMobileRpc() {\n if (mobileReady) {\n return;\n }\n\n if (ProcessDetector.isMobileAppBackend) {\n addon = (process as any)._linkedBinding(\"iModelJsMobile\");\n addon?.registerDeviceImpl();\n }\n\n let server: MobileRpcServer | null = new MobileRpcServer();\n\n /* The UV event loop (internal to node) is retained by handles,\n such as those created for setInterval/setTimeout and client/server connections.\n In a simple app, the RPC server may be the only handle retaining the UV loop.\n Thus, we install a temporary timer on suspend to prevent the loop from exiting prematurely.\n */\n let retainUvLoop: NodeJS.Timeout | undefined;\n const pendingMessages: Array<string | Uint8Array> = [];\n\n function usePendingSender() {\n const sender = (message: string | Uint8Array, _connectionId: number) => {\n pendingMessages.push(message);\n };\n MobileRpcServer.interop.sendString = sender;\n MobileRpcServer.interop.sendBinary = sender;\n }\n\n MobileHost.onEnterBackground.addListener(() => {\n hasSuspended = true;\n\n if (server === null) {\n return;\n }\n\n retainUvLoop = setInterval(() => { }, 1000);\n server.dispose();\n usePendingSender();\n server = null;\n (global as any).__iTwinJsRpcReady = false;\n });\n\n MobileHost.onEnterForeground.addListener(() => {\n if (!hasSuspended) {\n return;\n }\n\n server = new MobileRpcServer(pendingMessages);\n clearInterval(retainUvLoop);\n retainUvLoop = undefined;\n });\n\n MobileHost.onWillTerminate.addListener(() => {\n if (typeof (retainUvLoop) !== \"undefined\") {\n clearInterval(retainUvLoop);\n retainUvLoop = undefined;\n }\n\n if (server === null) {\n return;\n }\n\n server.dispose();\n server = null;\n });\n\n MobileRpcProtocol.obtainInterop = () => MobileRpcServer.interop;\n mobileReady = true;\n}\n"]}
|
|
@@ -10,6 +10,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.MobileEventLoop = void 0;
|
|
11
11
|
/** @internal */
|
|
12
12
|
class MobileEventLoop {
|
|
13
|
+
static { this._activeTasks = 0; }
|
|
14
|
+
static { this._idleCallback = null; }
|
|
13
15
|
static addTask() {
|
|
14
16
|
++this._activeTasks;
|
|
15
17
|
if (this._idleCallback === null) {
|
|
@@ -26,6 +28,4 @@ class MobileEventLoop {
|
|
|
26
28
|
static _idleHandler() { }
|
|
27
29
|
}
|
|
28
30
|
exports.MobileEventLoop = MobileEventLoop;
|
|
29
|
-
MobileEventLoop._activeTasks = 0;
|
|
30
|
-
MobileEventLoop._idleCallback = null;
|
|
31
31
|
//# sourceMappingURL=MobileEventLoop.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileEventLoop.js","sourceRoot":"","sources":["../../../src/common/MobileEventLoop.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gBAAgB;AAChB,MAAa,eAAe;
|
|
1
|
+
{"version":3,"file":"MobileEventLoop.js","sourceRoot":"","sources":["../../../src/common/MobileEventLoop.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gBAAgB;AAChB,MAAa,eAAe;aACX,iBAAY,GAAG,CAAC,CAAC;aACjB,kBAAa,GAA0B,IAAI,CAAC;IAEpD,MAAM,CAAC,OAAO;QACnB,EAAE,IAAI,CAAC,YAAY,CAAC;QAEpB,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;YAChC,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAEM,MAAM,CAAC,UAAU;QACtB,EAAE,IAAI,CAAC,YAAY,CAAC;QAEpB,IAAI,IAAI,CAAC,YAAY,KAAK,CAAC,IAAI,IAAI,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;YAC3D,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAClC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;QAC5B,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,YAAY,KAAK,CAAC;;AArBnC,0CAsBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module RpcInterface\n */\n\n/** @internal */\nexport class MobileEventLoop {\n private static _activeTasks = 0;\n private static _idleCallback: NodeJS.Timeout | null = null;\n\n public static addTask() {\n ++this._activeTasks;\n\n if (this._idleCallback === null) {\n this._idleCallback = setInterval(() => this._idleHandler());\n }\n }\n\n public static removeTask() {\n --this._activeTasks;\n\n if (this._activeTasks === 0 && this._idleCallback !== null) {\n clearInterval(this._idleCallback);\n this._idleCallback = null;\n }\n }\n\n private static _idleHandler() { }\n}\n"]}
|
|
@@ -14,10 +14,10 @@ const MobileRpcProtocol_1 = require("./MobileRpcProtocol");
|
|
|
14
14
|
const MobileRpcRequest_1 = require("./MobileRpcRequest");
|
|
15
15
|
const IPC = "__ipc__";
|
|
16
16
|
class IpcInterface extends core_common_1.RpcInterface {
|
|
17
|
+
static { this.interfaceName = IPC; }
|
|
18
|
+
static { this.interfaceVersion = "0.0.0"; }
|
|
17
19
|
async send() { }
|
|
18
20
|
}
|
|
19
|
-
IpcInterface.interfaceName = IPC;
|
|
20
|
-
IpcInterface.interfaceVersion = "0.0.0";
|
|
21
21
|
/** @internal */
|
|
22
22
|
class MobileIpcTransport extends core_common_1.IpcWebSocketTransport {
|
|
23
23
|
constructor(protocol) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileIpc.js","sourceRoot":"","sources":["../../../src/common/MobileIpc.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAG4B;AAC5B,uDAAoD;AACpD,2DAAwD;AACxD,yDAAsD;A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,CAAC,WAAW,CAAC,CAAC;QAC9D,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAEO,SAAS,CAAC,GAAU,EAAE,OAA4B;QACxD,KAAK,MAAM,QAAQ,IAAI,0BAAY,CAAC,SAAS;YAC3C,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF;AA3DD,gDA2DC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module RpcInterface\n */\n\nimport {\n IpcWebSocket, IpcWebSocketMessage, IpcWebSocketMessageType, IpcWebSocketTransport, RpcInterface, RpcManager, RpcMarshaling, RpcRequestFulfillment,\n SerializedRpcRequest,\n} from \"@itwin/core-common\";\nimport { MobileEventLoop } from \"./MobileEventLoop\";\nimport { MobileRpcProtocol } from \"./MobileRpcProtocol\";\nimport { MobileRpcRequest } from \"./MobileRpcRequest\";\n\nconst IPC = \"__ipc__\";\n\nclass IpcInterface extends RpcInterface {\n public static interfaceName = IPC;\n public static interfaceVersion = \"0.0.0\";\n public async send() { }\n}\n\n/** @internal */\nexport class MobileIpcTransport extends IpcWebSocketTransport {\n private _protocol: MobileRpcProtocol;\n private _client: IpcInterface;\n\n public constructor(protocol: MobileRpcProtocol) {\n super();\n this._protocol = protocol;\n\n RpcManager.initializeInterface(IpcInterface);\n this._client = RpcManager.getClientForInterface(IpcInterface);\n }\n\n public send(message: IpcWebSocketMessage): void {\n if (message.type === IpcWebSocketMessageType.Send || message.type === IpcWebSocketMessageType.Invoke) {\n this.sendToBackend(message); // eslint-disable-line @typescript-eslint/no-floating-promises\n } else if (message.type === IpcWebSocketMessageType.Push || message.type === IpcWebSocketMessageType.Response) {\n this.sendToFrontend(message);\n }\n }\n\n public consumeRequest(request: SerializedRpcRequest): boolean {\n if (request.operation.interfaceDefinition !== IPC)\n return false;\n\n const message = RpcMarshaling.deserialize(this._protocol, request.parameters)[0] as IpcWebSocketMessage;\n this.broadcast({} as Event, message);\n return true;\n }\n\n public consumeResponse(response: RpcRequestFulfillment): boolean {\n if (response.interfaceName !== IPC)\n return false;\n\n const message = RpcMarshaling.deserialize(this._protocol, response.result) as IpcWebSocketMessage;\n this.broadcast({} as Event, message);\n return true;\n }\n\n private async sendToBackend(message: IpcWebSocketMessage) {\n const request = new MobileRpcRequest(this._client, \"send\", [message]);\n const encoded = await MobileRpcProtocol.encodeRequest(request);\n this._protocol.sendToBackend(encoded);\n request.dispose();\n }\n\n private sendToFrontend(message: IpcWebSocketMessage) {\n MobileEventLoop.addTask();\n const result = RpcMarshaling.serialize(this._protocol, message);\n MobileEventLoop.removeTask();\n\n const fulfillment: RpcRequestFulfillment = { result, rawResult: message, interfaceName: IPC, id: message.channel, status: 0 };\n const encoded = MobileRpcProtocol.encodeResponse(fulfillment);\n this._protocol.sendToFrontend(encoded);\n }\n\n private broadcast(evt: Event, message: IpcWebSocketMessage) {\n for (const listener of IpcWebSocket.receivers)\n listener(evt, message);\n }\n}\n"]}
|
|
@@ -21,6 +21,11 @@ var RpcMobilePlatform;
|
|
|
21
21
|
* @internal
|
|
22
22
|
*/
|
|
23
23
|
class MobileRpcConfiguration extends core_common_1.RpcConfiguration {
|
|
24
|
+
/** @internal */
|
|
25
|
+
static { this.setup = {
|
|
26
|
+
obtainPort: () => 0,
|
|
27
|
+
checkPlatform: () => typeof (process) !== "undefined" && process.platform === "ios",
|
|
28
|
+
}; }
|
|
24
29
|
static getArgs() {
|
|
25
30
|
if (typeof window !== "object" || typeof window.location !== "object" || typeof window.location.hash !== "string") {
|
|
26
31
|
return Object.freeze({});
|
|
@@ -65,11 +70,6 @@ class MobileRpcConfiguration extends core_common_1.RpcConfiguration {
|
|
|
65
70
|
static get platform() { return MobileRpcConfiguration.getMobilePlatform(); }
|
|
66
71
|
}
|
|
67
72
|
exports.MobileRpcConfiguration = MobileRpcConfiguration;
|
|
68
|
-
/** @internal */
|
|
69
|
-
MobileRpcConfiguration.setup = {
|
|
70
|
-
obtainPort: () => 0,
|
|
71
|
-
checkPlatform: () => typeof (process) !== "undefined" && process.platform === "ios",
|
|
72
|
-
};
|
|
73
73
|
/** Coordinates usage of RPC interfaces for an Mobile-based application.
|
|
74
74
|
* @internal
|
|
75
75
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileRpcManager.js","sourceRoot":"","sources":["../../../src/common/MobileRpcManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,oDAA2F;AAC3F,2DAAwD;AAExD,qDAAqD;AAErD;;GAEG;AACH,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,+DAAO,CAAA;IACP,+DAAO,CAAA;IACP,uDAAG,CAAA;AACL,CAAC,EAJW,iBAAiB,iCAAjB,iBAAiB,QAI5B;AAED;;GAEG;AACH,MAAsB,sBAAuB,SAAQ,8BAAgB;
|
|
1
|
+
{"version":3,"file":"MobileRpcManager.js","sourceRoot":"","sources":["../../../src/common/MobileRpcManager.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,oDAA2F;AAC3F,2DAAwD;AAExD,qDAAqD;AAErD;;GAEG;AACH,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,+DAAO,CAAA;IACP,+DAAO,CAAA;IACP,uDAAG,CAAA;AACL,CAAC,EAJW,iBAAiB,iCAAjB,iBAAiB,QAI5B;AAED;;GAEG;AACH,MAAsB,sBAAuB,SAAQ,8BAAgB;IACnE,gBAAgB;aACF,UAAK,GAAG;QACpB,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;QACnB,aAAa,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,WAAW,IAAK,OAAO,CAAC,QAAgB,KAAK,KAAK;KAC7F,CAAC;IAIM,MAAM,CAAC,OAAO;QACpB,IAAI,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AC,MAAM,CAAC,CAAC;QAC7C,CAAC;QAED,MAAM,QAAQ,GAAG,8BAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACjD,8BAAgB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;QAEhD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,uEAAuE;IAChE,MAAM,CAAC,gBAAgB,CAAC,UAAoC;QACjE,OAAO,gBAAgB,CAAC,qBAAqB,CAAC,UAAU,EAAE,yBAAW,CAAC,QAAQ,CAAC,CAAC;IAClF,CAAC;IACD,sEAAsE;IAC/D,MAAM,CAAC,cAAc,CAAC,UAAoC;QAC/D,OAAO,gBAAgB,CAAC,qBAAqB,CAAC,UAAU,EAAE,yBAAW,CAAC,OAAO,CAAC,CAAC;IACjF,CAAC;CACF;AApCD,4CAoCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { RpcConfiguration, RpcEndpoint, RpcInterfaceDefinition } from \"@itwin/core-common\";\nimport { MobileRpcProtocol } from \"./MobileRpcProtocol\";\n\n/* eslint-disable @typescript-eslint/no-deprecated */\n\n/** RPC supported mobile platforms.\n * @internal\n */\nexport enum RpcMobilePlatform {\n Unknown,\n Android,\n iOS,\n}\n\n/** Holds configuration for the RpcInterfaces used by the application.\n * @internal\n */\nexport abstract class MobileRpcConfiguration extends RpcConfiguration {\n /** @internal */\n public static setup = {\n obtainPort: () => 0,\n checkPlatform: () => typeof (process) !== \"undefined\" && (process.platform as any) === \"ios\",\n };\n\n public abstract override protocol: MobileRpcProtocol;\n private static _args: any;\n private static getArgs(): any {\n if (typeof window !== \"object\" || typeof window.location !== \"object\" || typeof window.location.hash !== \"string\") {\n return Object.freeze({});\n }\n const queryArgs: any = {};\n try {\n const matches = window.location.hash.match(/([^#=&]+)(=([^&]*))?/g);\n if (matches) {\n for (const comp of matches) {\n const array = comp.split(\"=\");\n if (array.length === 2) {\n const key = decodeURIComponent(array[0]);\n const val = decodeURIComponent(array[1]);\n queryArgs[key] = val;\n }\n }\n }\n } catch { }\n return Object.freeze(queryArgs);\n }\n private static getMobilePlatform(): RpcMobilePlatform {\n if (!MobileRpcConfiguration.args.platform)\n return RpcMobilePlatform.Unknown;\n\n const win: any = window;\n if (/android/i.test(MobileRpcConfiguration.args.platform)) {\n return RpcMobilePlatform.Android;\n }\n\n if (/iOS|iPadOS/i.test(MobileRpcConfiguration.args.platform) && !win.MSStream) {\n return RpcMobilePlatform.iOS;\n }\n\n return RpcMobilePlatform.Unknown;\n }\n /** Read the mobile rpc args */\n public static get args(): any {\n if (!this._args) {\n this._args = MobileRpcConfiguration.getArgs();\n }\n return this._args;\n }\n\n /** Return type of mobile platform using browser userAgent */\n public static get platform(): RpcMobilePlatform { return MobileRpcConfiguration.getMobilePlatform(); }\n}\n\n/** Coordinates usage of RPC interfaces for an Mobile-based application.\n * @internal\n */\nexport class MobileRpcManager {\n /** @internal */\n public static async ready() {\n return new Promise<void>(async (resolve) => {\n while (!(global as any).__iTwinJsRpcReady) {\n await new Promise((r) => setTimeout(r));\n }\n\n resolve();\n });\n }\n\n private static performInitialization(interfaces: RpcInterfaceDefinition[], endPoint: RpcEndpoint): MobileRpcConfiguration {\n const config = class extends MobileRpcConfiguration {\n public interfaces = () => interfaces;\n public protocol: MobileRpcProtocol = new MobileRpcProtocol(this, endPoint);\n };\n\n for (const def of interfaces) {\n RpcConfiguration.assign(def, () => config);\n }\n\n const instance = RpcConfiguration.obtain(config);\n RpcConfiguration.initializeInterfaces(instance);\n\n return instance;\n }\n\n /** Initializes MobileRpcManager for the frontend of an application. */\n public static initializeClient(interfaces: RpcInterfaceDefinition[]): MobileRpcConfiguration {\n return MobileRpcManager.performInitialization(interfaces, RpcEndpoint.Frontend);\n }\n /** Initializes MobileRpcManager for the backend of an application. */\n public static initializeImpl(interfaces: RpcInterfaceDefinition[]): MobileRpcConfiguration {\n return MobileRpcManager.performInitialization(interfaces, RpcEndpoint.Backend);\n }\n}\n\n"]}
|
|
@@ -29,9 +29,16 @@ class MobileAppNotifyHandler extends core_frontend_1.NotificationHandler {
|
|
|
29
29
|
}
|
|
30
30
|
/** @beta */
|
|
31
31
|
class MobileApp {
|
|
32
|
+
static { this.onMemoryWarning = new core_bentley_1.BeEvent(); }
|
|
33
|
+
static { this.onOrientationChanged = new core_bentley_1.BeEvent(); }
|
|
34
|
+
static { this.onEnterForeground = new core_bentley_1.BeEvent(); }
|
|
35
|
+
static { this.onEnterBackground = new core_bentley_1.BeEvent(); }
|
|
36
|
+
static { this.onWillTerminate = new core_bentley_1.BeEvent(); }
|
|
37
|
+
static { this.onAuthAccessTokenChanged = new core_bentley_1.BeEvent(); }
|
|
32
38
|
static async callBackend(methodName, ...args) {
|
|
33
39
|
return core_frontend_1.IpcApp[core_frontend_1._callIpcChannel](MobileAppChannel_1.mobileAppStrings.mobileAppChannel, methodName, ...args);
|
|
34
40
|
}
|
|
41
|
+
static { this._isValid = false; }
|
|
35
42
|
static get isValid() { return this._isValid; }
|
|
36
43
|
/** @beta */
|
|
37
44
|
static async startup(opts) {
|
|
@@ -55,13 +62,6 @@ class MobileApp {
|
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
64
|
exports.MobileApp = MobileApp;
|
|
58
|
-
MobileApp.onMemoryWarning = new core_bentley_1.BeEvent();
|
|
59
|
-
MobileApp.onOrientationChanged = new core_bentley_1.BeEvent();
|
|
60
|
-
MobileApp.onEnterForeground = new core_bentley_1.BeEvent();
|
|
61
|
-
MobileApp.onEnterBackground = new core_bentley_1.BeEvent();
|
|
62
|
-
MobileApp.onWillTerminate = new core_bentley_1.BeEvent();
|
|
63
|
-
MobileApp.onAuthAccessTokenChanged = new core_bentley_1.BeEvent();
|
|
64
|
-
MobileApp._isValid = false;
|
|
65
65
|
/*
|
|
66
66
|
The suspend/resume lifecycle events cannot be reliably sent from the backend due to timing issues that arise when
|
|
67
67
|
inter-operating with the actual suspend and resume behavior on the native side.
|
|
@@ -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,wDAAgI;AAChI,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,CAAC;YACtD,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAC9B,CAAC;QACD,SAAS,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC;IACzC,CAAC;IACM,wBAAwB,KAAK,SAAS,CAAC,oBAAoB,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAC3E,mBAAmB,KAAK,SAAS,CAAC,eAAe,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IACjE,4BAA4B,CAAC,WAA+B,EAAE,cAAkC;QACrG,SAAS,CAAC,wBAAwB,CAAC,UAAU,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;IAC7E,CAAC;CACF;AAED,YAAY;AACZ,MAAa,SAAS;
|
|
1
|
+
{"version":3,"file":"MobileApp.js","sourceRoot":"","sources":["../../../src/frontend/MobileApp.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAAyF;AACzF,oDAA0G;AAC1G,wDAAgI;AAChI,iEAA8D;AAE9D,iEAA8D;AAC9D,+EAA4E;AAK5E,yCAAyC;AACzC,MAAM,sBAAuB,SAAQ,mCAAmB;IACtD,IAAW,WAAW,KAAK,OAAO,mCA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,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { AsyncMethodsOf, BeEvent, Logger, PromiseReturnType } from \"@itwin/core-bentley\";\nimport { IModelReadRpcInterface, IModelTileRpcInterface, IpcWebSocketFrontend } from \"@itwin/core-common\";\nimport { _callIpcChannel, IModelAppOptions, IpcApp, NativeApp, NativeAppOpts, NotificationHandler } from \"@itwin/core-frontend\";\nimport { mobileAppStrings } from \"../common/MobileAppChannel\";\nimport { MobileAppFunctions, MobileNotifications } from \"../common/MobileAppProps\";\nimport { MobileRpcManager } from \"../common/MobileRpcManager\";\nimport { MobileAuthorizationFrontend } from \"./MobileAuthorizationFrontend\";\n\n/** @beta */\nexport type MobileAppOpts = NativeAppOpts & { iModelApp: { authorizationClient?: never } };\n\n/** receive notifications from backend */\nclass MobileAppNotifyHandler extends NotificationHandler implements MobileNotifications {\n public get channelName() { return mobileAppStrings.mobileAppNotify; }\n\n public notifyMemoryWarning() {\n Logger.logWarning(\"mobileApp\", \"Low memory warning\");\n if (MobileApp.onMemoryWarning.numberOfListeners === 0) {\n alert(\"Low memory warning\");\n }\n MobileApp.onMemoryWarning.raiseEvent();\n }\n public notifyOrientationChanged() { MobileApp.onOrientationChanged.raiseEvent(); }\n public notifyWillTerminate() { MobileApp.onWillTerminate.raiseEvent(); }\n public notifyAuthAccessTokenChanged(accessToken: string | undefined, expirationDate: string | undefined) {\n MobileApp.onAuthAccessTokenChanged.raiseEvent(accessToken, expirationDate);\n }\n}\n\n/** @beta */\nexport class MobileApp {\n public static onMemoryWarning = new BeEvent<() => void>();\n public static onOrientationChanged = new BeEvent<() => void>();\n public static onEnterForeground = new BeEvent<() => void>();\n public static onEnterBackground = new BeEvent<() => void>();\n public static onWillTerminate = new BeEvent<() => void>();\n public static onAuthAccessTokenChanged = new BeEvent<(accessToken: string | undefined, expirationDate: string | undefined) => void>();\n public static async callBackend<T extends AsyncMethodsOf<MobileAppFunctions>>(methodName: T, ...args: Parameters<MobileAppFunctions[T]>) {\n return IpcApp[_callIpcChannel](mobileAppStrings.mobileAppChannel, methodName, ...args) as PromiseReturnType<MobileAppFunctions[T]>;\n }\n\n private static _isValid = false;\n public static get isValid() { return this._isValid; }\n /** @beta */\n public static async startup(opts?: MobileAppOpts) {\n attachDirectEventCallbacks();\n\n const iModelAppOpts: IModelAppOptions = {\n ...opts?.iModelApp,\n };\n const authorizationClient = new MobileAuthorizationFrontend();\n iModelAppOpts.authorizationClient = authorizationClient;\n\n if (!this._isValid) {\n this.onAuthAccessTokenChanged.addListener((accessToken: string | undefined, expirationDate: string | undefined) => {\n authorizationClient.setAccessToken(accessToken, expirationDate);\n });\n\n const rpcInterfaces = opts?.iModelApp?.rpcInterfaces ?? [IModelReadRpcInterface, IModelTileRpcInterface]; // eslint-disable-line @typescript-eslint/no-deprecated\n MobileRpcManager.initializeClient(rpcInterfaces);\n this._isValid = true;\n }\n\n const socket = new IpcWebSocketFrontend(); // needs work\n await NativeApp.startup(socket, { ...opts, iModelApp: iModelAppOpts });\n\n MobileAppNotifyHandler.register(); // receives notifications from backend\n }\n}\n\n/*\n The suspend/resume lifecycle events cannot be reliably sent from the backend due to timing issues that arise when\n inter-operating with the actual suspend and resume behavior on the native side.\n Instead, they are sent directly to the browser here from platform-specific code.\n*/\nfunction attachDirectEventCallbacks() {\n (window as any)._imodeljs_rpc_lifecycle = (evt: \"suspend\" | \"resume\") => {\n if (evt === \"suspend\") {\n MobileApp.onEnterBackground.raiseEvent();\n } else if (evt === \"resume\") {\n MobileApp.onEnterForeground.raiseEvent();\n }\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-mobile",
|
|
3
|
-
"version": "5.0.0-dev.
|
|
3
|
+
"version": "5.0.0-dev.34",
|
|
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": "5.0.0-dev.
|
|
26
|
-
"@itwin/core-
|
|
27
|
-
"@itwin/core-
|
|
28
|
-
"@itwin/core-
|
|
25
|
+
"@itwin/core-backend": "5.0.0-dev.34",
|
|
26
|
+
"@itwin/core-frontend": "5.0.0-dev.34",
|
|
27
|
+
"@itwin/core-bentley": "5.0.0-dev.34",
|
|
28
|
+
"@itwin/core-common": "5.0.0-dev.34"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"lodash": "^4.17.21",
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
"mocha": "^10.2.0",
|
|
50
50
|
"rimraf": "^3.0.2",
|
|
51
51
|
"typescript": "~5.6.2",
|
|
52
|
-
"@itwin/
|
|
53
|
-
"@itwin/
|
|
54
|
-
"@itwin/core-bentley": "5.0.0-dev.
|
|
55
|
-
"@itwin/core-frontend": "5.0.0-dev.
|
|
56
|
-
"@itwin/core-common": "5.0.0-dev.
|
|
52
|
+
"@itwin/build-tools": "5.0.0-dev.34",
|
|
53
|
+
"@itwin/core-backend": "5.0.0-dev.34",
|
|
54
|
+
"@itwin/core-bentley": "5.0.0-dev.34",
|
|
55
|
+
"@itwin/core-frontend": "5.0.0-dev.34",
|
|
56
|
+
"@itwin/core-common": "5.0.0-dev.34"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "npm run -s build:cjs",
|