@itwin/core-mobile 5.0.0-dev.40 → 5.0.0-dev.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -1
- package/lib/cjs/backend/MobileRpcServer.d.ts +1 -1
- package/lib/cjs/backend/MobileRpcServer.d.ts.map +1 -1
- package/lib/cjs/backend/MobileRpcServer.js +3 -3
- package/lib/cjs/backend/MobileRpcServer.js.map +1 -1
- package/lib/cjs/common/MobileIpc.d.ts.map +1 -1
- package/lib/cjs/common/MobileIpc.js +65 -4
- package/lib/cjs/common/MobileIpc.js.map +1 -1
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Change Log - @itwin/core-mobile
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 24 Jan 2025 08:05:17 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.10.6
|
|
6
|
+
Fri, 24 Jan 2025 08:02:40 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
9
|
+
|
|
10
|
+
## 4.10.5
|
|
11
|
+
Tue, 21 Jan 2025 21:56:45 GMT
|
|
12
|
+
|
|
13
|
+
_Version update only_
|
|
4
14
|
|
|
5
15
|
## 4.10.4
|
|
6
16
|
Mon, 13 Jan 2025 14:06:43 GMT
|
|
@@ -16,7 +16,7 @@ export declare class MobileRpcServer {
|
|
|
16
16
|
private _createSender;
|
|
17
17
|
private _sendPending;
|
|
18
18
|
private _onConnectionMessage;
|
|
19
|
-
dispose(): void;
|
|
19
|
+
[Symbol.dispose](): void;
|
|
20
20
|
}
|
|
21
21
|
export declare function setupMobileRpc(): void;
|
|
22
22
|
//# sourceMappingURL=MobileRpcServer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileRpcServer.d.ts","sourceRoot":"","sources":["../../../src/backend/MobileRpcServer.ts"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aAAa;IAiBrB,OAAO,CAAC,YAAY;IAcpB,OAAO,CAAC,oBAAoB;IAiBrB,CAAC,MAAM,CAAC,OAAO,CAAC;CAUxB;AAKD,wBAAgB,cAAc,SAoE7B"}
|
|
@@ -110,7 +110,7 @@ class MobileRpcServer {
|
|
|
110
110
|
}
|
|
111
111
|
MobileRpcServer.interop.handler(message, this._connectionId);
|
|
112
112
|
}
|
|
113
|
-
dispose() {
|
|
113
|
+
[Symbol.dispose]() {
|
|
114
114
|
clearInterval(this._pingTimer);
|
|
115
115
|
if (this._connection) {
|
|
116
116
|
MobileRpcServer.interop.sendString = () => { };
|
|
@@ -152,7 +152,7 @@ function setupMobileRpc() {
|
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
154
154
|
retainUvLoop = setInterval(() => { }, 1000);
|
|
155
|
-
server.dispose();
|
|
155
|
+
server[Symbol.dispose]();
|
|
156
156
|
usePendingSender();
|
|
157
157
|
server = null;
|
|
158
158
|
global.__iTwinJsRpcReady = false;
|
|
@@ -173,7 +173,7 @@ function setupMobileRpc() {
|
|
|
173
173
|
if (server === null) {
|
|
174
174
|
return;
|
|
175
175
|
}
|
|
176
|
-
server.dispose();
|
|
176
|
+
server[Symbol.dispose]();
|
|
177
177
|
server = null;
|
|
178
178
|
});
|
|
179
179
|
MobileRpcProtocol_1.MobileRpcProtocol.obtainInterop = () => MobileRpcServer.interop;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileRpcServer.js","sourceRoot":"","sources":["../../../src/backend/MobileRpcServer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAmJ/F,wCAoEC;AArND,yBAAyB;AACzB,oDAAiD;AACjD,mEAAkF;AAClF,iEAAoE;AACpE,6CAA0C;AAC1C,sDAAqE;AAOrE,IAAI,KAA8B,CAAC;AAEnC,gBAAgB;AAChB,MAAa,eAAe;aACX,YAAO,GAAG,CAAC,CAAC,CAAC;aAEd,YAAO,GAAqB;QACxC,OAAO,EAAE,CAAC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T,CAAC;QAED,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;QAC5C,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,gBAAgB,EAAE,CAAC;QACnB,MAAM,GAAG,IAAI,CAAC;QACb,MAAc,CAAC,iBAAiB,GAAG,KAAK,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE;QAC5C,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,MAAM,GAAG,IAAI,eAAe,CAAC,eAAe,CAAC,CAAC;QAC9C,aAAa,CAAC,YAAY,CAAC,CAAC;QAC5B,YAAY,GAAG,SAAS,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,eAAe,CAAC,WAAW,CAAC,GAAG,EAAE;QAC1C,IAAI,OAAO,CAAC,YAAY,CAAC,KAAK,WAAW,EAAE,CAAC;YAC1C,aAAa,CAAC,YAAY,CAAC,CAAC;YAC5B,YAAY,GAAG,SAAS,CAAC;QAC3B,CAAC;QAED,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,qCAAiB,CAAC,aAAa,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC;IAChE,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport * as ws from \"ws\";\nimport { IModelError } from \"@itwin/core-common\";\nimport { MobileRpcGateway, MobileRpcProtocol } from \"../common/MobileRpcProtocol\";\nimport { MobileRpcConfiguration } from \"../common/MobileRpcManager\";\nimport { MobileHost } from \"./MobileHost\";\nimport { BentleyStatus, ProcessDetector } from \"@itwin/core-bentley\";\n\ninterface MobileAddon {\n notifyListening: (port: number) => void;\n registerDeviceImpl: () => void;\n}\n\nlet addon: MobileAddon | undefined;\n\n/** @internal */\nexport class MobileRpcServer {\n private static _nextId = -1;\n\n public static interop: MobileRpcGateway = {\n handler: (_payload: ArrayBuffer | string) => { throw new IModelError(BentleyStatus.ERROR, \"Not implemented.\"); },\n sendString: (_message: string, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\n sendBinary: (_message: Uint8Array, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\n port: 0,\n connectionId: 0,\n };\n\n private _server: ws.Server;\n private _connection: ws | undefined;\n private _port: number;\n private _connectionId: number;\n private _pingTimer: NodeJS.Timeout;\n public constructor(private _pendingMessages: Array<string | Uint8Array> | undefined = undefined) {\n /* _pingTime is a fix for ios/mobile case where when the app moves into foreground from\n * background backend restart ws.Server and then notify frontend to reconnect. But ws.Server\n * listening event is not fired as node yield to kevent and wait for some io event to happen.\n * This causes a delay in reconnection which may be as long a 40 secs. To solve the issue we\n * create _pingTimer which causes kevent to yield back to uv poll so timer event can be fired.\n * This allow listening event to go through quickly (max 5ms). Once the listening event occur we\n * clear the timer. Here we use setInterval() just to make sure otherwise setTimeout() could equally\n * be effective\n */\n this._pingTimer = setInterval(() => { }, 5);\n this._port = MobileRpcConfiguration.setup.obtainPort();\n this._server = new ws.Server({ port: this._port });\n this._connectionId = ++MobileRpcServer._nextId;\n MobileRpcServer.interop.connectionId = this._connectionId;\n this._onListening();\n this._onConnection();\n }\n\n private _onListening() {\n this._server.on(\"listening\", () => {\n const address = this._server.address() as ws.AddressInfo;\n this._port = address.port;\n clearInterval(this._pingTimer);\n this._notifyListening();\n });\n }\n\n private _notifyListening() {\n MobileRpcServer.interop.port = this._port;\n\n if (addon) {\n addon.notifyListening(this._port);\n }\n\n if (this._connectionId !== 0) {\n MobileHost.reconnect(this._port);\n }\n }\n\n private _onConnection() {\n this._server.on(\"connection\", (connection) => {\n this._connection = connection;\n this._connection.on(\"message\", (data) => this._onConnectionMessage(data));\n this._createSender();\n this._sendPending();\n (global as any).__iTwinJsRpcReady = true;\n MobileHost.onConnected.raiseEvent();\n });\n }\n\n private _createSender() {\n const sender = (message: string | Uint8Array, connectionId: number) => {\n if (connectionId !== this._connectionId) {\n return;\n }\n\n this._connection!.send(message, (err) => {\n if (err) {\n throw err;\n }\n });\n };\n\n MobileRpcServer.interop.sendString = sender;\n MobileRpcServer.interop.sendBinary = sender;\n }\n\n private _sendPending() {\n if (this._pendingMessages === undefined)\n return;\n\n for (const message of this._pendingMessages) {\n this._connection!.send(message, (err) => {\n if (err) {\n throw err;\n }\n });\n }\n this._pendingMessages.length = 0;\n }\n\n private _onConnectionMessage(data: ws.Data) {\n let message = data;\n if (Array.isArray(message)) {\n throw new IModelError(BentleyStatus.ERROR, \"Unsupported data type\");\n }\n\n if (Buffer.isBuffer(message)) {\n if (message.byteOffset !== 0 || message.byteLength !== message.buffer.byteLength) {\n message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);\n } else {\n message = message.buffer;\n }\n }\n\n MobileRpcServer.interop.handler(message, this._connectionId);\n }\n\n public dispose() {\n clearInterval(this._pingTimer);\n if (this._connection) {\n MobileRpcServer.interop.sendString = () => { };\n MobileRpcServer.interop.sendBinary = () => { };\n this._connection.close();\n }\n\n this._server.close();\n }\n}\n\nlet mobileReady = false;\nlet hasSuspended = false;\n\nexport function setupMobileRpc() {\n if (mobileReady) {\n return;\n }\n\n if (ProcessDetector.isMobileAppBackend) {\n addon = (process as any)._linkedBinding(\"iModelJsMobile\");\n addon?.registerDeviceImpl();\n }\n\n let server: MobileRpcServer | null = new MobileRpcServer();\n\n /* The UV event loop (internal to node) is retained by handles,\n such as those created for setInterval/setTimeout and client/server connections.\n In a simple app, the RPC server may be the only handle retaining the UV loop.\n Thus, we install a temporary timer on suspend to prevent the loop from exiting prematurely.\n */\n let retainUvLoop: NodeJS.Timeout | undefined;\n const pendingMessages: Array<string | Uint8Array> = [];\n\n function usePendingSender() {\n const sender = (message: string | Uint8Array, _connectionId: number) => {\n pendingMessages.push(message);\n };\n MobileRpcServer.interop.sendString = sender;\n MobileRpcServer.interop.sendBinary = sender;\n }\n\n MobileHost.onEnterBackground.addListener(() => {\n hasSuspended = true;\n\n if (server === null) {\n return;\n }\n\n retainUvLoop = setInterval(() => { }, 1000);\n server.dispose();\n usePendingSender();\n server = null;\n (global as any).__iTwinJsRpcReady = false;\n });\n\n MobileHost.onEnterForeground.addListener(() => {\n if (!hasSuspended) {\n return;\n }\n\n server = new MobileRpcServer(pendingMessages);\n clearInterval(retainUvLoop);\n retainUvLoop = undefined;\n });\n\n MobileHost.onWillTerminate.addListener(() => {\n if (typeof (retainUvLoop) !== \"undefined\") {\n clearInterval(retainUvLoop);\n retainUvLoop = undefined;\n }\n\n if (server === null) {\n return;\n }\n\n server.dispose();\n server = null;\n });\n\n MobileRpcProtocol.obtainInterop = () => MobileRpcServer.interop;\n mobileReady = true;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MobileRpcServer.js","sourceRoot":"","sources":["../../../src/backend/MobileRpcServer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAmJ/F,wCAoEC;AArND,yBAAyB;AACzB,oDAAiD;AACjD,mEAAkF;AAClF,iEAAoE;AACpE,6CAA0C;AAC1C,sDAAqE;AAOrE,IAAI,KAA8B,CAAC;AAEnC,gBAAgB;AAChB,MAAa,eAAe;aACX,YAAO,GAAG,CAAC,CAAC,CAAC;aAEd,YAAO,GAAqB;QACxC,OAAO,EAAE,CAAC,QAA8B,EAAE,EAAE,GAAG,MAAM,IAAI,yBAAW,CAAC,4BAAa,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;QAChH,UAAU,EAAE,CAAC,QAAgB,EAAE,aAAqB,EAAE,EAAE,GAAG,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BAAgB,EAAE,CAAC;QACnB,MAAM,GAAG,IAAI,CAAC;QACb,MAAc,CAAC,iBAAiB,GAAG,KAAK,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE;QAC5C,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO;QACT,CAAC;QAED,MAAM,GAAG,IAAI,eAAe,CAAC,eAAe,CAAC,CAAC;QAC9C,aAAa,CAAC,YAAY,CAAC,CAAC;QAC5B,YAAY,GAAG,SAAS,CAAC;IAC3B,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,eAAe,CAAC,WAAW,CAAC,GAAG,EAAE;QAC1C,IAAI,OAAO,CAAC,YAAY,CAAC,KAAK,WAAW,EAAE,CAAC;YAC1C,aAAa,CAAC,YAAY,CAAC,CAAC;YAC5B,YAAY,GAAG,SAAS,CAAC;QAC3B,CAAC;QAED,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,qCAAiB,CAAC,aAAa,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC;IAChE,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport * as ws from \"ws\";\nimport { IModelError } from \"@itwin/core-common\";\nimport { MobileRpcGateway, MobileRpcProtocol } from \"../common/MobileRpcProtocol\";\nimport { MobileRpcConfiguration } from \"../common/MobileRpcManager\";\nimport { MobileHost } from \"./MobileHost\";\nimport { BentleyStatus, ProcessDetector } from \"@itwin/core-bentley\";\n\ninterface MobileAddon {\n notifyListening: (port: number) => void;\n registerDeviceImpl: () => void;\n}\n\nlet addon: MobileAddon | undefined;\n\n/** @internal */\nexport class MobileRpcServer {\n private static _nextId = -1;\n\n public static interop: MobileRpcGateway = {\n handler: (_payload: ArrayBuffer | string) => { throw new IModelError(BentleyStatus.ERROR, \"Not implemented.\"); },\n sendString: (_message: string, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\n sendBinary: (_message: Uint8Array, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\n port: 0,\n connectionId: 0,\n };\n\n private _server: ws.Server;\n private _connection: ws | undefined;\n private _port: number;\n private _connectionId: number;\n private _pingTimer: NodeJS.Timeout;\n public constructor(private _pendingMessages: Array<string | Uint8Array> | undefined = undefined) {\n /* _pingTime is a fix for ios/mobile case where when the app moves into foreground from\n * background backend restart ws.Server and then notify frontend to reconnect. But ws.Server\n * listening event is not fired as node yield to kevent and wait for some io event to happen.\n * This causes a delay in reconnection which may be as long a 40 secs. To solve the issue we\n * create _pingTimer which causes kevent to yield back to uv poll so timer event can be fired.\n * This allow listening event to go through quickly (max 5ms). Once the listening event occur we\n * clear the timer. Here we use setInterval() just to make sure otherwise setTimeout() could equally\n * be effective\n */\n this._pingTimer = setInterval(() => { }, 5);\n this._port = MobileRpcConfiguration.setup.obtainPort();\n this._server = new ws.Server({ port: this._port });\n this._connectionId = ++MobileRpcServer._nextId;\n MobileRpcServer.interop.connectionId = this._connectionId;\n this._onListening();\n this._onConnection();\n }\n\n private _onListening() {\n this._server.on(\"listening\", () => {\n const address = this._server.address() as ws.AddressInfo;\n this._port = address.port;\n clearInterval(this._pingTimer);\n this._notifyListening();\n });\n }\n\n private _notifyListening() {\n MobileRpcServer.interop.port = this._port;\n\n if (addon) {\n addon.notifyListening(this._port);\n }\n\n if (this._connectionId !== 0) {\n MobileHost.reconnect(this._port);\n }\n }\n\n private _onConnection() {\n this._server.on(\"connection\", (connection) => {\n this._connection = connection;\n this._connection.on(\"message\", (data) => this._onConnectionMessage(data));\n this._createSender();\n this._sendPending();\n (global as any).__iTwinJsRpcReady = true;\n MobileHost.onConnected.raiseEvent();\n });\n }\n\n private _createSender() {\n const sender = (message: string | Uint8Array, connectionId: number) => {\n if (connectionId !== this._connectionId) {\n return;\n }\n\n this._connection!.send(message, (err) => {\n if (err) {\n throw err;\n }\n });\n };\n\n MobileRpcServer.interop.sendString = sender;\n MobileRpcServer.interop.sendBinary = sender;\n }\n\n private _sendPending() {\n if (this._pendingMessages === undefined)\n return;\n\n for (const message of this._pendingMessages) {\n this._connection!.send(message, (err) => {\n if (err) {\n throw err;\n }\n });\n }\n this._pendingMessages.length = 0;\n }\n\n private _onConnectionMessage(data: ws.Data) {\n let message = data;\n if (Array.isArray(message)) {\n throw new IModelError(BentleyStatus.ERROR, \"Unsupported data type\");\n }\n\n if (Buffer.isBuffer(message)) {\n if (message.byteOffset !== 0 || message.byteLength !== message.buffer.byteLength) {\n message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);\n } else {\n message = message.buffer;\n }\n }\n\n MobileRpcServer.interop.handler(message, this._connectionId);\n }\n\n public [Symbol.dispose]() {\n clearInterval(this._pingTimer);\n if (this._connection) {\n MobileRpcServer.interop.sendString = () => { };\n MobileRpcServer.interop.sendBinary = () => { };\n this._connection.close();\n }\n\n this._server.close();\n }\n}\n\nlet mobileReady = false;\nlet hasSuspended = false;\n\nexport function setupMobileRpc() {\n if (mobileReady) {\n return;\n }\n\n if (ProcessDetector.isMobileAppBackend) {\n addon = (process as any)._linkedBinding(\"iModelJsMobile\");\n addon?.registerDeviceImpl();\n }\n\n let server: MobileRpcServer | null = new MobileRpcServer();\n\n /* The UV event loop (internal to node) is retained by handles,\n such as those created for setInterval/setTimeout and client/server connections.\n In a simple app, the RPC server may be the only handle retaining the UV loop.\n Thus, we install a temporary timer on suspend to prevent the loop from exiting prematurely.\n */\n let retainUvLoop: NodeJS.Timeout | undefined;\n const pendingMessages: Array<string | Uint8Array> = [];\n\n function usePendingSender() {\n const sender = (message: string | Uint8Array, _connectionId: number) => {\n pendingMessages.push(message);\n };\n MobileRpcServer.interop.sendString = sender;\n MobileRpcServer.interop.sendBinary = sender;\n }\n\n MobileHost.onEnterBackground.addListener(() => {\n hasSuspended = true;\n\n if (server === null) {\n return;\n }\n\n retainUvLoop = setInterval(() => { }, 1000);\n server[Symbol.dispose]();\n usePendingSender();\n server = null;\n (global as any).__iTwinJsRpcReady = false;\n });\n\n MobileHost.onEnterForeground.addListener(() => {\n if (!hasSuspended) {\n return;\n }\n\n server = new MobileRpcServer(pendingMessages);\n clearInterval(retainUvLoop);\n retainUvLoop = undefined;\n });\n\n MobileHost.onWillTerminate.addListener(() => {\n if (typeof (retainUvLoop) !== \"undefined\") {\n clearInterval(retainUvLoop);\n retainUvLoop = undefined;\n }\n\n if (server === null) {\n return;\n }\n\n server[Symbol.dispose]();\n server = null;\n });\n\n MobileRpcProtocol.obtainInterop = () => MobileRpcServer.interop;\n mobileReady = true;\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;
|
|
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");
|
|
@@ -49,10 +101,19 @@ class MobileIpcTransport extends core_common_1.IpcWebSocketTransport {
|
|
|
49
101
|
return true;
|
|
50
102
|
}
|
|
51
103
|
async sendToBackend(message) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
104
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
105
|
+
try {
|
|
106
|
+
const request = __addDisposableResource(env_1, new MobileRpcRequest_1.MobileRpcRequest(this._client, "send", [message]), false);
|
|
107
|
+
const encoded = await MobileRpcProtocol_1.MobileRpcProtocol.encodeRequest(request);
|
|
108
|
+
this._protocol.sendToBackend(encoded);
|
|
109
|
+
}
|
|
110
|
+
catch (e_1) {
|
|
111
|
+
env_1.error = e_1;
|
|
112
|
+
env_1.hasError = true;
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
__disposeResources(env_1);
|
|
116
|
+
}
|
|
56
117
|
}
|
|
57
118
|
sendToFrontend(message) {
|
|
58
119
|
MobileEventLoop_1.MobileEventLoop.addTask();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileIpc.js","sourceRoot":"","sources":["../../../src/common/MobileIpc.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG
|
|
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;aACvB,kBAAa,GAAG,GAAG,CAAC;aACpB,qBAAgB,GAAG,OAAO,CAAC;IAClC,KAAK,CAAC,IAAI,KAAK,CAAC;;AAGzB,gBAAgB;AAChB,MAAa,kBAAmB,SAAQ,mCAAqB;IAI3D,YAAmB,QAA2B;QAC5C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,QAAQ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M,OAAO,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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-mobile",
|
|
3
|
-
"version": "5.0.0-dev.
|
|
3
|
+
"version": "5.0.0-dev.49",
|
|
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-
|
|
26
|
-
"@itwin/core-
|
|
27
|
-
"@itwin/core-common": "5.0.0-dev.
|
|
28
|
-
"@itwin/core-
|
|
25
|
+
"@itwin/core-backend": "5.0.0-dev.49",
|
|
26
|
+
"@itwin/core-bentley": "5.0.0-dev.49",
|
|
27
|
+
"@itwin/core-common": "5.0.0-dev.49",
|
|
28
|
+
"@itwin/core-frontend": "5.0.0-dev.49"
|
|
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.
|
|
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",
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
"mocha": "^10.2.0",
|
|
50
50
|
"rimraf": "^3.0.2",
|
|
51
51
|
"typescript": "~5.6.2",
|
|
52
|
-
"@itwin/
|
|
53
|
-
"@itwin/
|
|
54
|
-
"@itwin/core-
|
|
55
|
-
"@itwin/core-
|
|
56
|
-
"@itwin/core-
|
|
52
|
+
"@itwin/core-backend": "5.0.0-dev.49",
|
|
53
|
+
"@itwin/build-tools": "5.0.0-dev.49",
|
|
54
|
+
"@itwin/core-common": "5.0.0-dev.49",
|
|
55
|
+
"@itwin/core-frontend": "5.0.0-dev.49",
|
|
56
|
+
"@itwin/core-bentley": "5.0.0-dev.49"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "npm run -s build:cjs",
|