@itwin/core-mobile 4.0.0-dev.23 → 4.0.0-dev.28

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/CHANGELOG.md CHANGED
@@ -11,6 +11,11 @@ Wed, 08 Feb 2023 14:58:40 GMT
11
11
  - Fix for mobile app lifcycle crash
12
12
  - React to RPC deprecations.
13
13
 
14
+ ## 3.5.6
15
+ Fri, 24 Feb 2023 16:02:47 GMT
16
+
17
+ _Version update only_
18
+
14
19
  ## 3.5.5
15
20
  Thu, 26 Jan 2023 22:53:27 GMT
16
21
 
@@ -39,7 +39,7 @@ class MobileAuthorizationBackend {
39
39
  }
40
40
  }
41
41
  setAccessToken(accessToken, expirationDate) {
42
- this._accessToken = accessToken !== null && accessToken !== void 0 ? accessToken : "";
42
+ this._accessToken = accessToken ?? "";
43
43
  this._expirationDate = expirationDate ? new Date(expirationDate) : undefined;
44
44
  }
45
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MobileAuthorizationBackend.js","sourceRoot":"","sources":["../../../src/backend/MobileAuthorizationBackend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH,6CAA0C;AAE1C;;GAEG;AACH,MAAa,0BAA0B;IAAvC;QACU,iBAAY,GAAgB,EAAE,CAAC;QAE/B,kBAAa,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,cAAc;QACvC,mBAAc,GAAG,KAAK,CAAC;IA4BjC,CAAC;IA1BC,IAAY,WAAW;QACrB,OAAO,IAAI,CAAC,eAAe,KAAK,SAAS,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IACxH,CAAC;IAEM,KAAK,CAAC,cAAc;QACzB,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,oDAAoD;SAC9E;QAED,IAAI,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YAC1C,OAAO,IAAI,CAAC,YAAY,CAAC;SAC1B;aAAM;YACL,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,MAAM,MAAM,GAAG,MAAM,uBAAU,CAAC,kBAAkB,EAAE,CAAC;YACrD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC9B,IAAI,MAAM,CAAC,CAAC,CAAC;gBACX,IAAI,CAAC,eAAe,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7C,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;YAC5B,OAAO,IAAI,CAAC,YAAY,CAAC;SAC1B;IACH,CAAC;IAEM,cAAc,CAAC,WAAoB,EAAE,cAAuB;QACjE,IAAI,CAAC,YAAY,GAAG,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,EAAE,CAAC;QACtC,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,CAAC;CACF;AAhCD,gEAgCC","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 OIDC\n */\n\nimport { AccessToken } from \"@itwin/core-bentley\";\nimport { AuthorizationClient } from \"@itwin/core-common\";\nimport { MobileHost } from \"./MobileHost\";\n\n/** Utility to provide and cache auth tokens from native mobile apps to IModelHost.\n * @internal\n */\nexport class MobileAuthorizationBackend implements AuthorizationClient {\n private _accessToken: AccessToken = \"\";\n private _expirationDate: Date | undefined;\n private _expiryBuffer = 60 * 10; // ten minutes\n private _fetchingToken = false;\n\n private get _hasExpired(): boolean {\n return this._expirationDate !== undefined && this._expirationDate.getTime() - Date.now() <= this._expiryBuffer * 1000;\n }\n\n public async getAccessToken(): Promise<AccessToken> {\n if (this._fetchingToken) {\n return Promise.reject(); // short-circuits any recursive use of this function\n }\n\n if (this._accessToken && !this._hasExpired) {\n return this._accessToken;\n } else {\n this._fetchingToken = true;\n const result = await MobileHost.authGetAccessToken();\n this._accessToken = result[0];\n if (result[1])\n this._expirationDate = new Date(result[1]);\n this._fetchingToken = false;\n return this._accessToken;\n }\n }\n\n public setAccessToken(accessToken?: string, expirationDate?: string) {\n this._accessToken = accessToken ?? \"\";\n this._expirationDate = expirationDate ? new Date(expirationDate) : undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"MobileAuthorizationBackend.js","sourceRoot":"","sources":["../../../src/backend/MobileAuthorizationBackend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH,6CAA0C;AAE1C;;GAEG;AACH,MAAa,0BAA0B;IAAvC;QACU,iBAAY,GAAgB,EAAE,CAAC;QAE/B,kBAAa,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,cAAc;QACvC,mBAAc,GAAG,KAAK,CAAC;IA4BjC,CAAC;IA1BC,IAAY,WAAW;QACrB,OAAO,IAAI,CAAC,eAAe,KAAK,SAAS,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IACxH,CAAC;IAEM,KAAK,CAAC,cAAc;QACzB,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,oDAAoD;SAC9E;QAED,IAAI,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YAC1C,OAAO,IAAI,CAAC,YAAY,CAAC;SAC1B;aAAM;YACL,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,MAAM,MAAM,GAAG,MAAM,uBAAU,CAAC,kBAAkB,EAAE,CAAC;YACrD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC9B,IAAI,MAAM,CAAC,CAAC,CAAC;gBACX,IAAI,CAAC,eAAe,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7C,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;YAC5B,OAAO,IAAI,CAAC,YAAY,CAAC;SAC1B;IACH,CAAC;IAEM,cAAc,CAAC,WAAoB,EAAE,cAAuB;QACjE,IAAI,CAAC,YAAY,GAAG,WAAW,IAAI,EAAE,CAAC;QACtC,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,CAAC;CACF;AAhCD,gEAgCC","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 OIDC\n */\n\nimport { AccessToken } from \"@itwin/core-bentley\";\nimport { AuthorizationClient } from \"@itwin/core-common\";\nimport { MobileHost } from \"./MobileHost\";\n\n/** Utility to provide and cache auth tokens from native mobile apps to IModelHost.\n * @internal\n */\nexport class MobileAuthorizationBackend implements AuthorizationClient {\n private _accessToken: AccessToken = \"\";\n private _expirationDate: Date | undefined;\n private _expiryBuffer = 60 * 10; // ten minutes\n private _fetchingToken = false;\n\n private get _hasExpired(): boolean {\n return this._expirationDate !== undefined && this._expirationDate.getTime() - Date.now() <= this._expiryBuffer * 1000;\n }\n\n public async getAccessToken(): Promise<AccessToken> {\n if (this._fetchingToken) {\n return Promise.reject(); // short-circuits any recursive use of this function\n }\n\n if (this._accessToken && !this._hasExpired) {\n return this._accessToken;\n } else {\n this._fetchingToken = true;\n const result = await MobileHost.authGetAccessToken();\n this._accessToken = result[0];\n if (result[1])\n this._expirationDate = new Date(result[1]);\n this._fetchingToken = false;\n return this._accessToken;\n }\n }\n\n public setAccessToken(accessToken?: string, expirationDate?: string) {\n this._accessToken = accessToken ?? \"\";\n this._expirationDate = expirationDate ? new Date(expirationDate) : undefined;\n }\n}\n"]}
@@ -69,7 +69,7 @@ class MobileHost {
69
69
  if (error) {
70
70
  reject(error);
71
71
  }
72
- resolve([tokenString !== null && tokenString !== void 0 ? tokenString : "", expirationDate !== null && expirationDate !== void 0 ? expirationDate : ""]);
72
+ resolve([tokenString ?? "", expirationDate ?? ""]);
73
73
  });
74
74
  });
75
75
  }
@@ -109,10 +109,9 @@ class MobileHost {
109
109
  static get isValid() { return undefined !== this._device; }
110
110
  /** Start the backend of a mobile app. */
111
111
  static async startup(opt) {
112
- var _a, _b, _c, _d, _e, _f, _g;
113
112
  const authorizationClient = new MobileAuthorizationBackend_1.MobileAuthorizationBackend();
114
113
  if (!this.isValid) {
115
- this._device = (_b = (_a = opt === null || opt === void 0 ? void 0 : opt.mobileHost) === null || _a === void 0 ? void 0 : _a.device) !== null && _b !== void 0 ? _b : new MobileDevice();
114
+ this._device = opt?.mobileHost?.device ?? new MobileDevice();
116
115
  // set global device interface.
117
116
  global.__iTwinJsNativeBridge = this._device;
118
117
  this.onMemoryWarning.addListener(() => {
@@ -131,14 +130,14 @@ class MobileHost {
131
130
  // following will provide impl for device specific api.
132
131
  (0, MobileRpcServer_1.setupMobileRpc)();
133
132
  }
134
- const socket = (_d = (_c = opt === null || opt === void 0 ? void 0 : opt.ipcHost) === null || _c === void 0 ? void 0 : _c.socket) !== null && _d !== void 0 ? _d : new core_common_1.IpcWebSocketBackend();
135
- opt = { ...opt, mobileHost: { ...opt === null || opt === void 0 ? void 0 : opt.mobileHost }, ipcHost: { ...opt === null || opt === void 0 ? void 0 : opt.ipcHost, socket } };
136
- const iModelHost = (_e = opt === null || opt === void 0 ? void 0 : opt.iModelHost) !== null && _e !== void 0 ? _e : {};
133
+ const socket = opt?.ipcHost?.socket ?? new core_common_1.IpcWebSocketBackend();
134
+ opt = { ...opt, mobileHost: { ...opt?.mobileHost }, ipcHost: { ...opt?.ipcHost, socket } };
135
+ const iModelHost = opt?.iModelHost ?? {};
137
136
  iModelHost.authorizationClient = authorizationClient;
138
137
  await core_backend_1.NativeHost.startup({ ...opt, iModelHost });
139
138
  if (core_backend_1.IpcHost.isValid)
140
139
  MobileAppHandler.register();
141
- const rpcInterfaces = (_g = (_f = opt === null || opt === void 0 ? void 0 : opt.mobileHost) === null || _f === void 0 ? void 0 : _f.rpcInterfaces) !== null && _g !== void 0 ? _g : [
140
+ const rpcInterfaces = opt?.mobileHost?.rpcInterfaces ?? [
142
141
  core_common_1.IModelReadRpcInterface,
143
142
  core_common_1.IModelTileRpcInterface,
144
143
  core_common_1.SnapshotIModelRpcInterface,
@@ -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,oDAG4B;AAC5B,2DAAwF;AAExF,oEAAsE;AACtE,iEAA+E;AAE/E,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,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,UAA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CAAE,UAAU,0CAAE,aAAa,mCAAI;YACtD,oCAAsB;YACtB,oCAAsB;YACtB,wCAA0B;YAC1B,8CAAwB;SACzB,CAAC;QAEF,mCAAgB,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IACjD,CAAC;;AAjHH,gCAkHC;AA/GwB,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","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 {\n IModelReadRpcInterface, IModelTileRpcInterface, IpcWebSocketBackend, RpcInterfaceDefinition,\n SnapshotIModelRpcInterface,\n} from \"@itwin/core-common\";\nimport { CancelRequest, DownloadFailed, UserCancelledError } from \"./MobileFileHandler\";\nimport { ProgressCallback } from \"./Request\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { mobileAppChannel, mobileAppNotify } 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 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 public static readonly onMemoryWarning = new BeEvent();\n public static readonly onOrientationChanged = new BeEvent();\n public static readonly onEnterForeground = new BeEvent();\n public static readonly onEnterBackground = new BeEvent();\n public static readonly onWillTerminate = new BeEvent();\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(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(error);\n }\n resolve([tokenString ?? \"\", expirationDate ?? \"\"]);\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 // eslint-disable-next-line @typescript-eslint/unbound-method\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 (global as any).__iTwinJsNativeBridge = this._device;\n this.onMemoryWarning.addListener(() => {\n MobileHost.notifyMobileFrontend(\"notifyMemoryWarning\");\n });\n this.onOrientationChanged.addListener(() => {\n MobileHost.notifyMobileFrontend(\"notifyOrientationChanged\");\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 IModelReadRpcInterface,\n IModelTileRpcInterface,\n SnapshotIModelRpcInterface,\n PresentationRpcInterface,\n ];\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,oDAG4B;AAC5B,2DAAwF;AAExF,oEAAsE;AACtE,iEAA+E;AAE/E,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,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,CAAC;gBAC/C,MAAM;YACR,KAAK,wBAAwB;gBAC3B,UAAU,CAAC,wBAAwB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBACjE,MAAM;SACT;IACH,CAAC;CAYF;AAlCD,oCAkCC;AAED,MAAM,gBAAiB,SAAQ,yBAAU;IACvC,IAAW,WAAW,KAAK,OA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DAAuD;YACvD,IAAA,gCAAc,GAAE,CAAC;SAClB;QAED,MAAM,MAAM,GAAG,GAAG,EAAE,OAAO,EAAE,MAAM,IAAI,IAAI,iCAAmB,EAAE,CAAC;QACjE,GAAG,GAAG,EAAE,GAAG,GAAG,EAAE,UAAU,EAAE,EAAE,GAAG,GAAG,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,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;YACtD,oCAAsB;YACtB,oCAAsB;YACtB,wCAA0B;YAC1B,8CAAwB;SACzB,CAAC;QAEF,mCAAgB,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IACjD,CAAC;;AAjHH,gCAkHC;AA/GwB,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","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 {\n IModelReadRpcInterface, IModelTileRpcInterface, IpcWebSocketBackend, RpcInterfaceDefinition,\n SnapshotIModelRpcInterface,\n} from \"@itwin/core-common\";\nimport { CancelRequest, DownloadFailed, UserCancelledError } from \"./MobileFileHandler\";\nimport { ProgressCallback } from \"./Request\";\nimport { PresentationRpcInterface } from \"@itwin/presentation-common\";\nimport { mobileAppChannel, mobileAppNotify } 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 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 public static readonly onMemoryWarning = new BeEvent();\n public static readonly onOrientationChanged = new BeEvent();\n public static readonly onEnterForeground = new BeEvent();\n public static readonly onEnterBackground = new BeEvent();\n public static readonly onWillTerminate = new BeEvent();\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(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(error);\n }\n resolve([tokenString ?? \"\", expirationDate ?? \"\"]);\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 // eslint-disable-next-line @typescript-eslint/unbound-method\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 (global as any).__iTwinJsNativeBridge = this._device;\n this.onMemoryWarning.addListener(() => {\n MobileHost.notifyMobileFrontend(\"notifyMemoryWarning\");\n });\n this.onOrientationChanged.addListener(() => {\n MobileHost.notifyMobileFrontend(\"notifyOrientationChanged\");\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 IModelReadRpcInterface,\n IModelTileRpcInterface,\n SnapshotIModelRpcInterface,\n PresentationRpcInterface,\n ];\n\n MobileRpcManager.initializeImpl(rpcInterfaces);\n }\n}\n"]}
@@ -113,7 +113,7 @@ function setupMobileRpc() {
113
113
  }
114
114
  if (core_bentley_1.ProcessDetector.isMobileAppBackend) {
115
115
  addon = process._linkedBinding("iModelJsMobile");
116
- addon === null || addon === void 0 ? void 0 : addon.registerDeviceImpl();
116
+ addon?.registerDeviceImpl();
117
117
  }
118
118
  let server = new MobileRpcServer();
119
119
  /* The UV event loop (internal to node) is retained by handles,
@@ -1 +1 @@
1
- {"version":3,"file":"MobileRpcServer.js","sourceRoot":"","sources":["../../../src/backend/MobileRpcServer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,oDAAgE;AAChE,mEAAkF;AAClF,iEAAoE;AACpE,6CAA0C;AAC1C,sDAAsD;AAStD,IAAI,KAA8B,CAAC;AAEnC,gBAAg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AC;AACrB,CAAC;AAzDD,wCAyDC","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\n/* eslint-disable deprecation/deprecation */\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() {\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 (global as any).__iTwinJsRpcReady = true;\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 _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.Timer | undefined;\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 server = null;\n });\n\n MobileHost.onEnterForeground.addListener(() => {\n if (!hasSuspended) {\n return;\n }\n\n server = new MobileRpcServer();\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;;;AAE/F,yBAAyB;AACzB,oDAAgE;AAChE,mEAAkF;AAClF,iEAAoE;AACpE,6CAA0C;AAC1C,sDAAsD;AAStD,IAAI,KAA8B,CAAC;AAEnC,gBAAgB;AAChB,MAAa,eAAe;IAgB1B;QACE;;;;;;;;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;QA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AW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE;QAC5C,IAAI,CAAC,YAAY,EAAE;YACjB,OAAO;SACR;QAED,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QAC/B,aAAa,CAAC,YAAY,CAAC,CAAC;QAC5B,YAAY,GAAG,SAAS,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,eAAe,CAAC,WAAW,CAAC,GAAG,EAAE;QAC1C,IAAI,OAAO,CAAC,YAAY,CAAC,KAAK,WAAW,EAAE;YACzC,aAAa,CAAC,YAAY,CAAC,CAAC;YAC5B,YAAY,GAAG,SAAS,CAAC;SAC1B;QAED,IAAI,MAAM,KAAK,IAAI,EAAE;YACnB,OAAO;SACR;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;AAzDD,wCAyDC","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\n/* eslint-disable deprecation/deprecation */\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() {\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 (global as any).__iTwinJsRpcReady = true;\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 _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.Timer | undefined;\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 server = null;\n });\n\n MobileHost.onEnterForeground.addListener(() => {\n if (!hasSuspended) {\n return;\n }\n\n server = new MobileRpcServer();\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"]}
@@ -35,10 +35,9 @@ class MobileApp {
35
35
  static get isValid() { return this._isValid; }
36
36
  /** @beta */
37
37
  static async startup(opts) {
38
- var _a, _b;
39
38
  attachDirectEventCallbacks();
40
39
  const iModelAppOpts = {
41
- ...opts === null || opts === void 0 ? void 0 : opts.iModelApp,
40
+ ...opts?.iModelApp,
42
41
  };
43
42
  const authorizationClient = new MobileAuthorizationFrontend_1.MobileAuthorizationFrontend();
44
43
  iModelAppOpts.authorizationClient = authorizationClient;
@@ -46,7 +45,7 @@ class MobileApp {
46
45
  this.onAuthAccessTokenChanged.addListener((accessToken, expirationDate) => {
47
46
  authorizationClient.setAccessToken(accessToken, expirationDate);
48
47
  });
49
- const rpcInterfaces = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.iModelApp) === null || _a === void 0 ? void 0 : _a.rpcInterfaces) !== null && _b !== void 0 ? _b : [core_common_1.IModelReadRpcInterface, core_common_1.IModelTileRpcInterface];
48
+ const rpcInterfaces = opts?.iModelApp?.rpcInterfaces ?? [core_common_1.IModelReadRpcInterface, core_common_1.IModelTileRpcInterface];
50
49
  MobileRpcManager_1.MobileRpcManager.initializeClient(rpcInterfaces);
51
50
  this._isValid = true;
52
51
  }
@@ -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,iEAA+E;AAE/E,iEAA8D;AAC9D,+EAA4E;AAK5E,yCAAyC;AACzC,MAAM,sBAAuB,SAAQ,mCAAmB;IACtD,IAAW,WAAW,KAAK,OAAO,kCA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------------------------------------------------------------------------------------------\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 { IModelAppOptions, IpcApp, NativeApp, NativeAppOpts, NotificationHandler } from \"@itwin/core-frontend\";\nimport { mobileAppChannel, mobileAppNotify } 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 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(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];\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"]}
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,iEAA+E;AAE/E,iEAA8D;AAC9D,+EAA4E;AAK5E,yCAAyC;AACzC,MAAM,sBAAuB,SAAQ,mCAAmB;I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E,EAAE;gBAChH,mBAAmB,CAAC,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;YAClE,CAAC,CAAC,CAAC;YAEH,MAAM,aAAa,GAAG,IAAI,EAAE,SAAS,EAAE,aAAa,IAAI,CAAC,oCAAsB,EAAE,oCAAsB,CAAC,CAAC;YACzG,mCAAgB,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;YACjD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;SACtB;QAED,MAAM,MAAM,GAAG,IAAI,kCAAoB,EAAE,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;;AArCH,8BAsCC;AArCe,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;AA6BlC;;;;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":["/*---------------------------------------------------------------------------------------------\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 { IModelAppOptions, IpcApp, NativeApp, NativeAppOpts, NotificationHandler } from \"@itwin/core-frontend\";\nimport { mobileAppChannel, mobileAppNotify } 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 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(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];\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"]}
@@ -39,7 +39,7 @@ class MobileAuthorizationFrontend {
39
39
  }
40
40
  }
41
41
  setAccessToken(accessToken, expirationDate) {
42
- this._accessToken = accessToken !== null && accessToken !== void 0 ? accessToken : "";
42
+ this._accessToken = accessToken ?? "";
43
43
  this._expirationDate = expirationDate ? new Date(expirationDate) : undefined;
44
44
  }
45
45
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MobileAuthorizationFrontend.js","sourceRoot":"","sources":["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e,GAAG,cAAc,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,CAAC;CACF;AAhCD,kEAgCC","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 OIDC\n */\n\nimport { AccessToken } from \"@itwin/core-bentley\";\nimport { AuthorizationClient } from \"@itwin/core-common\";\nimport { MobileApp } from \"./MobileApp\";\n\n/** Utility to provide and cache auth tokens from native mobile apps to IModelApp.\n * @internal\n */\nexport class MobileAuthorizationFrontend implements AuthorizationClient {\n private _accessToken: AccessToken = \"\";\n private _expirationDate: Date | undefined;\n private _expiryBuffer = 60 * 10; // ten minutes\n private _fetchingToken = false;\n\n private get _hasExpired(): boolean {\n return this._expirationDate !== undefined && this._expirationDate.getTime() - Date.now() <= this._expiryBuffer * 1000;\n }\n\n public async getAccessToken(): Promise<AccessToken> {\n if (this._fetchingToken) {\n return Promise.reject(); // short-circuits any recursive use of this function\n }\n\n if (this._accessToken && !this._hasExpired) {\n return this._accessToken;\n } else {\n this._fetchingToken = true;\n const result = await MobileApp.callBackend(\"getAccessToken\");\n this._accessToken = result[0];\n if (result[1])\n this._expirationDate = new Date(result[1]);\n this._fetchingToken = false;\n return this._accessToken;\n }\n }\n\n public setAccessToken(accessToken?: string, expirationDate?: string) {\n this._accessToken = accessToken ?? \"\";\n this._expirationDate = expirationDate ? new Date(expirationDate) : undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"MobileAuthorizationFrontend.js","sourceRoot":"","sources":["../../../src/frontend/MobileAuthorizationFrontend.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH,2CAAwC;AAExC;;GAEG;AACH,MAAa,2BAA2B;IAAxC;QACU,iBAAY,GAAgB,EAAE,CAAC;QAE/B,kBAAa,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,cAAc;QACvC,mBAAc,GAAG,KAAK,CAAC;IA4BjC,CAAC;IA1BC,IAAY,WAAW;QACrB,OAAO,IAAI,CAAC,eAAe,KAAK,SAAS,IAAI,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IACxH,CAAC;IAEM,KAAK,CAAC,cAAc;QACzB,IAAI,IAAI,CAAC,cAAc,EAAE;YACvB,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,oDAAoD;SAC9E;QAED,IAAI,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YAC1C,OAAO,IAAI,CAAC,YAAY,CAAC;SAC1B;aAAM;YACL,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,MAAM,MAAM,GAAG,MAAM,qBAAS,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;YAC7D,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC9B,IAAI,MAAM,CAAC,CAAC,CAAC;gBACX,IAAI,CAAC,eAAe,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7C,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;YAC5B,OAAO,IAAI,CAAC,YAAY,CAAC;SAC1B;IACH,CAAC;IAEM,cAAc,CAAC,WAAoB,EAAE,cAAuB;QACjE,IAAI,CAAC,YAAY,GAAG,WAAW,IAAI,EAAE,CAAC;QACtC,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,CAAC;CACF;AAhCD,kEAgCC","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 OIDC\n */\n\nimport { AccessToken } from \"@itwin/core-bentley\";\nimport { AuthorizationClient } from \"@itwin/core-common\";\nimport { MobileApp } from \"./MobileApp\";\n\n/** Utility to provide and cache auth tokens from native mobile apps to IModelApp.\n * @internal\n */\nexport class MobileAuthorizationFrontend implements AuthorizationClient {\n private _accessToken: AccessToken = \"\";\n private _expirationDate: Date | undefined;\n private _expiryBuffer = 60 * 10; // ten minutes\n private _fetchingToken = false;\n\n private get _hasExpired(): boolean {\n return this._expirationDate !== undefined && this._expirationDate.getTime() - Date.now() <= this._expiryBuffer * 1000;\n }\n\n public async getAccessToken(): Promise<AccessToken> {\n if (this._fetchingToken) {\n return Promise.reject(); // short-circuits any recursive use of this function\n }\n\n if (this._accessToken && !this._hasExpired) {\n return this._accessToken;\n } else {\n this._fetchingToken = true;\n const result = await MobileApp.callBackend(\"getAccessToken\");\n this._accessToken = result[0];\n if (result[1])\n this._expirationDate = new Date(result[1]);\n this._fetchingToken = false;\n return this._accessToken;\n }\n }\n\n public setAccessToken(accessToken?: string, expirationDate?: string) {\n this._accessToken = accessToken ?? \"\";\n this._expirationDate = expirationDate ? new Date(expirationDate) : undefined;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-mobile",
3
- "version": "4.0.0-dev.23",
3
+ "version": "4.0.0-dev.28",
4
4
  "description": "iTwin.js MobileHost and MobileApp",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -21,11 +21,11 @@
21
21
  "url": "http://www.bentley.com"
22
22
  },
23
23
  "peerDependencies": {
24
- "@itwin/core-backend": "^4.0.0-dev.23",
25
- "@itwin/core-bentley": "^4.0.0-dev.23",
26
- "@itwin/core-common": "^4.0.0-dev.23",
27
- "@itwin/core-frontend": "^4.0.0-dev.23",
28
- "@itwin/presentation-common": "^4.0.0-dev.23"
24
+ "@itwin/core-backend": "^4.0.0-dev.28",
25
+ "@itwin/core-bentley": "^4.0.0-dev.28",
26
+ "@itwin/core-common": "^4.0.0-dev.28",
27
+ "@itwin/core-frontend": "^4.0.0-dev.28",
28
+ "@itwin/presentation-common": "^4.0.0-dev.28"
29
29
  },
30
30
  "dependencies": {
31
31
  "deep-assign": "^2.0.0",
@@ -36,13 +36,13 @@
36
36
  "ws": "^7.5.3"
37
37
  },
38
38
  "devDependencies": {
39
- "@itwin/build-tools": "4.0.0-dev.23",
40
- "@itwin/core-backend": "4.0.0-dev.23",
41
- "@itwin/core-bentley": "4.0.0-dev.23",
42
- "@itwin/core-common": "4.0.0-dev.23",
43
- "@itwin/core-frontend": "4.0.0-dev.23",
44
- "@itwin/eslint-plugin": "4.0.0-dev.23",
45
- "@itwin/presentation-common": "4.0.0-dev.23",
39
+ "@itwin/build-tools": "4.0.0-dev.28",
40
+ "@itwin/core-backend": "4.0.0-dev.28",
41
+ "@itwin/core-bentley": "4.0.0-dev.28",
42
+ "@itwin/core-common": "4.0.0-dev.28",
43
+ "@itwin/core-frontend": "4.0.0-dev.28",
44
+ "@itwin/eslint-plugin": "4.0.0-dev.28",
45
+ "@itwin/presentation-common": "4.0.0-dev.28",
46
46
  "@types/chai": "4.3.1",
47
47
  "@types/deep-assign": "^0.1.0",
48
48
  "@types/fs-extra": "^4.0.7",