@itwin/core-mobile 5.0.0-dev.8 → 5.0.0-dev.83

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +46 -1
  2. package/lib/cjs/backend/MobileAuthorizationBackend.js +4 -5
  3. package/lib/cjs/backend/MobileAuthorizationBackend.js.map +1 -1
  4. package/lib/cjs/backend/MobileFileHandler.js +2 -0
  5. package/lib/cjs/backend/MobileFileHandler.js.map +1 -1
  6. package/lib/cjs/backend/MobileHost.js +34 -33
  7. package/lib/cjs/backend/MobileHost.js.map +1 -1
  8. package/lib/cjs/backend/MobileRpcServer.d.ts +1 -1
  9. package/lib/cjs/backend/MobileRpcServer.d.ts.map +1 -1
  10. package/lib/cjs/backend/MobileRpcServer.js +18 -12
  11. package/lib/cjs/backend/MobileRpcServer.js.map +1 -1
  12. package/lib/cjs/backend/Request.js +3 -0
  13. package/lib/cjs/backend/Request.js.map +1 -1
  14. package/lib/cjs/common/MobileEventLoop.js +2 -2
  15. package/lib/cjs/common/MobileEventLoop.js.map +1 -1
  16. package/lib/cjs/common/MobileIpc.d.ts.map +1 -1
  17. package/lib/cjs/common/MobileIpc.js +69 -6
  18. package/lib/cjs/common/MobileIpc.js.map +1 -1
  19. package/lib/cjs/common/MobilePush.js +4 -2
  20. package/lib/cjs/common/MobilePush.js.map +1 -1
  21. package/lib/cjs/common/MobileRpcManager.js +8 -10
  22. package/lib/cjs/common/MobileRpcManager.js.map +1 -1
  23. package/lib/cjs/common/MobileRpcProtocol.js +13 -11
  24. package/lib/cjs/common/MobileRpcProtocol.js.map +1 -1
  25. package/lib/cjs/common/MobileRpcRequest.js +4 -7
  26. package/lib/cjs/common/MobileRpcRequest.js.map +1 -1
  27. package/lib/cjs/frontend/MobileApp.js +7 -7
  28. package/lib/cjs/frontend/MobileApp.js.map +1 -1
  29. package/lib/cjs/frontend/MobileAuthorizationFrontend.js +4 -5
  30. package/lib/cjs/frontend/MobileAuthorizationFrontend.js.map +1 -1
  31. package/package.json +14 -14
@@ -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;IAInB,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;AArBgB,4BAAY,GAAG,CAAC,CAAC;AACjB,6BAAa,GAA0B,IAAI,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/** @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"]}
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;IAClB,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC;IACxB,MAAM,CAAC,aAAa,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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MobileIpc.d.ts","sourceRoot":"","sources":["../../../src/common/MobileIpc.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACS,mBAAmB,EAA2B,qBAAqB,EAA2C,qBAAqB,EACjJ,oBAAoB,EACrB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAWxD,gBAAgB;AAChB,qBAAa,kBAAmB,SAAQ,qBAAqB;IAC3D,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,OAAO,CAAe;gBAEX,QAAQ,EAAE,iBAAiB;IAQvC,IAAI,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAQxC,cAAc,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO;IAStD,eAAe,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO;YASlD,aAAa;IAO3B,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,SAAS;CAIlB"}
1
+ {"version":3,"file":"MobileIpc.d.ts","sourceRoot":"","sources":["../../../src/common/MobileIpc.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EACS,mBAAmB,EAA2B,qBAAqB,EAA2C,qBAAqB,EACjJ,oBAAoB,EACrB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAWxD,gBAAgB;AAChB,qBAAa,kBAAmB,SAAQ,qBAAqB;IAC3D,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,OAAO,CAAe;gBAEX,QAAQ,EAAE,iBAAiB;IAQvC,IAAI,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAQxC,cAAc,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO;IAStD,eAAe,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO;YASlD,aAAa;IAM3B,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,SAAS;CAIlB"}
@@ -6,6 +6,58 @@
6
6
  /** @packageDocumentation
7
7
  * @module RpcInterface
8
8
  */
9
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
10
+ if (value !== null && value !== void 0) {
11
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
12
+ var dispose, inner;
13
+ if (async) {
14
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
15
+ dispose = value[Symbol.asyncDispose];
16
+ }
17
+ if (dispose === void 0) {
18
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
19
+ dispose = value[Symbol.dispose];
20
+ if (async) inner = dispose;
21
+ }
22
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
23
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
24
+ env.stack.push({ value: value, dispose: dispose, async: async });
25
+ }
26
+ else if (async) {
27
+ env.stack.push({ async: true });
28
+ }
29
+ return value;
30
+ };
31
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
32
+ return function (env) {
33
+ function fail(e) {
34
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
35
+ env.hasError = true;
36
+ }
37
+ var r, s = 0;
38
+ function next() {
39
+ while (r = env.stack.pop()) {
40
+ try {
41
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
42
+ if (r.dispose) {
43
+ var result = r.dispose.call(r.value);
44
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
45
+ }
46
+ else s |= 1;
47
+ }
48
+ catch (e) {
49
+ fail(e);
50
+ }
51
+ }
52
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
53
+ if (env.hasError) throw env.error;
54
+ }
55
+ return next();
56
+ };
57
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
58
+ var e = new Error(message);
59
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
60
+ });
9
61
  Object.defineProperty(exports, "__esModule", { value: true });
10
62
  exports.MobileIpcTransport = void 0;
11
63
  const core_common_1 = require("@itwin/core-common");
@@ -14,12 +66,14 @@ const MobileRpcProtocol_1 = require("./MobileRpcProtocol");
14
66
  const MobileRpcRequest_1 = require("./MobileRpcRequest");
15
67
  const IPC = "__ipc__";
16
68
  class IpcInterface extends core_common_1.RpcInterface {
69
+ static interfaceName = IPC;
70
+ static interfaceVersion = "0.0.0";
17
71
  async send() { }
18
72
  }
19
- IpcInterface.interfaceName = IPC;
20
- IpcInterface.interfaceVersion = "0.0.0";
21
73
  /** @internal */
22
74
  class MobileIpcTransport extends core_common_1.IpcWebSocketTransport {
75
+ _protocol;
76
+ _client;
23
77
  constructor(protocol) {
24
78
  super();
25
79
  this._protocol = protocol;
@@ -49,10 +103,19 @@ class MobileIpcTransport extends core_common_1.IpcWebSocketTransport {
49
103
  return true;
50
104
  }
51
105
  async sendToBackend(message) {
52
- const request = new MobileRpcRequest_1.MobileRpcRequest(this._client, "send", [message]);
53
- const encoded = await MobileRpcProtocol_1.MobileRpcProtocol.encodeRequest(request);
54
- this._protocol.sendToBackend(encoded);
55
- request.dispose();
106
+ const env_1 = { stack: [], error: void 0, hasError: false };
107
+ try {
108
+ const request = __addDisposableResource(env_1, new MobileRpcRequest_1.MobileRpcRequest(this._client, "send", [message]), false);
109
+ const encoded = await MobileRpcProtocol_1.MobileRpcProtocol.encodeRequest(request);
110
+ this._protocol.sendToBackend(encoded);
111
+ }
112
+ catch (e_1) {
113
+ env_1.error = e_1;
114
+ env_1.hasError = true;
115
+ }
116
+ finally {
117
+ __disposeResources(env_1);
118
+ }
56
119
  }
57
120
  sendToFrontend(message) {
58
121
  MobileEventLoop_1.MobileEventLoop.addTask();
@@ -1 +1 @@
1
- {"version":3,"file":"MobileI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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"]}
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;AAEtD,MAAM,GAAG,GAAG,SAAS,CAAC;AAEtB,MAAM,YAAa,SAAQ,0BAAY;IAC9B,MAAM,CAAC,aAAa,GAAG,GAAG,CAAC;IAC3B,MAAM,CAAC,gBAAgB,GAAG,OAAO,CAAC;IAClC,KAAK,CAAC,IAAI,KAAK,CAAC;;AAGzB,gBAAgB;AAChB,MAAa,kBAAmB,SAAQ,mCAAqB;IACnD,SAAS,CAAoB;IAC7B,OAAO,CAAe;IAE9B,YAAmB,QAA2B;QAC5C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC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,kCAAG,IAAI,mCAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC,QAAA,CAAC;YACtE,MAAM,OAAO,GAAG,MAAM,qCAAiB,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAC/D,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;;;;;;;;;KACvC;IAEO,cAAc,CAAC,OAA4B;QACjD,iCAAe,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,2BAAa,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAChE,iCAAe,CAAC,UAAU,EAAE,CAAC;QAE7B,MAAM,WAAW,GAA0B,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;QAC9H,MAAM,OAAO,GAAG,qCAAiB,CAAC,cAAc,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;AA1DD,gDA0DC","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 using request = new MobileRpcRequest(this._client, \"send\", [message]);\n const encoded = await MobileRpcProtocol.encodeRequest(request);\n this._protocol.sendToBackend(encoded);\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"]}
@@ -14,10 +14,11 @@ const MobileRpcProtocol_1 = require("./MobileRpcProtocol");
14
14
  const PUSH = "__push__";
15
15
  /** @internal */
16
16
  class MobilePushTransport extends core_common_1.RpcPushTransport {
17
+ _protocol;
18
+ _last = -1;
17
19
  get last() { return this._last; }
18
20
  constructor(protocol) {
19
21
  super();
20
- this._last = -1;
21
22
  this._protocol = protocol;
22
23
  }
23
24
  consume(response) {
@@ -35,9 +36,10 @@ class MobilePushTransport extends core_common_1.RpcPushTransport {
35
36
  exports.MobilePushTransport = MobilePushTransport;
36
37
  /** @internal */
37
38
  class MobilePushConnection extends core_common_1.RpcPushConnection {
39
+ _protocol;
40
+ _next = -1;
38
41
  constructor(channel, client, protocol) {
39
42
  super(channel, client);
40
- this._next = -1;
41
43
  this._protocol = protocol;
42
44
  }
43
45
  async send(messageData) {
@@ -1 +1 @@
1
- {"version":3,"file":"MobilePush.js","sourceRoot":"","sources":["../../../src/common/MobilePush.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAA+H;AAC/H,uDAAoD;AACpD,2DAAwD;AAExD,MAAM,IAAI,GAAG,UAAU,CAAC;AAExB,gBAAgB;AAChB,MAAa,mBAAoB,SAAQ,8BAAgB;IAIvD,IAAW,IAAI,KAAK,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAExC,YAAmB,QAA2B;QAC5C,KAAK,EAAE,CAAC;QALF,UAAK,GAAW,CAAC,CAAC,CAAC;QAMzB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAEM,OAAO,CAAC,QAA+B;QAC5C,IAAI,QAAQ,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC;QAE7B,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,MAAM,WAAW,GAAG,2BAAa,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC/E,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;QAC3C,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAzBD,kDAyBC;AAED,gBAAgB;AAChB,MAAa,oBAAwB,SAAQ,+BAAoB;IAI/D,YAAmB,OAA0B,EAAE,MAAe,EAAE,QAA2B;QACzF,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAHjB,UAAK,GAAW,CAAC,CAAC,CAAC;QAIzB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,WAAgB;QAChC,iCAAe,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,2BAAa,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QACpE,iCAAe,CAAC,UAAU,EAAE,CAAC;QAE7B,MAAM,WAAW,GAA0B,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9I,MAAM,OAAO,GAAG,qCAAiB,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QAC9D,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACF;AAlBD,oDAkBC","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 { RpcMarshaling, RpcPushChannel, RpcPushConnection, RpcPushTransport, RpcRequestFulfillment } from \"@itwin/core-common\";\nimport { MobileEventLoop } from \"./MobileEventLoop\";\nimport { MobileRpcProtocol } from \"./MobileRpcProtocol\";\n\nconst PUSH = \"__push__\";\n\n/** @internal */\nexport class MobilePushTransport extends RpcPushTransport {\n private _protocol: MobileRpcProtocol;\n private _last: number = -1;\n\n public get last() { return this._last; }\n\n public constructor(protocol: MobileRpcProtocol) {\n super();\n this._protocol = protocol;\n }\n\n public consume(response: RpcRequestFulfillment): boolean {\n if (response.interfaceName !== PUSH) {\n return false;\n }\n\n this._last = response.status;\n\n if (this.onMessage) {\n const messageData = RpcMarshaling.deserialize(this._protocol, response.result);\n this.onMessage(response.id, messageData);\n }\n\n return true;\n }\n}\n\n/** @internal */\nexport class MobilePushConnection<T> extends RpcPushConnection<T> {\n private _protocol: MobileRpcProtocol;\n private _next: number = -1;\n\n public constructor(channel: RpcPushChannel<T>, client: unknown, protocol: MobileRpcProtocol) {\n super(channel, client);\n this._protocol = protocol;\n }\n\n public async send(messageData: any) {\n MobileEventLoop.addTask();\n const result = RpcMarshaling.serialize(this._protocol, messageData);\n MobileEventLoop.removeTask();\n\n const fulfillment: RpcRequestFulfillment = { result, rawResult: messageData, interfaceName: PUSH, id: this.channel.id, status: ++this._next };\n const encoded = MobileRpcProtocol.encodeResponse(fulfillment);\n this._protocol.sendToFrontend(encoded);\n }\n}\n"]}
1
+ {"version":3,"file":"MobilePush.js","sourceRoot":"","sources":["../../../src/common/MobilePush.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAA+H;AAC/H,uDAAoD;AACpD,2DAAwD;AAExD,MAAM,IAAI,GAAG,UAAU,CAAC;AAExB,gBAAgB;AAChB,MAAa,mBAAoB,SAAQ,8BAAgB;IAC/C,SAAS,CAAoB;IAC7B,KAA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C,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;QAC9I,MAAM,OAAO,GAAG,qCAAiB,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QAC9D,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACF;AAlBD,oDAkBC","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 { RpcMarshaling, RpcPushChannel, RpcPushConnection, RpcPushTransport, RpcRequestFulfillment } from \"@itwin/core-common\";\nimport { MobileEventLoop } from \"./MobileEventLoop\";\nimport { MobileRpcProtocol } from \"./MobileRpcProtocol\";\n\nconst PUSH = \"__push__\";\n\n/** @internal */\nexport class MobilePushTransport extends RpcPushTransport {\n private _protocol: MobileRpcProtocol;\n private _last: number = -1;\n\n public get last() { return this._last; }\n\n public constructor(protocol: MobileRpcProtocol) {\n super();\n this._protocol = protocol;\n }\n\n public consume(response: RpcRequestFulfillment): boolean {\n if (response.interfaceName !== PUSH) {\n return false;\n }\n\n this._last = response.status;\n\n if (this.onMessage) {\n const messageData = RpcMarshaling.deserialize(this._protocol, response.result);\n this.onMessage(response.id, messageData);\n }\n\n return true;\n }\n}\n\n/** @internal */\nexport class MobilePushConnection<T> extends RpcPushConnection<T> {\n private _protocol: MobileRpcProtocol;\n private _next: number = -1;\n\n public constructor(channel: RpcPushChannel<T>, client: unknown, protocol: MobileRpcProtocol) {\n super(channel, client);\n this._protocol = protocol;\n }\n\n public async send(messageData: any) {\n MobileEventLoop.addTask();\n const result = RpcMarshaling.serialize(this._protocol, messageData);\n MobileEventLoop.removeTask();\n\n const fulfillment: RpcRequestFulfillment = { result, rawResult: messageData, interfaceName: PUSH, id: this.channel.id, status: ++this._next };\n const encoded = MobileRpcProtocol.encodeResponse(fulfillment);\n this._protocol.sendToFrontend(encoded);\n }\n}\n"]}
@@ -21,6 +21,12 @@ var RpcMobilePlatform;
21
21
  * @internal
22
22
  */
23
23
  class MobileRpcConfiguration extends core_common_1.RpcConfiguration {
24
+ /** @internal */
25
+ static setup = {
26
+ obtainPort: () => 0,
27
+ checkPlatform: () => typeof (process) !== "undefined" && process.platform === "ios",
28
+ };
29
+ static _args;
24
30
  static getArgs() {
25
31
  if (typeof window !== "object" || typeof window.location !== "object" || typeof window.location.hash !== "string") {
26
32
  return Object.freeze({});
@@ -65,11 +71,6 @@ class MobileRpcConfiguration extends core_common_1.RpcConfiguration {
65
71
  static get platform() { return MobileRpcConfiguration.getMobilePlatform(); }
66
72
  }
67
73
  exports.MobileRpcConfiguration = MobileRpcConfiguration;
68
- /** @internal */
69
- MobileRpcConfiguration.setup = {
70
- obtainPort: () => 0,
71
- checkPlatform: () => typeof (process) !== "undefined" && process.platform === "ios",
72
- };
73
74
  /** Coordinates usage of RPC interfaces for an Mobile-based application.
74
75
  * @internal
75
76
  */
@@ -85,11 +86,8 @@ class MobileRpcManager {
85
86
  }
86
87
  static performInitialization(interfaces, endPoint) {
87
88
  const config = class extends MobileRpcConfiguration {
88
- constructor() {
89
- super(...arguments);
90
- this.interfaces = () => interfaces;
91
- this.protocol = new MobileRpcProtocol_1.MobileRpcProtocol(this, endPoint);
92
- }
89
+ interfaces = () => interfaces;
90
+ protocol = new MobileRpcProtocol_1.MobileRpcProtocol(this, endPoint);
93
91
  };
94
92
  for (const def of interfaces) {
95
93
  core_common_1.RpcConfiguration.assign(def, () => config);
@@ -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,+DAA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CAAC;IACL,CAAC;IAEO,MAAM,CAAC,qBAAqB,CAAC,UAAoC,EAAE,QAAqB;QAC9F,MAAM,MAAM,GAAG,KAAM,SAAQ,sBAAsB;YAApC;;gBACN,eAAU,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC;gBAC9B,aAAQ,GAAsB,IAAI,qCAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC7E,CAAC;SAAA,CAAC;QAEF,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;YAC7B,8BAAgB,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,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"]}
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;IACT,MAAM,CAAC,KAAK,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;IAGM,MAAM,CAAC,KAAK,CAAM;IAClB,MAAM,CAAC,OAAO;QACpB,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAClH,OAAO,MA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AAQ,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"]}
@@ -19,6 +19,19 @@ const MobileRpcRequest_1 = require("./MobileRpcRequest");
19
19
  * @internal
20
20
  */
21
21
  class MobileRpcProtocol extends core_common_1.RpcProtocol {
22
+ socket = undefined;
23
+ requests = new Map();
24
+ _pending = [];
25
+ _capacity = Number.MAX_SAFE_INTEGER;
26
+ _sendInterval = undefined;
27
+ _sendIntervalHandler = () => this.trySend();
28
+ requestType = MobileRpcRequest_1.MobileRpcRequest;
29
+ _partialRequest = undefined;
30
+ _partialFulfillment = undefined;
31
+ _partialData = [];
32
+ _port = 0;
33
+ _transport;
34
+ _ipc;
22
35
  static obtainInterop() { throw new core_common_1.IModelError(core_bentley_1.BentleyStatus.ERROR, "Not implemented."); }
23
36
  static async encodeRequest(request) {
24
37
  const serialized = await request.protocol.serialize(request);
@@ -37,17 +50,6 @@ class MobileRpcProtocol extends core_common_1.RpcProtocol {
37
50
  }
38
51
  constructor(configuration, endPoint) {
39
52
  super(configuration);
40
- this.socket = undefined;
41
- this.requests = new Map();
42
- this._pending = [];
43
- this._capacity = Number.MAX_SAFE_INTEGER;
44
- this._sendInterval = undefined;
45
- this._sendIntervalHandler = () => this.trySend();
46
- this.requestType = MobileRpcRequest_1.MobileRpcRequest;
47
- this._partialRequest = undefined;
48
- this._partialFulfillment = undefined;
49
- this._partialData = [];
50
- this._port = 0;
51
53
  if (endPoint === core_common_1.RpcEndpoint.Frontend) {
52
54
  this.initializeFrontend();
53
55
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MobileRpcProtocol.js","sourceRoot":"","sources":["../../../src/common/MobileRpcProtocol.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAoD;AACpD,oDAG4B;AAC5B,uDAAoD;AACpD,2CAAiD;AACjD,6CAAyE;AACzE,yDAA4D;AAC5D,yDAAsD;AAgBtD;;GAEG;AACH,MAAa,iBAAkB,SAAQ,yBAAW;IAczC,MAAM,CAAC,aAAa,KAAuB,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAE5G,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC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AC,4BAAa,CAAC,KAAK,EAAE,oCAAoC,CAAC,CAAC;QACnF,CAAC;QAED,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QAEjC,IAAI,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;YACtC,OAAO;QACT,CAAC;QAED,iCAAe,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAChD,iCAAe,CAAC,UAAU,EAAE,CAAC;QAE7B,MAAM,QAAQ,GAAG,iBAAiB,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC5C,CAAC;IAEM,aAAa,CAAC,OAAwB;QAC3C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAEM,cAAc,CAAC,OAAwB,EAAE,UAAmB;QACjE,MAAM,aAAa,GAAG,iBAAiB,CAAC,aAAa,EAAE,CAAC;QAExD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAChC,aAAa,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,IAAI,aAAa,CAAC,YAAY,CAAC,CAAC;YAC5E,CAAC;iBAAM,CAAC;gBACN,aAAa,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,IAAI,aAAa,CAAC,YAAY,CAAC,CAAC;YAC5E,CAAC;QACH,CAAC;IACH,CAAC;CACF;AArTD,8CAqTC","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 { BentleyStatus } from \"@itwin/core-bentley\";\nimport {\n IModelError, IpcWebSocket, RpcEndpoint, RpcProtocol, RpcPushChannel, RpcPushConnection, RpcRequest, RpcRequestFulfillment, RpcSerializedValue,\n SerializedRpcRequest,\n} from \"@itwin/core-common\";\nimport { MobileEventLoop } from \"./MobileEventLoop\";\nimport { MobileIpcTransport } from \"./MobileIpc\";\nimport { MobilePushConnection, MobilePushTransport } from \"./MobilePush\";\nimport { MobileRpcConfiguration } from \"./MobileRpcManager\";\nimport { MobileRpcRequest } from \"./MobileRpcRequest\";\n\n/* eslint-disable @typescript-eslint/no-deprecated */\n\n/** @internal */\nexport type MobileRpcChunks = Array<string | Uint8Array>;\n\n/** @internal */\nexport interface MobileRpcGateway {\n handler: (payload: ArrayBuffer | string, connectionId: number) => void;\n sendString: (message: string, connectionId: number) => void;\n sendBinary: (message: Uint8Array, connectionId: number) => void;\n port: number;\n connectionId: number;\n}\n\n/** RPC interface protocol for an Mobile-based application.\n * @internal\n */\nexport class MobileRpcProtocol extends RpcProtocol {\n public socket: WebSocket = (undefined as any);\n public requests: Map<string, MobileRpcRequest> = new Map();\n private _pending: MobileRpcChunks[] = [];\n private _capacity: number = Number.MAX_SAFE_INTEGER;\n private _sendInterval: number | undefined = undefined;\n private _sendIntervalHandler = () => this.trySend();\n public readonly requestType = MobileRpcRequest;\n private _partialRequest: SerializedRpcRequest | undefined = undefined;\n private _partialFulfillment: RpcRequestFulfillment | undefined = undefined;\n private _partialData: Uint8Array[] = [];\n private _port: number = 0;\n private _transport?: MobilePushTransport;\n private _ipc: MobileIpcTransport;\n public static obtainInterop(): MobileRpcGateway { throw new IModelError(BentleyStatus.ERROR, \"Not implemented.\"); }\n\n public static async encodeRequest(request: MobileRpcRequest): Promise<MobileRpcChunks> {\n const serialized = await request.protocol.serialize(request);\n const data = serialized.parameters.data;\n serialized.parameters.data = data.map((v) => v.byteLength) as any[];\n return [JSON.stringify(serialized), ...data];\n }\n\n public static encodeResponse(fulfillment: RpcRequestFulfillment): MobileRpcChunks {\n const data = fulfillment.result.data;\n fulfillment.result.data = data.map((v) => v.byteLength) as any[];\n const raw = fulfillment.rawResult;\n fulfillment.rawResult = undefined;\n const encoded = [JSON.stringify(fulfillment), ...data];\n fulfillment.rawResult = raw;\n return encoded;\n }\n\n constructor(configuration: MobileRpcConfiguration, endPoint: RpcEndpoint) {\n super(configuration);\n\n if (endPoint === RpcEndpoint.Frontend) {\n this.initializeFrontend();\n } else if (endPoint === RpcEndpoint.Backend) {\n this.initializeBackend();\n }\n\n this._ipc = new MobileIpcTransport(this);\n IpcWebSocket.transport = this._ipc;\n }\n\n private initializeFrontend() {\n if (typeof (WebSocket) === \"undefined\") {\n throw new IModelError(BentleyStatus.ERROR, \"MobileRpcProtocol on frontend require websocket to work\");\n }\n if (!MobileRpcConfiguration.args.port) {\n throw new IModelError(BentleyStatus.ERROR, \"MobileRpcProtocol require 'port' parameter\");\n }\n\n this._port = MobileRpcConfiguration.args.port;\n this.connect(this._port, false);\n\n (window as any)._imodeljs_rpc_reconnect = (port: number) => {\n this.socket.close();\n window.location.hash = window.location.hash.replace(`port=${this._port}`, `port=${port}`);\n this._port = port;\n this.connect(port, true);\n };\n\n const transport = new MobilePushTransport(this);\n this._transport = transport;\n RpcPushChannel.setup(transport);\n }\n\n private connect(port: number, reset: boolean) {\n const socket = new WebSocket(`ws://localhost:${port}`);\n socket.binaryType = \"arraybuffer\";\n this.connectMessageHandler(socket);\n this.connectOpenHandler(socket, reset);\n this.connectErrorHandler(socket);\n this.socket = socket;\n }\n\n private connectMessageHandler(socket: WebSocket) {\n socket.addEventListener(\"message\", async (event) => {\n if (this.socket !== socket) {\n return;\n }\n\n this.handleMessageFromBackend(event.data);\n });\n }\n\n private connectOpenHandler(socket: WebSocket, reset: boolean) {\n socket.addEventListener(\"open\", (_event) => {\n if (this.socket !== socket) {\n return;\n }\n\n if (reset) {\n this.reset();\n\n const requests = new Map(RpcRequest.activeRequests);\n requests.forEach((req) => {\n req.cancel();\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n req.submit();\n });\n }\n\n this.scheduleSend();\n });\n }\n\n private connectErrorHandler(socket: WebSocket) {\n socket.addEventListener(\"error\", (_event) => {\n if (this.socket !== socket) {\n return;\n }\n\n throw new IModelError(BentleyStatus.ERROR, \"Socket error.\");\n });\n }\n\n private reset() {\n this.requests.clear();\n this._capacity = Number.MAX_SAFE_INTEGER;\n\n if (typeof (this._sendInterval) !== \"undefined\") {\n window.clearInterval(this._sendInterval);\n this._sendInterval = undefined;\n }\n\n this._partialRequest = undefined;\n this._partialFulfillment = undefined;\n this._partialData.length = 0;\n }\n\n private scheduleSend() {\n if (!this._pending.length) {\n return;\n }\n\n this.trySend();\n\n if (this._pending.length && typeof (this._sendInterval) === \"undefined\") {\n this._sendInterval = window.setInterval(this._sendIntervalHandler, 0);\n }\n }\n\n private trySend() {\n if (this.socket.readyState !== WebSocket.OPEN) {\n return;\n }\n\n while (this._capacity !== 0 && this._pending.length) {\n --this._capacity;\n const next = this._pending.shift()!;\n for (const chunk of next) {\n this.socket.send(chunk);\n }\n }\n\n if (!this._pending.length && typeof (this._sendInterval) !== \"undefined\") {\n window.clearInterval(this._sendInterval);\n this._sendInterval = undefined;\n }\n }\n\n private handleMessageFromBackend(data: string | ArrayBuffer) {\n if (typeof (data) === \"string\") {\n this.handleStringFromBackend(data);\n } else {\n this.handleBinaryFromBackend(data);\n }\n }\n\n private handleStringFromBackend(data: string) {\n if (this._partialFulfillment) {\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (already receiving response).\");\n }\n\n const response = JSON.parse(data) as RpcRequestFulfillment;\n this._partialFulfillment = response;\n\n if (!response.result.data.length) {\n this.notifyResponse();\n }\n }\n\n private handleBinaryFromBackend(data: ArrayBuffer) {\n const fulfillment = this._partialFulfillment;\n if (!fulfillment) {\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (no response received).\");\n }\n\n this._partialData.push(new Uint8Array(data));\n if (this._partialData.length === fulfillment.result.data.length) {\n this.notifyResponse();\n }\n }\n\n private notifyResponse() {\n const response = this._partialFulfillment;\n if (!response) {\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (no response exists).\");\n }\n\n ++this._capacity;\n this.consumePartialData(response.result);\n this._partialFulfillment = undefined;\n\n if (this._transport && this._transport.consume(response)) {\n return;\n }\n\n if (this._ipc.consumeResponse(response)) {\n return;\n }\n\n const request = this.requests.get(response.id) as MobileRpcRequest;\n this.requests.delete(response.id);\n request.notifyResponse(response);\n }\n\n private consumePartialData(value: RpcSerializedValue) {\n for (let i = 0, l = value.data.length; i !== l; ++i) {\n value.data[i] = this._partialData[i];\n }\n\n this._partialData.length = 0;\n }\n\n private initializeBackend() {\n const mobilegateway = MobileRpcProtocol.obtainInterop();\n if (mobilegateway === undefined || mobilegateway == null) {\n throw new IModelError(BentleyStatus.ERROR, \"MobileRpcProtocol on backend require native bridge to be setup\");\n }\n\n mobilegateway.handler = (payload, connectionId) => this.handleMessageFromFrontend(payload, connectionId);\n RpcPushConnection.for = (channel, client) => new MobilePushConnection(channel, client, this);\n RpcPushChannel.enabled = true;\n }\n\n private handleMessageFromFrontend(data: string | ArrayBuffer, connectionId: number) {\n if (typeof (data) === \"string\") {\n this.handleStringFromFrontend(data, connectionId);\n } else {\n this.handleBinaryFromFrontend(data, connectionId);\n }\n }\n\n private handleStringFromFrontend(data: string, connection: number) {\n if (this._partialRequest) {\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (already receiving request).\");\n }\n\n const request = JSON.parse(data) as SerializedRpcRequest;\n this._partialRequest = request;\n\n if (!request.parameters.data.length) {\n this.notifyRequest(connection); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n }\n\n private handleBinaryFromFrontend(data: ArrayBuffer, connection: number) {\n const request = this._partialRequest;\n if (!request) {\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (no request received).\");\n }\n\n this._partialData.push(new Uint8Array(data));\n if (this._partialData.length === request.parameters.data.length) {\n this.notifyRequest(connection); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n }\n\n private async notifyRequest(connection: number) {\n const request = this._partialRequest;\n if (!request) {\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (no request exists).\");\n }\n\n this.consumePartialData(request.parameters);\n this._partialRequest = undefined;\n\n if (this._ipc.consumeRequest(request)) {\n return;\n }\n\n MobileEventLoop.addTask();\n const fulfillment = await this.fulfill(request);\n MobileEventLoop.removeTask();\n\n const response = MobileRpcProtocol.encodeResponse(fulfillment);\n this.sendToFrontend(response, connection);\n }\n\n public sendToBackend(message: MobileRpcChunks): void {\n this._pending.push(message);\n this.scheduleSend();\n }\n\n public sendToFrontend(message: MobileRpcChunks, connection?: number): void {\n const mobilegateway = MobileRpcProtocol.obtainInterop();\n\n for (const chunk of message) {\n if (typeof (chunk) === \"string\") {\n mobilegateway.sendString(chunk, connection || mobilegateway.connectionId);\n } else {\n mobilegateway.sendBinary(chunk, connection || mobilegateway.connectionId);\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"MobileRpcProtocol.js","sourceRoot":"","sources":["../../../src/common/MobileRpcProtocol.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAoD;AACpD,oDAG4B;AAC5B,uDAAoD;AACpD,2CAAiD;AACjD,6CAAyE;AACzE,yDAA4D;AAC5D,yDAAsD;AAgBtD;;GAEG;AACH,MAAa,iBAAkB,SAAQ,yBAAW;IACzC,MAAM,GAAe,SAAiB,CAAC;IACvC,QAAQ,GAAkC,IAAI,GAAG,EAAE,CAAC;IACnD,QAAQ,GAAsB,EAAE,CAAC;IACjC,SAAS,GAAW,MAAM,CAAC,gBAAgB,CAAC;IAC5C,aAAa,GAAuB,SAAS,CAAC;IAC9C,oBAAoB,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IACpC,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AAC,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QAEjC,IAAI,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;YACtC,OAAO;QACT,CAAC;QAED,iCAAe,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAChD,iCAAe,CAAC,UAAU,EAAE,CAAC;QAE7B,MAAM,QAAQ,GAAG,iBAAiB,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QAC/D,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC5C,CAAC;IAEM,aAAa,CAAC,OAAwB;QAC3C,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAEM,cAAc,CAAC,OAAwB,EAAE,UAAmB;QACjE,MAAM,aAAa,GAAG,iBAAiB,CAAC,aAAa,EAAE,CAAC;QAExD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;YAC5B,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAChC,aAAa,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,IAAI,aAAa,CAAC,YAAY,CAAC,CAAC;YAC5E,CAAC;iBAAM,CAAC;gBACN,aAAa,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,IAAI,aAAa,CAAC,YAAY,CAAC,CAAC;YAC5E,CAAC;QACH,CAAC;IACH,CAAC;CACF;AArTD,8CAqTC","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 { BentleyStatus } from \"@itwin/core-bentley\";\nimport {\n IModelError, IpcWebSocket, RpcEndpoint, RpcProtocol, RpcPushChannel, RpcPushConnection, RpcRequest, RpcRequestFulfillment, RpcSerializedValue,\n SerializedRpcRequest,\n} from \"@itwin/core-common\";\nimport { MobileEventLoop } from \"./MobileEventLoop\";\nimport { MobileIpcTransport } from \"./MobileIpc\";\nimport { MobilePushConnection, MobilePushTransport } from \"./MobilePush\";\nimport { MobileRpcConfiguration } from \"./MobileRpcManager\";\nimport { MobileRpcRequest } from \"./MobileRpcRequest\";\n\n/* eslint-disable @typescript-eslint/no-deprecated */\n\n/** @internal */\nexport type MobileRpcChunks = Array<string | Uint8Array>;\n\n/** @internal */\nexport interface MobileRpcGateway {\n handler: (payload: ArrayBuffer | string, connectionId: number) => void;\n sendString: (message: string, connectionId: number) => void;\n sendBinary: (message: Uint8Array, connectionId: number) => void;\n port: number;\n connectionId: number;\n}\n\n/** RPC interface protocol for an Mobile-based application.\n * @internal\n */\nexport class MobileRpcProtocol extends RpcProtocol {\n public socket: WebSocket = (undefined as any);\n public requests: Map<string, MobileRpcRequest> = new Map();\n private _pending: MobileRpcChunks[] = [];\n private _capacity: number = Number.MAX_SAFE_INTEGER;\n private _sendInterval: number | undefined = undefined;\n private _sendIntervalHandler = () => this.trySend();\n public readonly requestType = MobileRpcRequest;\n private _partialRequest: SerializedRpcRequest | undefined = undefined;\n private _partialFulfillment: RpcRequestFulfillment | undefined = undefined;\n private _partialData: Uint8Array[] = [];\n private _port: number = 0;\n private _transport?: MobilePushTransport;\n private _ipc: MobileIpcTransport;\n public static obtainInterop(): MobileRpcGateway { throw new IModelError(BentleyStatus.ERROR, \"Not implemented.\"); }\n\n public static async encodeRequest(request: MobileRpcRequest): Promise<MobileRpcChunks> {\n const serialized = await request.protocol.serialize(request);\n const data = serialized.parameters.data;\n serialized.parameters.data = data.map((v) => v.byteLength) as any[];\n return [JSON.stringify(serialized), ...data];\n }\n\n public static encodeResponse(fulfillment: RpcRequestFulfillment): MobileRpcChunks {\n const data = fulfillment.result.data;\n fulfillment.result.data = data.map((v) => v.byteLength) as any[];\n const raw = fulfillment.rawResult;\n fulfillment.rawResult = undefined;\n const encoded = [JSON.stringify(fulfillment), ...data];\n fulfillment.rawResult = raw;\n return encoded;\n }\n\n constructor(configuration: MobileRpcConfiguration, endPoint: RpcEndpoint) {\n super(configuration);\n\n if (endPoint === RpcEndpoint.Frontend) {\n this.initializeFrontend();\n } else if (endPoint === RpcEndpoint.Backend) {\n this.initializeBackend();\n }\n\n this._ipc = new MobileIpcTransport(this);\n IpcWebSocket.transport = this._ipc;\n }\n\n private initializeFrontend() {\n if (typeof (WebSocket) === \"undefined\") {\n throw new IModelError(BentleyStatus.ERROR, \"MobileRpcProtocol on frontend require websocket to work\");\n }\n if (!MobileRpcConfiguration.args.port) {\n throw new IModelError(BentleyStatus.ERROR, \"MobileRpcProtocol require 'port' parameter\");\n }\n\n this._port = MobileRpcConfiguration.args.port;\n this.connect(this._port, false);\n\n (window as any)._imodeljs_rpc_reconnect = (port: number) => {\n this.socket.close();\n window.location.hash = window.location.hash.replace(`port=${this._port}`, `port=${port}`);\n this._port = port;\n this.connect(port, true);\n };\n\n const transport = new MobilePushTransport(this);\n this._transport = transport;\n RpcPushChannel.setup(transport);\n }\n\n private connect(port: number, reset: boolean) {\n const socket = new WebSocket(`ws://localhost:${port}`);\n socket.binaryType = \"arraybuffer\";\n this.connectMessageHandler(socket);\n this.connectOpenHandler(socket, reset);\n this.connectErrorHandler(socket);\n this.socket = socket;\n }\n\n private connectMessageHandler(socket: WebSocket) {\n socket.addEventListener(\"message\", async (event) => {\n if (this.socket !== socket) {\n return;\n }\n\n this.handleMessageFromBackend(event.data);\n });\n }\n\n private connectOpenHandler(socket: WebSocket, reset: boolean) {\n socket.addEventListener(\"open\", (_event) => {\n if (this.socket !== socket) {\n return;\n }\n\n if (reset) {\n this.reset();\n\n const requests = new Map(RpcRequest.activeRequests);\n requests.forEach((req) => {\n req.cancel();\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n req.submit();\n });\n }\n\n this.scheduleSend();\n });\n }\n\n private connectErrorHandler(socket: WebSocket) {\n socket.addEventListener(\"error\", (_event) => {\n if (this.socket !== socket) {\n return;\n }\n\n throw new IModelError(BentleyStatus.ERROR, \"Socket error.\");\n });\n }\n\n private reset() {\n this.requests.clear();\n this._capacity = Number.MAX_SAFE_INTEGER;\n\n if (typeof (this._sendInterval) !== \"undefined\") {\n window.clearInterval(this._sendInterval);\n this._sendInterval = undefined;\n }\n\n this._partialRequest = undefined;\n this._partialFulfillment = undefined;\n this._partialData.length = 0;\n }\n\n private scheduleSend() {\n if (!this._pending.length) {\n return;\n }\n\n this.trySend();\n\n if (this._pending.length && typeof (this._sendInterval) === \"undefined\") {\n this._sendInterval = window.setInterval(this._sendIntervalHandler, 0);\n }\n }\n\n private trySend() {\n if (this.socket.readyState !== WebSocket.OPEN) {\n return;\n }\n\n while (this._capacity !== 0 && this._pending.length) {\n --this._capacity;\n const next = this._pending.shift()!;\n for (const chunk of next) {\n this.socket.send(chunk);\n }\n }\n\n if (!this._pending.length && typeof (this._sendInterval) !== \"undefined\") {\n window.clearInterval(this._sendInterval);\n this._sendInterval = undefined;\n }\n }\n\n private handleMessageFromBackend(data: string | ArrayBuffer) {\n if (typeof (data) === \"string\") {\n this.handleStringFromBackend(data);\n } else {\n this.handleBinaryFromBackend(data);\n }\n }\n\n private handleStringFromBackend(data: string) {\n if (this._partialFulfillment) {\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (already receiving response).\");\n }\n\n const response = JSON.parse(data) as RpcRequestFulfillment;\n this._partialFulfillment = response;\n\n if (!response.result.data.length) {\n this.notifyResponse();\n }\n }\n\n private handleBinaryFromBackend(data: ArrayBuffer) {\n const fulfillment = this._partialFulfillment;\n if (!fulfillment) {\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (no response received).\");\n }\n\n this._partialData.push(new Uint8Array(data));\n if (this._partialData.length === fulfillment.result.data.length) {\n this.notifyResponse();\n }\n }\n\n private notifyResponse() {\n const response = this._partialFulfillment;\n if (!response) {\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (no response exists).\");\n }\n\n ++this._capacity;\n this.consumePartialData(response.result);\n this._partialFulfillment = undefined;\n\n if (this._transport && this._transport.consume(response)) {\n return;\n }\n\n if (this._ipc.consumeResponse(response)) {\n return;\n }\n\n const request = this.requests.get(response.id) as MobileRpcRequest;\n this.requests.delete(response.id);\n request.notifyResponse(response);\n }\n\n private consumePartialData(value: RpcSerializedValue) {\n for (let i = 0, l = value.data.length; i !== l; ++i) {\n value.data[i] = this._partialData[i];\n }\n\n this._partialData.length = 0;\n }\n\n private initializeBackend() {\n const mobilegateway = MobileRpcProtocol.obtainInterop();\n if (mobilegateway === undefined || mobilegateway == null) {\n throw new IModelError(BentleyStatus.ERROR, \"MobileRpcProtocol on backend require native bridge to be setup\");\n }\n\n mobilegateway.handler = (payload, connectionId) => this.handleMessageFromFrontend(payload, connectionId);\n RpcPushConnection.for = (channel, client) => new MobilePushConnection(channel, client, this);\n RpcPushChannel.enabled = true;\n }\n\n private handleMessageFromFrontend(data: string | ArrayBuffer, connectionId: number) {\n if (typeof (data) === \"string\") {\n this.handleStringFromFrontend(data, connectionId);\n } else {\n this.handleBinaryFromFrontend(data, connectionId);\n }\n }\n\n private handleStringFromFrontend(data: string, connection: number) {\n if (this._partialRequest) {\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (already receiving request).\");\n }\n\n const request = JSON.parse(data) as SerializedRpcRequest;\n this._partialRequest = request;\n\n if (!request.parameters.data.length) {\n this.notifyRequest(connection); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n }\n\n private handleBinaryFromFrontend(data: ArrayBuffer, connection: number) {\n const request = this._partialRequest;\n if (!request) {\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (no request received).\");\n }\n\n this._partialData.push(new Uint8Array(data));\n if (this._partialData.length === request.parameters.data.length) {\n this.notifyRequest(connection); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n }\n\n private async notifyRequest(connection: number) {\n const request = this._partialRequest;\n if (!request) {\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (no request exists).\");\n }\n\n this.consumePartialData(request.parameters);\n this._partialRequest = undefined;\n\n if (this._ipc.consumeRequest(request)) {\n return;\n }\n\n MobileEventLoop.addTask();\n const fulfillment = await this.fulfill(request);\n MobileEventLoop.removeTask();\n\n const response = MobileRpcProtocol.encodeResponse(fulfillment);\n this.sendToFrontend(response, connection);\n }\n\n public sendToBackend(message: MobileRpcChunks): void {\n this._pending.push(message);\n this.scheduleSend();\n }\n\n public sendToFrontend(message: MobileRpcChunks, connection?: number): void {\n const mobilegateway = MobileRpcProtocol.obtainInterop();\n\n for (const chunk of message) {\n if (typeof (chunk) === \"string\") {\n mobilegateway.sendString(chunk, connection || mobilegateway.connectionId);\n } else {\n mobilegateway.sendBinary(chunk, connection || mobilegateway.connectionId);\n }\n }\n }\n}\n"]}
@@ -12,13 +12,10 @@ const core_common_1 = require("@itwin/core-common");
12
12
  const MobileRpcProtocol_1 = require("./MobileRpcProtocol");
13
13
  /** @internal */
14
14
  class MobileRpcRequest extends core_common_1.RpcRequest {
15
- constructor() {
16
- super(...arguments);
17
- this._res = () => undefined;
18
- this._fulfillment = undefined;
19
- /** Convenience access to the protocol of this request. */
20
- this.protocol = this.client.configuration.protocol;
21
- }
15
+ _res = () => undefined;
16
+ _fulfillment = undefined;
17
+ /** Convenience access to the protocol of this request. */
18
+ protocol = this.client.configuration.protocol;
22
19
  /** Sends the request. */
23
20
  async send() {
24
21
  this.protocol.requests.set(this.id, this);
@@ -1 +1 @@
1
- {"version":3,"file":"MobileRpcRequest.js","sourceRoot":"","sources":["../../../src/common/MobileRpcRequest.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAA2F;AAC3F,2DAAwD;AAExD,gBAAgB;AAChB,MAAa,gBAAiB,SAAQ,wBAAU;IAAhD;;QACU,SAAI,GAA4B,GAAG,EAAE,CAAC,SAAS,CAAC;QAChD,iBAAY,GAAsC,SAAS,CAAC;QAEpE,0DAA0D;QACjC,aAAQ,GAAsB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAe,CAAC;IAgCnG,CAAC;IA9BC,yBAAyB;IACf,KAAK,CAAC,IAAI;QAClB,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,MAAM,qCAAiB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC1D,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,EAAE;YACrC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,yBAAyB;IACf,KAAK,CAAC,IAAI;QAClB,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvD,CAAC;QAED,OAAO,WAAW,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,kCAAkC;IACxB,SAAS,CAAC,KAAa,EAAE,MAAc;QAC/C,oBAAoB;IACtB,CAAC;IAED,gBAAgB;IACT,cAAc,CAAC,WAAkC;QACtD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;CACF;AArCD,4CAqCC","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 { RpcRequest, RpcRequestFulfillment, RpcSerializedValue } from \"@itwin/core-common\";\nimport { MobileRpcProtocol } from \"./MobileRpcProtocol\";\n\n/** @internal */\nexport class MobileRpcRequest extends RpcRequest {\n private _res: (value: number) => void = () => undefined;\n private _fulfillment: RpcRequestFulfillment | undefined = undefined;\n\n /** Convenience access to the protocol of this request. */\n public override readonly protocol: MobileRpcProtocol = this.client.configuration.protocol as any;\n\n /** Sends the request. */\n protected async send(): Promise<number> {\n this.protocol.requests.set(this.id, this);\n const parts = await MobileRpcProtocol.encodeRequest(this);\n this.protocol.sendToBackend(parts);\n return new Promise<number>((resolve) => {\n this._res = resolve;\n });\n }\n\n /** Loads the request. */\n protected async load(): Promise<RpcSerializedValue> {\n const fulfillment = this._fulfillment;\n if (!fulfillment) {\n throw new Error(\"No request fulfillment available.\");\n }\n\n return fulfillment.result;\n }\n\n /** Sets request header values. */\n protected setHeader(_name: string, _value: string): void {\n // No implementation\n }\n\n /** @internal */\n public notifyResponse(fulfillment: RpcRequestFulfillment) {\n this._fulfillment = fulfillment;\n this._res(fulfillment.status);\n }\n}\n"]}
1
+ {"version":3,"file":"MobileRpcRequest.js","sourceRoot":"","sources":["../../../src/common/MobileRpcRequest.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAA2F;AAC3F,2DAAwD;AAExD,gBAAgB;AAChB,MAAa,gBAAiB,SAAQ,wBAAU;IACtC,IAAI,GAA4B,GAAG,EAAE,CAAC,SAAS,CAAC;IAChD,YAAY,GAAsC,SAAS,CAAC;IAEpE,0DAA0D;IACjC,QAAQ,GAAsB,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,QAAe,CAAC;IAEjG,yBAAyB;IACf,KAAK,CAAC,IAAI;QAClB,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,MAAM,qCAAiB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC1D,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACnC,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,EAAE;YACrC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACtB,CAAC,CAAC,CAAC;IACL,CAAC;IAED,yBAAyB;IACf,KAAK,CAAC,IAAI;QAClB,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvD,CAAC;QAED,OAAO,WAAW,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,kCAAkC;IACxB,SAAS,CAAC,KAAa,EAAE,MAAc;QAC/C,oBAAoB;IACtB,CAAC;IAED,gBAAgB;IACT,cAAc,CAAC,WAAkC;QACtD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;CACF;AArCD,4CAqCC","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 { RpcRequest, RpcRequestFulfillment, RpcSerializedValue } from \"@itwin/core-common\";\nimport { MobileRpcProtocol } from \"./MobileRpcProtocol\";\n\n/** @internal */\nexport class MobileRpcRequest extends RpcRequest {\n private _res: (value: number) => void = () => undefined;\n private _fulfillment: RpcRequestFulfillment | undefined = undefined;\n\n /** Convenience access to the protocol of this request. */\n public override readonly protocol: MobileRpcProtocol = this.client.configuration.protocol as any;\n\n /** Sends the request. */\n protected async send(): Promise<number> {\n this.protocol.requests.set(this.id, this);\n const parts = await MobileRpcProtocol.encodeRequest(this);\n this.protocol.sendToBackend(parts);\n return new Promise<number>((resolve) => {\n this._res = resolve;\n });\n }\n\n /** Loads the request. */\n protected async load(): Promise<RpcSerializedValue> {\n const fulfillment = this._fulfillment;\n if (!fulfillment) {\n throw new Error(\"No request fulfillment available.\");\n }\n\n return fulfillment.result;\n }\n\n /** Sets request header values. */\n protected setHeader(_name: string, _value: string): void {\n // No implementation\n }\n\n /** @internal */\n public notifyResponse(fulfillment: RpcRequestFulfillment) {\n this._fulfillment = fulfillment;\n this._res(fulfillment.status);\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 onMemoryWarning = new core_bentley_1.BeEvent();
33
+ static onOrientationChanged = new core_bentley_1.BeEvent();
34
+ static onEnterForeground = new core_bentley_1.BeEvent();
35
+ static onEnterBackground = new core_bentley_1.BeEvent();
36
+ static onWillTerminate = new core_bentley_1.BeEvent();
37
+ static 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 _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;IAOb,MAAM,CAAC,KAAK,CAAC,WAAW,CAA+C,UAAa,EAAE,GAAG,IAAuC;QACrI,OAAO,sBAAM,CAAC,+BAAe,CAAC,CAAC,mCAAgB,CAAC,gBAAgB,EAAE,UAAU,EAAE,GAAG,IAAI,CAA6C,CAAC;IACrI,CAAC;IAGM,MAAM,KAAK,OAAO,KAAK,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACrD,YAAY;IACL,MAAM,CA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AK,CAAC;AA6BlC;;;;EAIE;AACF,SAAS,0BAA0B;IAChC,MAAc,CAAC,uBAAuB,GAAG,CAAC,GAAyB,EAAE,EAAE;QACtE,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtB,SAAS,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAC;QAC3C,CAAC;aAAM,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,SAAS,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAC;QAC3C,CAAC;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 { _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"]}
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;IACb,MAAM,CAAC,eAAe,GAAG,IAAI,sBAAO,EAAc,CAAC;IACnD,MAAM,CAAC,oBAAoB,GAAG,IAAI,sBAAO,EAAc,CAAC;IACxD,MAAM,CAAC,iBAAiB,GAAG,IAAI,sBAAO,EAAc,CAAC;IACrD,MAA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;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;AAED;;;;EAIE;AACF,SAAS,0BAA0B;IAChC,MAAc,CAAC,uBAAuB,GAAG,CAAC,GAAyB,EAAE,EAAE;QACtE,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtB,SAAS,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAC;QAC3C,CAAC;aAAM,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,SAAS,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAC;QAC3C,CAAC;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 { _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"]}
@@ -13,11 +13,10 @@ const MobileApp_1 = require("./MobileApp");
13
13
  * @internal
14
14
  */
15
15
  class MobileAuthorizationFrontend {
16
- constructor() {
17
- this._accessToken = "";
18
- this._expiryBuffer = 60 * 10; // ten minutes
19
- this._fetchingToken = false;
20
- }
16
+ _accessToken = "";
17
+ _expirationDate;
18
+ _expiryBuffer = 60 * 10; // ten minutes
19
+ _fetchingToken = false;
21
20
  get _hasExpired() {
22
21
  return this._expirationDate !== undefined && this._expirationDate.getTime() - Date.now() <= this._expiryBuffer * 1000;
23
22
  }
@@ -1 +1 @@
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;IAkCjC,CAAC;IAhCC,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,CAAC;YACxB,0FAA0F;YAC1F,4FAA4F;YAC5F,OAAO,EAAE,CAAC,CAAC,oDAAoD;QACjE,CAAC;QAED,IAAI,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC,YAAY,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC;gBACH,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;gBAC3B,MAAM,MAAM,GAAG,MAAM,qBAAS,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;gBAC7D,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBAC9B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;gBACnE,OAAO,IAAI,CAAC,YAAY,CAAC;YAC3B,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,EAAE,CAAC;YACZ,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;YAC9B,CAAC;QACH,CAAC;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;AAtCD,kEAsCC","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 // NOTE: This function is from the AuthorizationClient interface. That interface documents\n // this function to return an empty string if no token is available, NOT throw an exception.\n return \"\"; // short-circuits any recursive use of this function\n }\n\n if (this._accessToken && !this._hasExpired) {\n return this._accessToken;\n } else {\n try {\n this._fetchingToken = true;\n const result = await MobileApp.callBackend(\"getAccessToken\");\n this._accessToken = result[0];\n this._expirationDate = result[1] ? new Date(result[1]) : undefined;\n return this._accessToken;\n } catch {\n return \"\";\n } finally {\n this._fetchingToken = false;\n }\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;IAC9B,YAAY,GAAgB,EAAE,CAAC;IAC/B,eAAe,CAAmB;IAClC,aAAa,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,cAAc;IACvC,cAAc,GAAG,KAAK,CAAC;IAE/B,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,CAAC;YACxB,0FAA0F;YAC1F,4FAA4F;YAC5F,OAAO,EAAE,CAAC,CAAC,oDAAoD;QACjE,CAAC;QAED,IAAI,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC,YAAY,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC;gBACH,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;gBAC3B,MAAM,MAAM,GAAG,MAAM,qBAAS,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;gBAC7D,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;gBAC9B,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;gBACnE,OAAO,IAAI,CAAC,YAAY,CAAC;YAC3B,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,EAAE,CAAC;YACZ,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;YAC9B,CAAC;QACH,CAAC;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;AAtCD,kEAsCC","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 // NOTE: This function is from the AuthorizationClient interface. That interface documents\n // this function to return an empty string if no token is available, NOT throw an exception.\n return \"\"; // short-circuits any recursive use of this function\n }\n\n if (this._accessToken && !this._hasExpired) {\n return this._accessToken;\n } else {\n try {\n this._fetchingToken = true;\n const result = await MobileApp.callBackend(\"getAccessToken\");\n this._accessToken = result[0];\n this._expirationDate = result[1] ? new Date(result[1]) : undefined;\n return this._accessToken;\n } catch {\n return \"\";\n } finally {\n this._fetchingToken = false;\n }\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": "5.0.0-dev.8",
3
+ "version": "5.0.0-dev.83",
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.8",
26
- "@itwin/core-bentley": "^5.0.0-dev.8",
27
- "@itwin/core-common": "^5.0.0-dev.8",
28
- "@itwin/core-frontend": "^5.0.0-dev.8"
25
+ "@itwin/core-backend": "5.0.0-dev.83",
26
+ "@itwin/core-bentley": "5.0.0-dev.83",
27
+ "@itwin/core-frontend": "5.0.0-dev.83",
28
+ "@itwin/core-common": "5.0.0-dev.83"
29
29
  },
30
30
  "dependencies": {
31
31
  "lodash": "^4.17.21",
@@ -38,7 +38,7 @@
38
38
  "@types/fs-extra": "^4.0.7",
39
39
  "@types/lodash": "^4.14.202",
40
40
  "@types/mocha": "^10.0.6",
41
- "@types/node": "~20.9.5",
41
+ "@types/node": "~20.17.0",
42
42
  "@types/superagent": "^8.1.6",
43
43
  "@types/ws": "^7.0.0",
44
44
  "chai": "^4.3.10",
@@ -46,19 +46,19 @@
46
46
  "dotenv": "^16.4.5",
47
47
  "dotenv-expand": "^5.1.0",
48
48
  "eslint": "^9.13.0",
49
- "mocha": "^10.2.0",
50
- "rimraf": "^3.0.2",
49
+ "mocha": "^11.1.0",
50
+ "rimraf": "^6.0.1",
51
51
  "typescript": "~5.6.2",
52
- "@itwin/build-tools": "5.0.0-dev.8",
53
- "@itwin/core-backend": "5.0.0-dev.8",
54
- "@itwin/core-bentley": "5.0.0-dev.8",
55
- "@itwin/core-common": "5.0.0-dev.8",
56
- "@itwin/core-frontend": "5.0.0-dev.8"
52
+ "@itwin/core-bentley": "5.0.0-dev.83",
53
+ "@itwin/core-common": "5.0.0-dev.83",
54
+ "@itwin/build-tools": "5.0.0-dev.83",
55
+ "@itwin/core-backend": "5.0.0-dev.83",
56
+ "@itwin/core-frontend": "5.0.0-dev.83"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "npm run -s build:cjs",
60
60
  "build:cjs": "tsc 1>&2 --outDir lib/cjs",
61
- "clean": "rimraf lib .rush/temp/package-deps*.json",
61
+ "clean": "rimraf -g lib .rush/temp/package-deps*.json",
62
62
  "docs": "betools docs --json=../../generated-docs/core/core-mobile/file.json --tsIndexFile=./__DOC_ONLY__.ts --onlyJson",
63
63
  "extract-api": "betools extract-api --entry=__DOC_ONLY__",
64
64
  "lint": "eslint \"./src/**/*.ts\" 1>&2",