@itwin/core-mobile 3.0.0-dev.100
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 +263 -0
- package/LICENSE.md +9 -0
- package/README.md +11 -0
- package/lib/cjs/MobileBackend.d.ts +7 -0
- package/lib/cjs/MobileBackend.d.ts.map +1 -0
- package/lib/cjs/MobileBackend.js +24 -0
- package/lib/cjs/MobileBackend.js.map +1 -0
- package/lib/cjs/MobileFrontend.d.ts +5 -0
- package/lib/cjs/MobileFrontend.d.ts.map +1 -0
- package/lib/cjs/MobileFrontend.js +21 -0
- package/lib/cjs/MobileFrontend.js.map +1 -0
- package/lib/cjs/__DOC_ONLY__.d.ts +9 -0
- package/lib/cjs/__DOC_ONLY__.d.ts.map +1 -0
- package/lib/cjs/__DOC_ONLY__.js +28 -0
- package/lib/cjs/__DOC_ONLY__.js.map +1 -0
- package/lib/cjs/backend/AndroidHost.d.ts +11 -0
- package/lib/cjs/backend/AndroidHost.d.ts.map +1 -0
- package/lib/cjs/backend/AndroidHost.js +23 -0
- package/lib/cjs/backend/AndroidHost.js.map +1 -0
- package/lib/cjs/backend/MobileAuthorizationBackend.d.ts +23 -0
- package/lib/cjs/backend/MobileAuthorizationBackend.d.ts.map +1 -0
- package/lib/cjs/backend/MobileAuthorizationBackend.js +78 -0
- package/lib/cjs/backend/MobileAuthorizationBackend.js.map +1 -0
- package/lib/cjs/backend/MobileFileHandler.d.ts +88 -0
- package/lib/cjs/backend/MobileFileHandler.d.ts.map +1 -0
- package/lib/cjs/backend/MobileFileHandler.js +233 -0
- package/lib/cjs/backend/MobileFileHandler.js.map +1 -0
- package/lib/cjs/backend/MobileHost.d.ts +78 -0
- package/lib/cjs/backend/MobileHost.d.ts.map +1 -0
- package/lib/cjs/backend/MobileHost.js +126 -0
- package/lib/cjs/backend/MobileHost.js.map +1 -0
- package/lib/cjs/backend/MobileRpcServer.d.ts +19 -0
- package/lib/cjs/backend/MobileRpcServer.d.ts.map +1 -0
- package/lib/cjs/backend/MobileRpcServer.js +136 -0
- package/lib/cjs/backend/MobileRpcServer.js.map +1 -0
- package/lib/cjs/backend/iOSHost.d.ts +11 -0
- package/lib/cjs/backend/iOSHost.d.ts.map +1 -0
- package/lib/cjs/backend/iOSHost.js +23 -0
- package/lib/cjs/backend/iOSHost.js.map +1 -0
- package/lib/cjs/common/MobileAppProps.d.ts +35 -0
- package/lib/cjs/common/MobileAppProps.d.ts.map +1 -0
- package/lib/cjs/common/MobileAppProps.js +29 -0
- package/lib/cjs/common/MobileAppProps.js.map +1 -0
- package/lib/cjs/common/MobileEventLoop.d.ts +12 -0
- package/lib/cjs/common/MobileEventLoop.d.ts.map +1 -0
- package/lib/cjs/common/MobileEventLoop.js +31 -0
- package/lib/cjs/common/MobileEventLoop.js.map +1 -0
- package/lib/cjs/common/MobileIpc.d.ts +18 -0
- package/lib/cjs/common/MobileIpc.d.ts.map +1 -0
- package/lib/cjs/common/MobileIpc.js +71 -0
- package/lib/cjs/common/MobileIpc.js.map +1 -0
- package/lib/cjs/common/MobilePush.d.ts +21 -0
- package/lib/cjs/common/MobilePush.d.ts.map +1 -0
- package/lib/cjs/common/MobilePush.js +53 -0
- package/lib/cjs/common/MobilePush.js.map +1 -0
- package/lib/cjs/common/MobileRpcManager.d.ts +41 -0
- package/lib/cjs/common/MobileRpcManager.d.ts.map +1 -0
- package/lib/cjs/common/MobileRpcManager.js +110 -0
- package/lib/cjs/common/MobileRpcManager.js.map +1 -0
- package/lib/cjs/common/MobileRpcProtocol.d.ts +59 -0
- package/lib/cjs/common/MobileRpcProtocol.d.ts.map +1 -0
- package/lib/cjs/common/MobileRpcProtocol.js +279 -0
- package/lib/cjs/common/MobileRpcProtocol.js.map +1 -0
- package/lib/cjs/common/MobileRpcRequest.d.ts +21 -0
- package/lib/cjs/common/MobileRpcRequest.d.ts.map +1 -0
- package/lib/cjs/common/MobileRpcRequest.js +48 -0
- package/lib/cjs/common/MobileRpcRequest.js.map +1 -0
- package/lib/cjs/frontend/AndroidApp.d.ts +14 -0
- package/lib/cjs/frontend/AndroidApp.d.ts.map +1 -0
- package/lib/cjs/frontend/AndroidApp.js +17 -0
- package/lib/cjs/frontend/AndroidApp.js.map +1 -0
- package/lib/cjs/frontend/IOSApp.d.ts +10 -0
- package/lib/cjs/frontend/IOSApp.d.ts.map +1 -0
- package/lib/cjs/frontend/IOSApp.js +21 -0
- package/lib/cjs/frontend/IOSApp.js.map +1 -0
- package/lib/cjs/frontend/MobileApp.d.ts +20 -0
- package/lib/cjs/frontend/MobileApp.d.ts.map +1 -0
- package/lib/cjs/frontend/MobileApp.js +57 -0
- package/lib/cjs/frontend/MobileApp.js.map +1 -0
- package/lib/cjs/test/ios/MobilePlatform.test.d.ts +2 -0
- package/lib/cjs/test/ios/MobilePlatform.test.d.ts.map +1 -0
- package/lib/cjs/test/ios/MobilePlatform.test.js +85 -0
- package/lib/cjs/test/ios/MobilePlatform.test.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.setupMobileRpc = exports.MobileRpcServer = void 0;
|
|
8
|
+
const ws = require("ws");
|
|
9
|
+
const core_common_1 = require("@itwin/core-common");
|
|
10
|
+
const MobileRpcProtocol_1 = require("../common/MobileRpcProtocol");
|
|
11
|
+
const MobileRpcManager_1 = require("../common/MobileRpcManager");
|
|
12
|
+
const MobileHost_1 = require("./MobileHost");
|
|
13
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
14
|
+
let addon;
|
|
15
|
+
class MobileRpcServer {
|
|
16
|
+
constructor() {
|
|
17
|
+
/* _pingTime is a fix for ios/mobile case where when app move into foreground from
|
|
18
|
+
* background backend restart ws.Server and then notify frontend to reconnect. But ws.Server
|
|
19
|
+
* listening event is not fired as node yield to kevent and wait for some io event to happen.
|
|
20
|
+
* This causes a delay in reconnection which may be as long a 40 secs. To solve the issue we
|
|
21
|
+
* create _pingTimer which causes kevent to yield back to uv poll so timer event can be fired.
|
|
22
|
+
* This allow listening event to go through quickly (max 5ms). Once the listening event occur we
|
|
23
|
+
* clear the timer. Here we use setInterval() just to make sure otherwise setTimeout() could equally
|
|
24
|
+
* be effective
|
|
25
|
+
*/
|
|
26
|
+
this._pingTimer = setInterval(() => { }, 5);
|
|
27
|
+
this._port = MobileRpcManager_1.MobileRpcConfiguration.setup.obtainPort();
|
|
28
|
+
this._server = new ws.Server({ port: this._port });
|
|
29
|
+
this._connectionId = ++MobileRpcServer._nextId;
|
|
30
|
+
MobileRpcServer.interop.connectionId = this._connectionId;
|
|
31
|
+
this._onListening();
|
|
32
|
+
this._onConnection();
|
|
33
|
+
}
|
|
34
|
+
_onListening() {
|
|
35
|
+
this._server.on("listening", () => {
|
|
36
|
+
const address = this._server.address();
|
|
37
|
+
this._port = address.port;
|
|
38
|
+
clearInterval(this._pingTimer);
|
|
39
|
+
this._notifyListening();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
_notifyListening() {
|
|
43
|
+
MobileRpcServer.interop.port = this._port;
|
|
44
|
+
if (addon) {
|
|
45
|
+
addon.notifyListening(this._port);
|
|
46
|
+
}
|
|
47
|
+
if (this._connectionId !== 0) {
|
|
48
|
+
MobileHost_1.MobileHost.reconnect(this._port);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
_onConnection() {
|
|
52
|
+
this._server.on("connection", (connection) => {
|
|
53
|
+
this._connection = connection;
|
|
54
|
+
this._connection.on("message", (data) => this._onConnectionMessage(data));
|
|
55
|
+
this._createSender();
|
|
56
|
+
global.__iTwinJsRpcReady = true;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
_createSender() {
|
|
60
|
+
const sender = (message, connectionId) => {
|
|
61
|
+
if (connectionId !== this._connectionId) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this._connection.send(message, (err) => {
|
|
65
|
+
if (err) {
|
|
66
|
+
throw err;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
MobileRpcServer.interop.sendString = sender;
|
|
71
|
+
MobileRpcServer.interop.sendBinary = sender;
|
|
72
|
+
}
|
|
73
|
+
_onConnectionMessage(data) {
|
|
74
|
+
let message = data;
|
|
75
|
+
if (Array.isArray(message)) {
|
|
76
|
+
throw new core_common_1.IModelError(core_common_1.BentleyStatus.ERROR, "Unsupported data type");
|
|
77
|
+
}
|
|
78
|
+
if (Buffer.isBuffer(message)) {
|
|
79
|
+
if (message.byteOffset !== 0 || message.byteLength !== message.buffer.byteLength) {
|
|
80
|
+
message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
message = message.buffer;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
MobileRpcServer.interop.handler(message, this._connectionId);
|
|
87
|
+
}
|
|
88
|
+
dispose() {
|
|
89
|
+
clearInterval(this._pingTimer);
|
|
90
|
+
if (this._connection) {
|
|
91
|
+
MobileRpcServer.interop.sendString = () => { };
|
|
92
|
+
MobileRpcServer.interop.sendBinary = () => { };
|
|
93
|
+
this._connection.close();
|
|
94
|
+
}
|
|
95
|
+
this._server.close();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.MobileRpcServer = MobileRpcServer;
|
|
99
|
+
MobileRpcServer._nextId = -1;
|
|
100
|
+
MobileRpcServer.interop = {
|
|
101
|
+
handler: (_payload) => { throw new core_common_1.IModelError(core_common_1.BentleyStatus.ERROR, "Not implemented."); },
|
|
102
|
+
sendString: (_message, _connectionId) => { throw new core_common_1.IModelError(core_common_1.BentleyStatus.ERROR, "No connection."); },
|
|
103
|
+
sendBinary: (_message, _connectionId) => { throw new core_common_1.IModelError(core_common_1.BentleyStatus.ERROR, "No connection."); },
|
|
104
|
+
port: 0,
|
|
105
|
+
connectionId: 0,
|
|
106
|
+
};
|
|
107
|
+
let mobileReady = false;
|
|
108
|
+
let hasSuspended = false;
|
|
109
|
+
function setupMobileRpc() {
|
|
110
|
+
if (mobileReady) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (core_bentley_1.ProcessDetector.isMobileAppBackend) {
|
|
114
|
+
addon = process._linkedBinding("iModelJsMobile");
|
|
115
|
+
addon === null || addon === void 0 ? void 0 : addon.registerDeviceImpl();
|
|
116
|
+
}
|
|
117
|
+
let server = new MobileRpcServer();
|
|
118
|
+
MobileHost_1.MobileHost.onEnterBackground.addListener(() => {
|
|
119
|
+
hasSuspended = true;
|
|
120
|
+
if (server === null) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
server.dispose();
|
|
124
|
+
server = null;
|
|
125
|
+
});
|
|
126
|
+
MobileHost_1.MobileHost.onEnterForeground.addListener(() => {
|
|
127
|
+
if (!hasSuspended) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
server = new MobileRpcServer();
|
|
131
|
+
});
|
|
132
|
+
MobileRpcProtocol_1.MobileRpcProtocol.obtainInterop = () => MobileRpcServer.interop;
|
|
133
|
+
mobileReady = true;
|
|
134
|
+
}
|
|
135
|
+
exports.setupMobileRpc = setupMobileRpc;
|
|
136
|
+
//# sourceMappingURL=MobileRpcServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileRpcServer.js","sourceRoot":"","sources":["../../../src/backend/MobileRpcServer.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,yBAAyB;AACzB,oDAAgE;AAChE,mEAAkF;AAClF,iEAAoE;AACpE,6CAA0C;AAC1C,sDAAsD;AAOtD,IAAI,KAA8B,CAAC;AAEnC,MAAa,eAAe;I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EAAE;QACtC,KAAK,GAAI,OAAe,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC;QAC1D,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,kBAAkB,EAAE,CAAC;KAC7B;IAED,IAAI,MAAM,GAA2B,IAAI,eAAe,EAAE,CAAC;IAE3D,uBAAU,CAAC,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE;QAC5C,YAAY,GAAG,IAAI,CAAC;QAEpB,IAAI,MAAM,KAAK,IAAI,EAAE;YACnB,OAAO;SACR;QAED,MAAM,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC,CAAC,CAAC;IAEH,uBAAU,CAAC,iBAAiB,CAAC,WAAW,CAAC,GAAG,EAAE;QAC5C,IAAI,CAAC,YAAY,EAAE;YACjB,OAAO;SACR;QAED,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACjC,CAAC,CAAC,CAAC;IAEH,qCAAiB,CAAC,aAAa,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC,OAAO,CAAC;IAChE,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAjCD,wCAiCC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport * as ws from \"ws\";\r\nimport { BentleyStatus, IModelError } from \"@itwin/core-common\";\r\nimport { MobileRpcGateway, MobileRpcProtocol } from \"../common/MobileRpcProtocol\";\r\nimport { MobileRpcConfiguration } from \"../common/MobileRpcManager\";\r\nimport { MobileHost } from \"./MobileHost\";\r\nimport { ProcessDetector } from \"@itwin/core-bentley\";\r\n\r\ninterface MobileAddon {\r\n notifyListening: (port: number) => void;\r\n registerDeviceImpl: () => void;\r\n}\r\n\r\nlet addon: MobileAddon | undefined;\r\n\r\nexport class MobileRpcServer {\r\n private static _nextId = -1;\r\n\r\n public static interop: MobileRpcGateway = {\r\n handler: (_payload: ArrayBuffer | string) => { throw new IModelError(BentleyStatus.ERROR, \"Not implemented.\"); },\r\n sendString: (_message: string, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\r\n sendBinary: (_message: Uint8Array, _connectionId: number) => { throw new IModelError(BentleyStatus.ERROR, \"No connection.\"); },\r\n port: 0,\r\n connectionId: 0,\r\n };\r\n\r\n private _server: ws.Server;\r\n private _connection: ws | undefined;\r\n private _port: number;\r\n private _connectionId: number;\r\n private _pingTimer: NodeJS.Timeout;\r\n public constructor() {\r\n /* _pingTime is a fix for ios/mobile case where when app move into foreground from\r\n * background backend restart ws.Server and then notify frontend to reconnect. But ws.Server\r\n * listening event is not fired as node yield to kevent and wait for some io event to happen.\r\n * This causes a delay in reconnection which may be as long a 40 secs. To solve the issue we\r\n * create _pingTimer which causes kevent to yield back to uv poll so timer event can be fired.\r\n * This allow listening event to go through quickly (max 5ms). Once the listening event occur we\r\n * clear the timer. Here we use setInterval() just to make sure otherwise setTimeout() could equally\r\n * be effective\r\n */\r\n this._pingTimer = setInterval(() => { }, 5);\r\n this._port = MobileRpcConfiguration.setup.obtainPort();\r\n this._server = new ws.Server({ port: this._port });\r\n this._connectionId = ++MobileRpcServer._nextId;\r\n MobileRpcServer.interop.connectionId = this._connectionId;\r\n this._onListening();\r\n this._onConnection();\r\n }\r\n\r\n private _onListening() {\r\n this._server.on(\"listening\", () => {\r\n const address = this._server.address() as ws.AddressInfo;\r\n this._port = address.port;\r\n clearInterval(this._pingTimer);\r\n this._notifyListening();\r\n });\r\n }\r\n\r\n private _notifyListening() {\r\n MobileRpcServer.interop.port = this._port;\r\n\r\n if (addon) {\r\n addon.notifyListening(this._port);\r\n }\r\n\r\n if (this._connectionId !== 0) {\r\n MobileHost.reconnect(this._port);\r\n }\r\n }\r\n\r\n private _onConnection() {\r\n this._server.on(\"connection\", (connection) => {\r\n this._connection = connection;\r\n this._connection.on(\"message\", (data) => this._onConnectionMessage(data));\r\n this._createSender();\r\n (global as any).__iTwinJsRpcReady = true;\r\n });\r\n }\r\n\r\n private _createSender() {\r\n const sender = (message: string | Uint8Array, connectionId: number) => {\r\n if (connectionId !== this._connectionId) {\r\n return;\r\n }\r\n\r\n this._connection!.send(message, (err) => {\r\n if (err) {\r\n throw err;\r\n }\r\n });\r\n };\r\n\r\n MobileRpcServer.interop.sendString = sender;\r\n MobileRpcServer.interop.sendBinary = sender;\r\n }\r\n\r\n private _onConnectionMessage(data: ws.Data) {\r\n let message = data;\r\n if (Array.isArray(message)) {\r\n throw new IModelError(BentleyStatus.ERROR, \"Unsupported data type\");\r\n }\r\n\r\n if (Buffer.isBuffer(message)) {\r\n if (message.byteOffset !== 0 || message.byteLength !== message.buffer.byteLength) {\r\n message = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);\r\n } else {\r\n message = message.buffer;\r\n }\r\n }\r\n\r\n MobileRpcServer.interop.handler(message, this._connectionId);\r\n }\r\n\r\n public dispose() {\r\n clearInterval(this._pingTimer);\r\n if (this._connection) {\r\n MobileRpcServer.interop.sendString = () => { };\r\n MobileRpcServer.interop.sendBinary = () => { };\r\n this._connection.close();\r\n }\r\n\r\n this._server.close();\r\n }\r\n}\r\n\r\nlet mobileReady = false;\r\nlet hasSuspended = false;\r\n\r\nexport function setupMobileRpc() {\r\n if (mobileReady) {\r\n return;\r\n }\r\n\r\n if (ProcessDetector.isMobileAppBackend) {\r\n addon = (process as any)._linkedBinding(\"iModelJsMobile\");\r\n addon?.registerDeviceImpl();\r\n }\r\n\r\n let server: MobileRpcServer | null = new MobileRpcServer();\r\n\r\n MobileHost.onEnterBackground.addListener(() => {\r\n hasSuspended = true;\r\n\r\n if (server === null) {\r\n return;\r\n }\r\n\r\n server.dispose();\r\n server = null;\r\n });\r\n\r\n MobileHost.onEnterForeground.addListener(() => {\r\n if (!hasSuspended) {\r\n return;\r\n }\r\n\r\n server = new MobileRpcServer();\r\n });\r\n\r\n MobileRpcProtocol.obtainInterop = () => MobileRpcServer.interop;\r\n mobileReady = true;\r\n}\r\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MobileHost, MobileHostOpts } from "./MobileHost";
|
|
2
|
+
/** @beta */
|
|
3
|
+
export declare type IOSHostOpts = MobileHostOpts;
|
|
4
|
+
/** @beta */
|
|
5
|
+
export declare class IOSHost extends MobileHost {
|
|
6
|
+
/**
|
|
7
|
+
* Start the backend of an IOS app.
|
|
8
|
+
*/
|
|
9
|
+
static startup(opt?: IOSHostOpts): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=iOSHost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iOSHost.d.ts","sourceRoot":"","sources":["../../../src/backend/iOSHost.ts"],"names":[],"mappings":"AAMA,OAAO,EAAgB,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAExE,YAAY;AACZ,oBAAY,WAAW,GAAG,cAAc,CAAC;AAEzC,YAAY;AACZ,qBAAa,OAAQ,SAAQ,UAAU;IACrC;;OAEG;WAC0B,OAAO,CAAC,GAAG,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAKvE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.IOSHost = void 0;
|
|
8
|
+
const core_common_1 = require("@itwin/core-common");
|
|
9
|
+
const MobileHost_1 = require("./MobileHost");
|
|
10
|
+
/** @beta */
|
|
11
|
+
class IOSHost extends MobileHost_1.MobileHost {
|
|
12
|
+
/**
|
|
13
|
+
* Start the backend of an IOS app.
|
|
14
|
+
*/
|
|
15
|
+
static async startup(opt) {
|
|
16
|
+
var _a, _b, _c, _d;
|
|
17
|
+
const device = (_b = (_a = opt === null || opt === void 0 ? void 0 : opt.mobileHost) === null || _a === void 0 ? void 0 : _a.device) !== null && _b !== void 0 ? _b : new MobileHost_1.MobileDevice();
|
|
18
|
+
const socket = (_d = (_c = opt === null || opt === void 0 ? void 0 : opt.ipcHost) === null || _c === void 0 ? void 0 : _c.socket) !== null && _d !== void 0 ? _d : new core_common_1.IpcWebSocketBackend();
|
|
19
|
+
return MobileHost_1.MobileHost.startup({ ...opt, mobileHost: { ...opt === null || opt === void 0 ? void 0 : opt.mobileHost, device }, ipcHost: { ...opt === null || opt === void 0 ? void 0 : opt.ipcHost, socket } });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.IOSHost = IOSHost;
|
|
23
|
+
//# sourceMappingURL=iOSHost.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iOSHost.js","sourceRoot":"","sources":["../../../src/backend/iOSHost.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,oDAAyD;AACzD,6CAAwE;AAKxE,YAAY;AACZ,MAAa,OAAQ,SAAQ,uBAAU;IACrC;;OAEG;IACI,MAAM,CAAU,KAAK,CAAC,OAAO,CAAC,GAAiB;;QACpD,MAAM,MAAM,GAAG,MAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,0CAAE,MAAM,mCAAI,IAAK,yBAAoB,EAAE,CAAC;QACtE,MAAM,MAAM,GAAG,MAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,0CAAE,MAAM,mCAAI,IAAI,iCAAmB,EAAE,CAAC;QACjE,OAAO,uBAAU,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,EAAE,UAAU,EAAE,EAAE,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,GAAG,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IAC1H,CAAC;CACF;AATD,0BASC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { IpcWebSocketBackend } from \"@itwin/core-common\";\r\nimport { MobileDevice, MobileHost, MobileHostOpts } from \"./MobileHost\";\r\n\r\n/** @beta */\r\nexport type IOSHostOpts = MobileHostOpts;\r\n\r\n/** @beta */\r\nexport class IOSHost extends MobileHost {\r\n /**\r\n * Start the backend of an IOS app.\r\n */\r\n public static override async startup(opt?: IOSHostOpts): Promise<void> {\r\n const device = opt?.mobileHost?.device ?? new (MobileDevice as any)();\r\n const socket = opt?.ipcHost?.socket ?? new IpcWebSocketBackend();\r\n return MobileHost.startup({ ...opt, mobileHost: { ...opt?.mobileHost, device }, ipcHost: { ...opt?.ipcHost, socket } });\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export declare const mobileAppChannel = "mobileApp";
|
|
3
|
+
/** @internal */
|
|
4
|
+
export declare const mobileAppNotify = "mobileApp-notify";
|
|
5
|
+
export declare enum Orientation {
|
|
6
|
+
Unknown = 0,
|
|
7
|
+
Portrait = 1,
|
|
8
|
+
PortraitUpsideDown = 2,
|
|
9
|
+
LandscapeLeft = 4,
|
|
10
|
+
LandscapeRight = 8,
|
|
11
|
+
FaceUp = 16,
|
|
12
|
+
FaceDown = 32
|
|
13
|
+
}
|
|
14
|
+
export declare enum BatteryState {
|
|
15
|
+
Unknown = 0,
|
|
16
|
+
Unplugged = 1,
|
|
17
|
+
Charging = 2,
|
|
18
|
+
Full = 3
|
|
19
|
+
}
|
|
20
|
+
export interface MobileNotifications {
|
|
21
|
+
notifyMemoryWarning: () => void;
|
|
22
|
+
notifyOrientationChanged: () => void;
|
|
23
|
+
notifyEnterForeground: () => void;
|
|
24
|
+
notifyEnterBackground: () => void;
|
|
25
|
+
notifyWillTerminate: () => void;
|
|
26
|
+
}
|
|
27
|
+
export declare type DeviceEvents = "memoryWarning" | "orientationChanged" | "enterForeground" | "enterBackground" | "willTerminate";
|
|
28
|
+
/**
|
|
29
|
+
* The methods that may be invoked via Ipc from the frontend of a Mobile App that are implemented on its backend.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export interface MobileAppFunctions {
|
|
33
|
+
reconnect: (connection: number) => Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=MobileAppProps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileAppProps.d.ts","sourceRoot":"","sources":["../../../src/common/MobileAppProps.ts"],"names":[],"mappings":"AAKA,gBAAgB;AAChB,eAAO,MAAM,gBAAgB,cAAc,CAAC;AAC5C,gBAAgB;AAChB,eAAO,MAAM,eAAe,qBAAqB,CAAC;AAElD,oBAAY,WAAW;IACrB,OAAO,IAAI;IACX,QAAQ,IAAM;IACd,kBAAkB,IAAM;IACxB,aAAa,IAAM;IACnB,cAAc,IAAM;IACpB,MAAM,KAAO;IACb,QAAQ,KAAO;CAChB;AAED,oBAAY,YAAY;IACtB,OAAO,IAAI;IACX,SAAS,IAAI;IACb,QAAQ,IAAI;IACZ,IAAI,IAAI;CACT;AAED,MAAM,WAAW,mBAAmB;IAClC,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,wBAAwB,EAAE,MAAM,IAAI,CAAC;IACrC,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC;AAED,oBAAY,YAAY,GAAG,eAAe,GAAG,oBAAoB,GAAG,iBAAiB,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAE5H;;;EAGE;AACF,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAClD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.BatteryState = exports.Orientation = exports.mobileAppNotify = exports.mobileAppChannel = void 0;
|
|
8
|
+
/** @internal */
|
|
9
|
+
exports.mobileAppChannel = "mobileApp";
|
|
10
|
+
/** @internal */
|
|
11
|
+
exports.mobileAppNotify = "mobileApp-notify";
|
|
12
|
+
var Orientation;
|
|
13
|
+
(function (Orientation) {
|
|
14
|
+
Orientation[Orientation["Unknown"] = 0] = "Unknown";
|
|
15
|
+
Orientation[Orientation["Portrait"] = 1] = "Portrait";
|
|
16
|
+
Orientation[Orientation["PortraitUpsideDown"] = 2] = "PortraitUpsideDown";
|
|
17
|
+
Orientation[Orientation["LandscapeLeft"] = 4] = "LandscapeLeft";
|
|
18
|
+
Orientation[Orientation["LandscapeRight"] = 8] = "LandscapeRight";
|
|
19
|
+
Orientation[Orientation["FaceUp"] = 16] = "FaceUp";
|
|
20
|
+
Orientation[Orientation["FaceDown"] = 32] = "FaceDown";
|
|
21
|
+
})(Orientation = exports.Orientation || (exports.Orientation = {}));
|
|
22
|
+
var BatteryState;
|
|
23
|
+
(function (BatteryState) {
|
|
24
|
+
BatteryState[BatteryState["Unknown"] = 0] = "Unknown";
|
|
25
|
+
BatteryState[BatteryState["Unplugged"] = 1] = "Unplugged";
|
|
26
|
+
BatteryState[BatteryState["Charging"] = 2] = "Charging";
|
|
27
|
+
BatteryState[BatteryState["Full"] = 3] = "Full";
|
|
28
|
+
})(BatteryState = exports.BatteryState || (exports.BatteryState = {}));
|
|
29
|
+
//# sourceMappingURL=MobileAppProps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileAppProps.js","sourceRoot":"","sources":["../../../src/common/MobileAppProps.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,gBAAgB;AACH,QAAA,gBAAgB,GAAG,WAAW,CAAC;AAC5C,gBAAgB;AACH,QAAA,eAAe,GAAG,kBAAkB,CAAC;AAElD,IAAY,WAQX;AARD,WAAY,WAAW;IACrB,mDAAW,CAAA;IACX,qDAAc,CAAA;IACd,yEAAwB,CAAA;IACxB,+DAAmB,CAAA;IACnB,iEAAoB,CAAA;IACpB,kDAAa,CAAA;IACb,sDAAe,CAAA;AACjB,CAAC,EARW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAQtB;AAED,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,qDAAW,CAAA;IACX,yDAAa,CAAA;IACb,uDAAY,CAAA;IACZ,+CAAQ,CAAA;AACV,CAAC,EALW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAKvB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @internal */\r\nexport const mobileAppChannel = \"mobileApp\";\r\n/** @internal */\r\nexport const mobileAppNotify = \"mobileApp-notify\";\r\n\r\nexport enum Orientation {\r\n Unknown = 0,\r\n Portrait = 0x1,\r\n PortraitUpsideDown = 0x2,\r\n LandscapeLeft = 0x4,\r\n LandscapeRight = 0x8,\r\n FaceUp = 0x10,\r\n FaceDown = 0x20,\r\n}\r\n\r\nexport enum BatteryState {\r\n Unknown = 0,\r\n Unplugged = 1,\r\n Charging = 2,\r\n Full = 3,\r\n}\r\n\r\nexport interface MobileNotifications {\r\n notifyMemoryWarning: () => void;\r\n notifyOrientationChanged: () => void;\r\n notifyEnterForeground: () => void;\r\n notifyEnterBackground: () => void;\r\n notifyWillTerminate: () => void;\r\n}\r\n\r\nexport type DeviceEvents = \"memoryWarning\" | \"orientationChanged\" | \"enterForeground\" | \"enterBackground\" | \"willTerminate\";\r\n\r\n/**\r\n* The methods that may be invoked via Ipc from the frontend of a Mobile App that are implemented on its backend.\r\n* @internal\r\n*/\r\nexport interface MobileAppFunctions {\r\n reconnect: (connection: number) => Promise<void>;\r\n}\r\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module RpcInterface
|
|
3
|
+
*/
|
|
4
|
+
/** @internal */
|
|
5
|
+
export declare class MobileEventLoop {
|
|
6
|
+
private static _activeTasks;
|
|
7
|
+
private static _idleCallback;
|
|
8
|
+
static addTask(): void;
|
|
9
|
+
static removeTask(): void;
|
|
10
|
+
private static _idleHandler;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=MobileEventLoop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileEventLoop.d.ts","sourceRoot":"","sources":["../../../src/common/MobileEventLoop.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,gBAAgB;AAChB,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,YAAY,CAAK;IAChC,OAAO,CAAC,MAAM,CAAC,aAAa,CAA6B;WAE3C,OAAO;WAQP,UAAU;IASxB,OAAO,CAAC,MAAM,CAAC,YAAY;CAC5B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module RpcInterface
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.MobileEventLoop = void 0;
|
|
11
|
+
/** @internal */
|
|
12
|
+
class MobileEventLoop {
|
|
13
|
+
static addTask() {
|
|
14
|
+
++this._activeTasks;
|
|
15
|
+
if (this._idleCallback === null) {
|
|
16
|
+
this._idleCallback = setInterval(() => this._idleHandler());
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
static removeTask() {
|
|
20
|
+
--this._activeTasks;
|
|
21
|
+
if (this._activeTasks === 0 && this._idleCallback !== null) {
|
|
22
|
+
clearInterval(this._idleCallback);
|
|
23
|
+
this._idleCallback = null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
static _idleHandler() { }
|
|
27
|
+
}
|
|
28
|
+
exports.MobileEventLoop = MobileEventLoop;
|
|
29
|
+
MobileEventLoop._activeTasks = 0;
|
|
30
|
+
MobileEventLoop._idleCallback = null;
|
|
31
|
+
//# sourceMappingURL=MobileEventLoop.js.map
|
|
@@ -0,0 +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;YAC/B,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;SAC7D;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;YAC1D,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAClC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;SAC3B;IACH,CAAC;IAEO,MAAM,CAAC,YAAY,KAAK,CAAC;;AArBnC,0CAsBC;AArBgB,4BAAY,GAAG,CAAC,CAAC;AACjB,6BAAa,GAAwB,IAAI,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RpcInterface\r\n */\r\n\r\n/** @internal */\r\nexport class MobileEventLoop {\r\n private static _activeTasks = 0;\r\n private static _idleCallback: NodeJS.Timer | null = null;\r\n\r\n public static addTask() {\r\n ++this._activeTasks;\r\n\r\n if (this._idleCallback === null) {\r\n this._idleCallback = setInterval(() => this._idleHandler());\r\n }\r\n }\r\n\r\n public static removeTask() {\r\n --this._activeTasks;\r\n\r\n if (this._activeTasks === 0 && this._idleCallback !== null) {\r\n clearInterval(this._idleCallback);\r\n this._idleCallback = null;\r\n }\r\n }\r\n\r\n private static _idleHandler() { }\r\n}\r\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module RpcInterface
|
|
3
|
+
*/
|
|
4
|
+
import { IpcWebSocketMessage, IpcWebSocketTransport, RpcRequestFulfillment, SerializedRpcRequest } from "@itwin/core-common";
|
|
5
|
+
import { MobileRpcProtocol } from "./MobileRpcProtocol";
|
|
6
|
+
/** @internal */
|
|
7
|
+
export declare class MobileIpcTransport extends IpcWebSocketTransport {
|
|
8
|
+
private _protocol;
|
|
9
|
+
private _client;
|
|
10
|
+
constructor(protocol: MobileRpcProtocol);
|
|
11
|
+
send(message: IpcWebSocketMessage): void;
|
|
12
|
+
consumeRequest(request: SerializedRpcRequest): boolean;
|
|
13
|
+
consumeResponse(response: RpcRequestFulfillment): boolean;
|
|
14
|
+
private sendToBackend;
|
|
15
|
+
private sendToFrontend;
|
|
16
|
+
private broadcast;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=MobileIpc.d.ts.map
|
|
@@ -0,0 +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;YAOb,cAAc;IAU5B,OAAO,CAAC,SAAS;CAIlB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module RpcInterface
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.MobileIpcTransport = void 0;
|
|
11
|
+
const core_common_1 = require("@itwin/core-common");
|
|
12
|
+
const MobileEventLoop_1 = require("./MobileEventLoop");
|
|
13
|
+
const MobileRpcProtocol_1 = require("./MobileRpcProtocol");
|
|
14
|
+
const MobileRpcRequest_1 = require("./MobileRpcRequest");
|
|
15
|
+
const IPC = "__ipc__";
|
|
16
|
+
class IpcInterface extends core_common_1.RpcInterface {
|
|
17
|
+
async send() { }
|
|
18
|
+
}
|
|
19
|
+
IpcInterface.interfaceName = IPC;
|
|
20
|
+
IpcInterface.interfaceVersion = "0.0.0";
|
|
21
|
+
/** @internal */
|
|
22
|
+
class MobileIpcTransport extends core_common_1.IpcWebSocketTransport {
|
|
23
|
+
constructor(protocol) {
|
|
24
|
+
super();
|
|
25
|
+
this._protocol = protocol;
|
|
26
|
+
core_common_1.RpcManager.initializeInterface(IpcInterface);
|
|
27
|
+
this._client = core_common_1.RpcManager.getClientForInterface(IpcInterface);
|
|
28
|
+
}
|
|
29
|
+
send(message) {
|
|
30
|
+
if (message.type === core_common_1.IpcWebSocketMessageType.Send || message.type === core_common_1.IpcWebSocketMessageType.Invoke) {
|
|
31
|
+
this.sendToBackend(message); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
32
|
+
}
|
|
33
|
+
else if (message.type === core_common_1.IpcWebSocketMessageType.Push || message.type === core_common_1.IpcWebSocketMessageType.Response) {
|
|
34
|
+
this.sendToFrontend(message); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
consumeRequest(request) {
|
|
38
|
+
if (request.operation.interfaceDefinition !== IPC)
|
|
39
|
+
return false;
|
|
40
|
+
const message = core_common_1.RpcMarshaling.deserialize(this._protocol, request.parameters)[0];
|
|
41
|
+
this.broadcast({}, message);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
consumeResponse(response) {
|
|
45
|
+
if (response.interfaceName !== IPC)
|
|
46
|
+
return false;
|
|
47
|
+
const message = core_common_1.RpcMarshaling.deserialize(this._protocol, response.result);
|
|
48
|
+
this.broadcast({}, message);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
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();
|
|
56
|
+
}
|
|
57
|
+
async sendToFrontend(message) {
|
|
58
|
+
MobileEventLoop_1.MobileEventLoop.addTask();
|
|
59
|
+
const result = await core_common_1.RpcMarshaling.serialize(this._protocol, message);
|
|
60
|
+
MobileEventLoop_1.MobileEventLoop.removeTask();
|
|
61
|
+
const fulfillment = { result, rawResult: message, interfaceName: IPC, id: message.channel, status: 0 };
|
|
62
|
+
const encoded = MobileRpcProtocol_1.MobileRpcProtocol.encodeResponse(fulfillment);
|
|
63
|
+
this._protocol.sendToFrontend(encoded);
|
|
64
|
+
}
|
|
65
|
+
broadcast(evt, message) {
|
|
66
|
+
for (const listener of core_common_1.IpcWebSocket.receivers)
|
|
67
|
+
listener(evt, message);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.MobileIpcTransport = MobileIpcTransport;
|
|
71
|
+
//# sourceMappingURL=MobileIpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileIpc.js","sourceRoot":"","sources":["../../../src/common/MobileIpc.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,oDAG4B;AAC5B,uDAAoD;AACpD,2DAAwD;AACxD,yDAAsD;AAEtD,MAAM,GAAG,GAAG,SAAS,CAAC;AAEtB,MAAM,YAAa,SAAQ,0BAAY;IAG9B,KAAK,CAAC,IAAI,KAAK,CAAC;;AAFT,0BAAa,GAAG,GAAG,CAAC;AACpB,6BAAgB,GAAG,OAAO,CAAC;AAI3C,gBAAgB;AAChB,MAAa,kBAAmB,SAAQ,mCAAqB;IAI3D,YAAmB,QAA2B;QAC5C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAE1B,wBAAU,CAAC,mBAAmB,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AO,EAAE,MAAM,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;QACtE,MAAM,OAAO,GAAG,MAAM,qCAAiB,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC/D,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACtC,OAAO,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;IAEO,KAAK,CAAC,cAAc,CAAC,OAA4B;QACvD,iCAAe,CAAC,OAAO,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,MAAM,2BAAa,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QACtE,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;AA3DD,gDA2DC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RpcInterface\r\n */\r\n\r\nimport {\r\n IpcWebSocket, IpcWebSocketMessage, IpcWebSocketMessageType, IpcWebSocketTransport, RpcInterface, RpcManager, RpcMarshaling, RpcRequestFulfillment,\r\n SerializedRpcRequest,\r\n} from \"@itwin/core-common\";\r\nimport { MobileEventLoop } from \"./MobileEventLoop\";\r\nimport { MobileRpcProtocol } from \"./MobileRpcProtocol\";\r\nimport { MobileRpcRequest } from \"./MobileRpcRequest\";\r\n\r\nconst IPC = \"__ipc__\";\r\n\r\nclass IpcInterface extends RpcInterface {\r\n public static interfaceName = IPC;\r\n public static interfaceVersion = \"0.0.0\";\r\n public async send() { }\r\n}\r\n\r\n/** @internal */\r\nexport class MobileIpcTransport extends IpcWebSocketTransport {\r\n private _protocol: MobileRpcProtocol;\r\n private _client: IpcInterface;\r\n\r\n public constructor(protocol: MobileRpcProtocol) {\r\n super();\r\n this._protocol = protocol;\r\n\r\n RpcManager.initializeInterface(IpcInterface);\r\n this._client = RpcManager.getClientForInterface(IpcInterface);\r\n }\r\n\r\n public send(message: IpcWebSocketMessage): void {\r\n if (message.type === IpcWebSocketMessageType.Send || message.type === IpcWebSocketMessageType.Invoke) {\r\n this.sendToBackend(message); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n } else if (message.type === IpcWebSocketMessageType.Push || message.type === IpcWebSocketMessageType.Response) {\r\n this.sendToFrontend(message); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n }\r\n\r\n public consumeRequest(request: SerializedRpcRequest): boolean {\r\n if (request.operation.interfaceDefinition !== IPC)\r\n return false;\r\n\r\n const message = RpcMarshaling.deserialize(this._protocol, request.parameters)[0] as IpcWebSocketMessage;\r\n this.broadcast({} as Event, message);\r\n return true;\r\n }\r\n\r\n public consumeResponse(response: RpcRequestFulfillment): boolean {\r\n if (response.interfaceName !== IPC)\r\n return false;\r\n\r\n const message = RpcMarshaling.deserialize(this._protocol, response.result) as IpcWebSocketMessage;\r\n this.broadcast({} as Event, message);\r\n return true;\r\n }\r\n\r\n private async sendToBackend(message: IpcWebSocketMessage) {\r\n const request = new MobileRpcRequest(this._client, \"send\", [message]);\r\n const encoded = await MobileRpcProtocol.encodeRequest(request);\r\n this._protocol.sendToBackend(encoded);\r\n request.dispose();\r\n }\r\n\r\n private async sendToFrontend(message: IpcWebSocketMessage) {\r\n MobileEventLoop.addTask();\r\n const result = await RpcMarshaling.serialize(this._protocol, message);\r\n MobileEventLoop.removeTask();\r\n\r\n const fulfillment: RpcRequestFulfillment = { result, rawResult: message, interfaceName: IPC, id: message.channel, status: 0 };\r\n const encoded = MobileRpcProtocol.encodeResponse(fulfillment);\r\n this._protocol.sendToFrontend(encoded);\r\n }\r\n\r\n private broadcast(evt: Event, message: IpcWebSocketMessage) {\r\n for (const listener of IpcWebSocket.receivers)\r\n listener(evt, message);\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module RpcInterface
|
|
3
|
+
*/
|
|
4
|
+
import { RpcPushChannel, RpcPushConnection, RpcPushTransport, RpcRequestFulfillment } from "@itwin/core-common";
|
|
5
|
+
import { MobileRpcProtocol } from "./MobileRpcProtocol";
|
|
6
|
+
/** @internal */
|
|
7
|
+
export declare class MobilePushTransport extends RpcPushTransport {
|
|
8
|
+
private _protocol;
|
|
9
|
+
private _last;
|
|
10
|
+
get last(): number;
|
|
11
|
+
constructor(protocol: MobileRpcProtocol);
|
|
12
|
+
consume(response: RpcRequestFulfillment): boolean;
|
|
13
|
+
}
|
|
14
|
+
/** @internal */
|
|
15
|
+
export declare class MobilePushConnection<T> extends RpcPushConnection<T> {
|
|
16
|
+
private _protocol;
|
|
17
|
+
private _next;
|
|
18
|
+
constructor(channel: RpcPushChannel<T>, client: unknown, protocol: MobileRpcProtocol);
|
|
19
|
+
send(messageData: any): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=MobilePush.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobilePush.d.ts","sourceRoot":"","sources":["../../../src/common/MobilePush.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAiB,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE/H,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIxD,gBAAgB;AAChB,qBAAa,mBAAoB,SAAQ,gBAAgB;IACvD,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,KAAK,CAAc;IAE3B,IAAW,IAAI,WAAyB;gBAErB,QAAQ,EAAE,iBAAiB;IAKvC,OAAO,CAAC,QAAQ,EAAE,qBAAqB,GAAG,OAAO;CAczD;AAED,gBAAgB;AAChB,qBAAa,oBAAoB,CAAC,CAAC,CAAE,SAAQ,iBAAiB,CAAC,CAAC,CAAC;IAC/D,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,KAAK,CAAc;gBAER,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,iBAAiB;IAK9E,IAAI,CAAC,WAAW,EAAE,GAAG;CASnC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module RpcInterface
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.MobilePushConnection = exports.MobilePushTransport = void 0;
|
|
11
|
+
const core_common_1 = require("@itwin/core-common");
|
|
12
|
+
const MobileEventLoop_1 = require("./MobileEventLoop");
|
|
13
|
+
const MobileRpcProtocol_1 = require("./MobileRpcProtocol");
|
|
14
|
+
const PUSH = "__push__";
|
|
15
|
+
/** @internal */
|
|
16
|
+
class MobilePushTransport extends core_common_1.RpcPushTransport {
|
|
17
|
+
constructor(protocol) {
|
|
18
|
+
super();
|
|
19
|
+
this._last = -1;
|
|
20
|
+
this._protocol = protocol;
|
|
21
|
+
}
|
|
22
|
+
get last() { return this._last; }
|
|
23
|
+
consume(response) {
|
|
24
|
+
if (response.interfaceName !== PUSH) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
this._last = response.status;
|
|
28
|
+
if (this.onMessage) {
|
|
29
|
+
const messageData = core_common_1.RpcMarshaling.deserialize(this._protocol, response.result);
|
|
30
|
+
this.onMessage(response.id, messageData);
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.MobilePushTransport = MobilePushTransport;
|
|
36
|
+
/** @internal */
|
|
37
|
+
class MobilePushConnection extends core_common_1.RpcPushConnection {
|
|
38
|
+
constructor(channel, client, protocol) {
|
|
39
|
+
super(channel, client);
|
|
40
|
+
this._next = -1;
|
|
41
|
+
this._protocol = protocol;
|
|
42
|
+
}
|
|
43
|
+
async send(messageData) {
|
|
44
|
+
MobileEventLoop_1.MobileEventLoop.addTask();
|
|
45
|
+
const result = await core_common_1.RpcMarshaling.serialize(this._protocol, messageData);
|
|
46
|
+
MobileEventLoop_1.MobileEventLoop.removeTask();
|
|
47
|
+
const fulfillment = { result, rawResult: messageData, interfaceName: PUSH, id: this.channel.id, status: ++this._next };
|
|
48
|
+
const encoded = MobileRpcProtocol_1.MobileRpcProtocol.encodeResponse(fulfillment);
|
|
49
|
+
this._protocol.sendToFrontend(encoded);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.MobilePushConnection = MobilePushConnection;
|
|
53
|
+
//# sourceMappingURL=MobilePush.js.map
|
|
@@ -0,0 +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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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":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module RpcInterface\r\n */\r\n\r\nimport { RpcMarshaling, RpcPushChannel, RpcPushConnection, RpcPushTransport, RpcRequestFulfillment } from \"@itwin/core-common\";\r\nimport { MobileEventLoop } from \"./MobileEventLoop\";\r\nimport { MobileRpcProtocol } from \"./MobileRpcProtocol\";\r\n\r\nconst PUSH = \"__push__\";\r\n\r\n/** @internal */\r\nexport class MobilePushTransport extends RpcPushTransport {\r\n private _protocol: MobileRpcProtocol;\r\n private _last: number = -1;\r\n\r\n public get last() { return this._last; }\r\n\r\n public constructor(protocol: MobileRpcProtocol) {\r\n super();\r\n this._protocol = protocol;\r\n }\r\n\r\n public consume(response: RpcRequestFulfillment): boolean {\r\n if (response.interfaceName !== PUSH) {\r\n return false;\r\n }\r\n\r\n this._last = response.status;\r\n\r\n if (this.onMessage) {\r\n const messageData = RpcMarshaling.deserialize(this._protocol, response.result);\r\n this.onMessage(response.id, messageData);\r\n }\r\n\r\n return true;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class MobilePushConnection<T> extends RpcPushConnection<T> {\r\n private _protocol: MobileRpcProtocol;\r\n private _next: number = -1;\r\n\r\n public constructor(channel: RpcPushChannel<T>, client: unknown, protocol: MobileRpcProtocol) {\r\n super(channel, client);\r\n this._protocol = protocol;\r\n }\r\n\r\n public async send(messageData: any) {\r\n MobileEventLoop.addTask();\r\n const result = await RpcMarshaling.serialize(this._protocol, messageData);\r\n MobileEventLoop.removeTask();\r\n\r\n const fulfillment: RpcRequestFulfillment = { result, rawResult: messageData, interfaceName: PUSH, id: this.channel.id, status: ++this._next };\r\n const encoded = MobileRpcProtocol.encodeResponse(fulfillment);\r\n this._protocol.sendToFrontend(encoded);\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RpcConfiguration, RpcInterfaceDefinition } from "@itwin/core-common";
|
|
2
|
+
import { MobileRpcProtocol } from "./MobileRpcProtocol";
|
|
3
|
+
/** RPC supported mobile platforms.
|
|
4
|
+
* @beta
|
|
5
|
+
*/
|
|
6
|
+
export declare enum RpcMobilePlatform {
|
|
7
|
+
Unknown = 0,
|
|
8
|
+
Android = 1,
|
|
9
|
+
iOS = 2
|
|
10
|
+
}
|
|
11
|
+
/** Holds configuration for the RpcInterfaces used by the application.
|
|
12
|
+
* @beta
|
|
13
|
+
*/
|
|
14
|
+
export declare abstract class MobileRpcConfiguration extends RpcConfiguration {
|
|
15
|
+
/** @internal */
|
|
16
|
+
static setup: {
|
|
17
|
+
obtainPort: () => number;
|
|
18
|
+
checkPlatform: () => boolean;
|
|
19
|
+
};
|
|
20
|
+
abstract protocol: MobileRpcProtocol;
|
|
21
|
+
private static _args;
|
|
22
|
+
private static getArgs;
|
|
23
|
+
private static getMobilePlatform;
|
|
24
|
+
/** Read the mobile rpc args */
|
|
25
|
+
static get args(): any;
|
|
26
|
+
/** Return type of mobile platform using browser userAgent */
|
|
27
|
+
static get platform(): RpcMobilePlatform;
|
|
28
|
+
}
|
|
29
|
+
/** Coordinates usage of RPC interfaces for an Mobile-based application.
|
|
30
|
+
* @beta
|
|
31
|
+
*/
|
|
32
|
+
export declare class MobileRpcManager {
|
|
33
|
+
/** @internal */
|
|
34
|
+
static ready(): Promise<void>;
|
|
35
|
+
private static performInitialization;
|
|
36
|
+
/** Initializes MobileRpcManager for the frontend of an application. */
|
|
37
|
+
static initializeClient(interfaces: RpcInterfaceDefinition[]): MobileRpcConfiguration;
|
|
38
|
+
/** Initializes MobileRpcManager for the backend of an application. */
|
|
39
|
+
static initializeImpl(interfaces: RpcInterfaceDefinition[]): MobileRpcConfiguration;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=MobileRpcManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileRpcManager.d.ts","sourceRoot":"","sources":["../../../src/common/MobileRpcManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAe,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;GAEG;AACH,oBAAY,iBAAiB;IAC3B,OAAO,IAAA;IACP,OAAO,IAAA;IACP,GAAG,IAAA;CACJ;AAED;;GAEG;AACH,8BAAsB,sBAAuB,SAAQ,gBAAgB;IACnE,gBAAgB;IAChB,OAAc,KAAK;;;MAGjB;IAEF,SAAyB,QAAQ,EAAE,iBAAiB,CAAC;IACrD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAM;IAC1B,OAAO,CAAC,MAAM,CAAC,OAAO;IAoBtB,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAehC,+BAA+B;IAC/B,WAAkB,IAAI,IAAI,GAAG,CAK5B;IAED,6DAA6D;IAC7D,WAAkB,QAAQ,IAAI,iBAAiB,CAAuD;CACvG;AAED;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,gBAAgB;WACI,KAAK;IAUzB,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAgBpC,uEAAuE;WACzD,gBAAgB,CAAC,UAAU,EAAE,sBAAsB,EAAE,GAAG,sBAAsB;IAG5F,sEAAsE;WACxD,cAAc,CAAC,UAAU,EAAE,sBAAsB,EAAE,GAAG,sBAAsB;CAG3F"}
|