@itwin/core-mobile 5.0.0-dev.9 → 5.0.0-dev.90

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 (37) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/lib/cjs/MobileBackend.js.map +1 -1
  3. package/lib/cjs/MobileFrontend.js.map +1 -1
  4. package/lib/cjs/__DOC_ONLY__.js.map +1 -1
  5. package/lib/cjs/backend/MobileAuthorizationBackend.js +4 -5
  6. package/lib/cjs/backend/MobileAuthorizationBackend.js.map +1 -1
  7. package/lib/cjs/backend/MobileFileHandler.js +2 -0
  8. package/lib/cjs/backend/MobileFileHandler.js.map +1 -1
  9. package/lib/cjs/backend/MobileHost.js +34 -33
  10. package/lib/cjs/backend/MobileHost.js.map +1 -1
  11. package/lib/cjs/backend/MobileRpcServer.d.ts +1 -1
  12. package/lib/cjs/backend/MobileRpcServer.d.ts.map +1 -1
  13. package/lib/cjs/backend/MobileRpcServer.js +18 -12
  14. package/lib/cjs/backend/MobileRpcServer.js.map +1 -1
  15. package/lib/cjs/backend/Request.js +3 -0
  16. package/lib/cjs/backend/Request.js.map +1 -1
  17. package/lib/cjs/common/MobileAppChannel.js.map +1 -1
  18. package/lib/cjs/common/MobileAppProps.js.map +1 -1
  19. package/lib/cjs/common/MobileEventLoop.js +2 -2
  20. package/lib/cjs/common/MobileEventLoop.js.map +1 -1
  21. package/lib/cjs/common/MobileIpc.d.ts.map +1 -1
  22. package/lib/cjs/common/MobileIpc.js +69 -6
  23. package/lib/cjs/common/MobileIpc.js.map +1 -1
  24. package/lib/cjs/common/MobilePush.js +4 -2
  25. package/lib/cjs/common/MobilePush.js.map +1 -1
  26. package/lib/cjs/common/MobileRpcManager.js +8 -10
  27. package/lib/cjs/common/MobileRpcManager.js.map +1 -1
  28. package/lib/cjs/common/MobileRpcProtocol.js +13 -11
  29. package/lib/cjs/common/MobileRpcProtocol.js.map +1 -1
  30. package/lib/cjs/common/MobileRpcRequest.js +4 -7
  31. package/lib/cjs/common/MobileRpcRequest.js.map +1 -1
  32. package/lib/cjs/frontend/MobileApp.js +7 -7
  33. package/lib/cjs/frontend/MobileApp.js.map +1 -1
  34. package/lib/cjs/frontend/MobileAuthorizationFrontend.js +4 -5
  35. package/lib/cjs/frontend/MobileAuthorizationFrontend.js.map +1 -1
  36. package/lib/cjs/test/ios/MobilePlatform.test.js.map +1 -1
  37. package/package.json +14 -14
@@ -1 +1 @@
1
- {"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../src/backend/Request.ts"],"names":[],"mappings":";;;AA6MA,0BAmIC;AAOD,0BAOC;AA9VD;;;+FAG+F;AAC/F;;GAEG;AACH,4BAA4B;AAE5B,wCAAwC;AACxC,sDAAsG;AAEtG,MAAM,cAAc,GAAW,6BAA6B,CAAC;AAE7D,gBAAgB;AACH,QAAA,mBAAmB,GAAG,kBAAkB,CAAC;AAoEtD;;GAEG;AACH,MAAa,aAAc,SAAQ,2BAAY;IAI7C,YAAmB,WAAgC,EAAE,OAAgB,EAAE,WAAiC;QACtG,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,QAAa,EAAE,GAAG,GAAG,IAAI;QAC3C,MAAM,KAAK,GAAG,IAAI,aAAa,CAAC,aAAa,CAAC,eAAe,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;QACpF,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,KAAK,CAAC,OAAO,GAAG,+BAA+B,CAAC;YAChD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACtB,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;gBAC5B,KAAK,CAAC,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC;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pB,EAAE,CAAC,OAAO,EAAE,CAAC,KAAU,EAAE,EAAE;gBAC1B,MAAM,WAAW,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;gBACzC,MAAM,CAAC,WAAW,CAAC,CAAC;YACtB,CAAC,CAAC;iBACD,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;gBACjB,MAAM,WAAW,GAAa;oBAC5B,MAAM,EAAE,GAAG;oBACX,MAAM,EAAE,SAAS;oBACjB,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,SAAS;iBAChB,CAAC;gBACF,OAAO,CAAC,WAAW,CAAC,CAAC;YACvB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACL,CAAC;IAED,0DAA0D;IAE1D;;;;;;MAME;IACF,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC;QAC7B,MAAM,WAAW,GAAa;YAC5B,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;SACxB,CAAC;QACF,OAAO,WAAW,CAAC;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,WAAW,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QACzC,MAAM,WAAW,CAAC;IACpB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,OAAO,CAAC,GAAW;IACvC,MAAM,OAAO,GAAmB;QAC9B,MAAM,EAAE,KAAK;QACb,YAAY,EAAE,MAAM;KACrB,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC,IAAI,CAAC;AACnB,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 iTwinServiceClients\r\n */\r\nimport * as _ from \"lodash\";\r\nimport * as https from \"https\";\r\nimport * as sarequest from \"superagent\";\r\nimport { BentleyError, GetMetaDataFunction, HttpStatus, Logger, LogLevel } from \"@itwin/core-bentley\";\r\n\r\nconst loggerCategory: string = \"core-mobile-backend.Request\";\r\n\r\n/** @internal */\r\nexport const requestIdHeaderName = \"X-Correlation-Id\";\r\n\r\n/** @internal */\r\nexport interface RequestQueryStringifyOptions {\r\n delimiter?: string;\r\n encode?: boolean;\r\n}\r\n\r\n/** Option to control the time outs\r\n * Use a short response timeout to detect unresponsive networks quickly, and a long deadline to give time for downloads on slow,\r\n * but reliable, networks. Note that both of these timers limit how long uploads of attached files are allowed to take. Use long\r\n * timeouts if you're uploading files.\r\n * @internal\r\n */\r\nexport interface RequestTimeoutOptions {\r\n /** Sets a deadline (in milliseconds) for the entire request (including all uploads, redirects, server processing time) to complete.\r\n * If the response isn't fully downloaded within that time, the request will be aborted\r\n */\r\n deadline?: number;\r\n\r\n /** Sets maximum time (in milliseconds) to wait for the first byte to arrive from the server, but it does not limit how long the entire\r\n * download can take. Response timeout should be at least few seconds longer than just the time it takes the server to respond, because\r\n * it also includes time to make DNS lookup, TCP/IP and TLS connections, and time to upload request data.\r\n */\r\n response?: number;\r\n}\r\n\r\n/** @internal */\r\nexport interface RequestOptions {\r\n method: string;\r\n headers?: any; // {Mas-App-Guid, Mas-UUid, User-Agent}\r\n body?: any;\r\n responseType?: string;\r\n timeout?: RequestTimeoutOptions; // Optional timeouts. If unspecified, an arbitrary default is setup.\r\n stream?: any; // Optional stream to read the response to/from (only for NodeJs applications)\r\n readStream?: any; // Optional stream to read input from (only for NodeJs applications)\r\n buffer?: any;\r\n parser?: any;\r\n accept?: string;\r\n redirects?: number;\r\n errorCallback?: (response: any) => ResponseError;\r\n retryCallback?: (error: any, response: any) => boolean;\r\n progressCallback?: ProgressCallback;\r\n agent?: https.Agent;\r\n retries?: number;\r\n useCorsProxy?: boolean;\r\n}\r\n\r\n/** Response object if the request was successful. Note that the status within the range of 200-299 are considered as a success.\r\n * @internal\r\n */\r\nexport interface Response {\r\n body: any; // Parsed body of response\r\n text: string | undefined; // Returned for responseType:text\r\n header: any; // Parsed headers of response\r\n status: number; // Status code of response\r\n}\r\n\r\n/** @internal */\r\nexport interface ProgressInfo {\r\n percent?: number;\r\n total?: number;\r\n loaded: number;\r\n}\r\n\r\n/** @internal */\r\nexport type ProgressCallback = (progress: ProgressInfo) => void;\r\n\r\n/** Error object that's thrown/rejected if the Request fails due to a network error, or if the status is *not* in the range of 200-299 (inclusive)\r\n * @internal\r\n */\r\nexport class ResponseError extends BentleyError {\r\n protected _data?: any;\r\n public status?: number;\r\n public description?: string;\r\n public constructor(errorNumber: number | HttpStatus, message?: string, getMetaData?: GetMetaDataFunction) {\r\n super(errorNumber, message, getMetaData);\r\n }\r\n\r\n /**\r\n * Parses error from server's response\r\n * @param response Http response from the server.\r\n * @returns Parsed error.\r\n * @internal\r\n */\r\n public static parse(response: any, log = true): ResponseError {\r\n const error = new ResponseError(ResponseError.parseHttpStatus(response.statusType));\r\n if (!response) {\r\n error.message = \"Couldn't get response object.\";\r\n return error;\r\n }\r\n\r\n if (response.response) {\r\n if (response.response.error) {\r\n error.name = response.response.error.name || error.name;\r\n error.description = response.response.error.message;\r\n }\r\n if (response.response.res) {\r\n error.message = response.response.res.statusMessage;\r\n }\r\n if (response.response.body && Object.keys(response.response.body).length > 0) {\r\n error._data = {};\r\n _.merge(error._data, response.response.body);\r\n } else {\r\n error._data = response.response.text;\r\n }\r\n }\r\n\r\n error.status = response.status || response.statusCode;\r\n error.name = response.code || response.name || error.name;\r\n error.message = error.message || response.message || response.statusMessage;\r\n\r\n if (log)\r\n error.log();\r\n\r\n return error;\r\n }\r\n\r\n /**\r\n * Decides whether request should be retried or not\r\n * @param error Error returned by request\r\n * @param response Response returned by request\r\n * @internal\r\n */\r\n public static shouldRetry(error: any, response: any): boolean {\r\n if (error !== undefined && error !== null) {\r\n if ((error.status === undefined || error.status === null) && (error.res === undefined || error.res === null)) {\r\n return true;\r\n }\r\n }\r\n return (response !== undefined && response.statusType === HttpStatus.ServerError);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static parseHttpStatus(statusType: number): HttpStatus {\r\n switch (statusType) {\r\n case 1:\r\n return HttpStatus.Info;\r\n case 2:\r\n return HttpStatus.Success;\r\n case 3:\r\n return HttpStatus.Redirection;\r\n case 4:\r\n return HttpStatus.ClientError;\r\n case 5:\r\n return HttpStatus.ServerError;\r\n default:\r\n return HttpStatus.Success;\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public logMessage(): string {\r\n return `${this.status} ${this.name}: ${this.message}`;\r\n }\r\n\r\n /**\r\n * Logs this error\r\n * @internal\r\n */\r\n public log(): void {\r\n Logger.logError(loggerCategory, this.logMessage(), () => this.getMetaData());\r\n }\r\n}\r\n\r\nconst logResponse = (req: sarequest.SuperAgentRequest, startTime: number) => (res: sarequest.Response) => {\r\n const elapsed = new Date().getTime() - startTime;\r\n const elapsedTime = `${elapsed}ms`;\r\n Logger.logTrace(loggerCategory, `${req.method.toUpperCase()} ${res.status} ${req.url} (${elapsedTime})`);\r\n};\r\n\r\nconst logRequest = (req: sarequest.SuperAgentRequest): sarequest.SuperAgentRequest => {\r\n const startTime = new Date().getTime();\r\n return req.on(\"response\", logResponse(req, startTime));\r\n};\r\n\r\n/** Wrapper around making HTTP requests with the specific options.\r\n *\r\n * Usable in both a browser and node based environment.\r\n *\r\n * @param url Server URL to address the request\r\n * @param options Options to pass to the request\r\n * @returns Resolves to the response from the server\r\n * @throws ResponseError if the request fails due to network issues, or if the returned status is *outside* the range of 200-299 (inclusive)\r\n * @internal\r\n */\r\nexport async function request(url: string, options: RequestOptions): Promise<Response> {\r\n let sareq: sarequest.SuperAgentRequest = sarequest(options.method, url);\r\n if (options.retries)\r\n sareq = sareq.retry(options.retries, options.retryCallback);\r\n\r\n if (Logger.isEnabled(loggerCategory, LogLevel.Trace))\r\n sareq = sareq.use(logRequest);\r\n\r\n if (options.headers)\r\n sareq = sareq.set(options.headers);\r\n\r\n Logger.logInfo(loggerCategory, url);\r\n\r\n if (options.accept)\r\n sareq = sareq.accept(options.accept);\r\n\r\n if (options.body)\r\n sareq = sareq.send(options.body);\r\n\r\n if (options.timeout)\r\n sareq = sareq.timeout(options.timeout);\r\n\r\n if (options.responseType)\r\n sareq = sareq.responseType(options.responseType);\r\n\r\n if (options.redirects)\r\n sareq = sareq.redirects(options.redirects);\r\n else\r\n sareq = sareq.redirects(0);\r\n\r\n if (options.buffer)\r\n sareq = sareq.buffer(options.buffer);\r\n\r\n if (options.parser)\r\n sareq = sareq.parse(options.parser);\r\n\r\n /** Default to any globally supplied proxy, unless an agent is specified in this call */\r\n if (options.agent)\r\n sareq = sareq.agent(options.agent);\r\n\r\n if (options.progressCallback) {\r\n sareq = sareq.on(\"progress\", (event: sarequest.ProgressEvent) => {\r\n if (event) {\r\n options.progressCallback!({\r\n loaded: event.loaded,\r\n total: event.total,\r\n percent: event.percent,\r\n });\r\n }\r\n });\r\n }\r\n\r\n const errorCallback = options.errorCallback ? options.errorCallback : (response: any) => ResponseError.parse(response);\r\n\r\n if (options.readStream) {\r\n if (typeof window !== \"undefined\")\r\n throw new Error(\"This option is not supported on browsers\");\r\n\r\n return new Promise<Response>((resolve, reject) => {\r\n sareq = sareq.type(\"blob\");\r\n options\r\n .readStream\r\n .pipe(sareq)\r\n .on(\"error\", (error: any) => {\r\n const parsedError = errorCallback(error);\r\n reject(parsedError);\r\n })\r\n .on(\"end\", () => {\r\n const retResponse: Response = {\r\n status: 201,\r\n header: undefined,\r\n body: undefined,\r\n text: undefined,\r\n };\r\n resolve(retResponse);\r\n });\r\n });\r\n }\r\n\r\n if (options.stream) {\r\n if (typeof window !== \"undefined\")\r\n throw new Error(\"This option is not supported on browsers\");\r\n\r\n return new Promise<Response>((resolve, reject) => {\r\n sareq\r\n .on(\"response\", (res: any) => {\r\n if (res.statusCode !== 200) {\r\n const parsedError = errorCallback(res);\r\n reject(parsedError);\r\n return;\r\n }\r\n })\r\n .pipe(options.stream)\r\n .on(\"error\", (error: any) => {\r\n const parsedError = errorCallback(error);\r\n reject(parsedError);\r\n })\r\n .on(\"finish\", () => {\r\n const retResponse: Response = {\r\n status: 200,\r\n header: undefined,\r\n body: undefined,\r\n text: undefined,\r\n };\r\n resolve(retResponse);\r\n });\r\n });\r\n }\r\n\r\n // console.log(\"%s %s %s\", url, options.method, queryStr);\r\n\r\n /**\r\n * Note:\r\n * Javascript's fetch returns status.OK if error is between 200-299 inclusive, and doesn't reject in this case.\r\n * Fetch only rejects if there's some network issue (permissions issue or similar)\r\n * Superagent rejects network issues, and errors outside the range of 200-299. We are currently using\r\n * superagent, but may eventually switch to JavaScript's fetch library.\r\n */\r\n try {\r\n const response = await sareq;\r\n const retResponse: Response = {\r\n body: response.body,\r\n text: response.text,\r\n header: response.header,\r\n status: response.status,\r\n };\r\n return retResponse;\r\n } catch (error) {\r\n const parsedError = errorCallback(error);\r\n throw parsedError;\r\n }\r\n}\r\n\r\n/**\r\n * fetch json from HTTP request\r\n * @param url server URL to address the request\r\n * @internal\r\n */\r\nexport async function getJson(url: string): Promise<any> {\r\n const options: RequestOptions = {\r\n method: \"GET\",\r\n responseType: \"json\",\r\n };\r\n const data = await request(url, options);\r\n return data.body;\r\n}\r\n"]}
1
+ {"version":3,"file":"Request.js","sourceRoot":"","sources":["../../../src/backend/Request.ts"],"names":[],"mappings":";;;AA6MA,0BAmIC;AAOD,0BAOC;AA9VD;;;+FAG+F;AAC/F;;GAEG;AACH,4BAA4B;AAE5B,wCAAwC;AACxC,sDAAsG;AAEtG,MAAM,cAAc,GAAW,6BAA6B,CAAC;AAE7D,gBAAgB;AACH,QAAA,mBAAmB,GAAG,kBAAkB,CAAC;AAoEtD;;GAEG;AACH,MAAa,aAAc,SAAQ,2BAAY;IACnC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,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;SACxB,CAAC;QACF,OAAO,WAAW,CAAC;IACrB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,WAAW,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;QACzC,MAAM,WAAW,CAAC;IACpB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,OAAO,CAAC,GAAW;IACvC,MAAM,OAAO,GAAmB;QAC9B,MAAM,EAAE,KAAK;QACb,YAAY,EAAE,MAAM;KACrB,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC,IAAI,CAAC;AACnB,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 iTwinServiceClients\n */\nimport * as _ from \"lodash\";\nimport * as https from \"https\";\nimport * as sarequest from \"superagent\";\nimport { BentleyError, GetMetaDataFunction, HttpStatus, Logger, LogLevel } from \"@itwin/core-bentley\";\n\nconst loggerCategory: string = \"core-mobile-backend.Request\";\n\n/** @internal */\nexport const requestIdHeaderName = \"X-Correlation-Id\";\n\n/** @internal */\nexport interface RequestQueryStringifyOptions {\n delimiter?: string;\n encode?: boolean;\n}\n\n/** Option to control the time outs\n * Use a short response timeout to detect unresponsive networks quickly, and a long deadline to give time for downloads on slow,\n * but reliable, networks. Note that both of these timers limit how long uploads of attached files are allowed to take. Use long\n * timeouts if you're uploading files.\n * @internal\n */\nexport interface RequestTimeoutOptions {\n /** Sets a deadline (in milliseconds) for the entire request (including all uploads, redirects, server processing time) to complete.\n * If the response isn't fully downloaded within that time, the request will be aborted\n */\n deadline?: number;\n\n /** Sets maximum time (in milliseconds) to wait for the first byte to arrive from the server, but it does not limit how long the entire\n * download can take. Response timeout should be at least few seconds longer than just the time it takes the server to respond, because\n * it also includes time to make DNS lookup, TCP/IP and TLS connections, and time to upload request data.\n */\n response?: number;\n}\n\n/** @internal */\nexport interface RequestOptions {\n method: string;\n headers?: any; // {Mas-App-Guid, Mas-UUid, User-Agent}\n body?: any;\n responseType?: string;\n timeout?: RequestTimeoutOptions; // Optional timeouts. If unspecified, an arbitrary default is setup.\n stream?: any; // Optional stream to read the response to/from (only for NodeJs applications)\n readStream?: any; // Optional stream to read input from (only for NodeJs applications)\n buffer?: any;\n parser?: any;\n accept?: string;\n redirects?: number;\n errorCallback?: (response: any) => ResponseError;\n retryCallback?: (error: any, response: any) => boolean;\n progressCallback?: ProgressCallback;\n agent?: https.Agent;\n retries?: number;\n useCorsProxy?: boolean;\n}\n\n/** Response object if the request was successful. Note that the status within the range of 200-299 are considered as a success.\n * @internal\n */\nexport interface Response {\n body: any; // Parsed body of response\n text: string | undefined; // Returned for responseType:text\n header: any; // Parsed headers of response\n status: number; // Status code of response\n}\n\n/** @internal */\nexport interface ProgressInfo {\n percent?: number;\n total?: number;\n loaded: number;\n}\n\n/** @internal */\nexport type ProgressCallback = (progress: ProgressInfo) => void;\n\n/** Error object that's thrown/rejected if the Request fails due to a network error, or if the status is *not* in the range of 200-299 (inclusive)\n * @internal\n */\nexport class ResponseError extends BentleyError {\n protected _data?: any;\n public status?: number;\n public description?: string;\n public constructor(errorNumber: number | HttpStatus, message?: string, getMetaData?: GetMetaDataFunction) {\n super(errorNumber, message, getMetaData);\n }\n\n /**\n * Parses error from server's response\n * @param response Http response from the server.\n * @returns Parsed error.\n * @internal\n */\n public static parse(response: any, log = true): ResponseError {\n const error = new ResponseError(ResponseError.parseHttpStatus(response.statusType));\n if (!response) {\n error.message = \"Couldn't get response object.\";\n return error;\n }\n\n if (response.response) {\n if (response.response.error) {\n error.name = response.response.error.name || error.name;\n error.description = response.response.error.message;\n }\n if (response.response.res) {\n error.message = response.response.res.statusMessage;\n }\n if (response.response.body && Object.keys(response.response.body).length > 0) {\n error._data = {};\n _.merge(error._data, response.response.body);\n } else {\n error._data = response.response.text;\n }\n }\n\n error.status = response.status || response.statusCode;\n error.name = response.code || response.name || error.name;\n error.message = error.message || response.message || response.statusMessage;\n\n if (log)\n error.log();\n\n return error;\n }\n\n /**\n * Decides whether request should be retried or not\n * @param error Error returned by request\n * @param response Response returned by request\n * @internal\n */\n public static shouldRetry(error: any, response: any): boolean {\n if (error !== undefined && error !== null) {\n if ((error.status === undefined || error.status === null) && (error.res === undefined || error.res === null)) {\n return true;\n }\n }\n return (response !== undefined && response.statusType === HttpStatus.ServerError);\n }\n\n /**\n * @internal\n */\n public static parseHttpStatus(statusType: number): HttpStatus {\n switch (statusType) {\n case 1:\n return HttpStatus.Info;\n case 2:\n return HttpStatus.Success;\n case 3:\n return HttpStatus.Redirection;\n case 4:\n return HttpStatus.ClientError;\n case 5:\n return HttpStatus.ServerError;\n default:\n return HttpStatus.Success;\n }\n }\n\n /**\n * @internal\n */\n public logMessage(): string {\n return `${this.status} ${this.name}: ${this.message}`;\n }\n\n /**\n * Logs this error\n * @internal\n */\n public log(): void {\n Logger.logError(loggerCategory, this.logMessage(), () => this.getMetaData());\n }\n}\n\nconst logResponse = (req: sarequest.SuperAgentRequest, startTime: number) => (res: sarequest.Response) => {\n const elapsed = new Date().getTime() - startTime;\n const elapsedTime = `${elapsed}ms`;\n Logger.logTrace(loggerCategory, `${req.method.toUpperCase()} ${res.status} ${req.url} (${elapsedTime})`);\n};\n\nconst logRequest = (req: sarequest.SuperAgentRequest): sarequest.SuperAgentRequest => {\n const startTime = new Date().getTime();\n return req.on(\"response\", logResponse(req, startTime));\n};\n\n/** Wrapper around making HTTP requests with the specific options.\n *\n * Usable in both a browser and node based environment.\n *\n * @param url Server URL to address the request\n * @param options Options to pass to the request\n * @returns Resolves to the response from the server\n * @throws ResponseError if the request fails due to network issues, or if the returned status is *outside* the range of 200-299 (inclusive)\n * @internal\n */\nexport async function request(url: string, options: RequestOptions): Promise<Response> {\n let sareq: sarequest.SuperAgentRequest = sarequest(options.method, url);\n if (options.retries)\n sareq = sareq.retry(options.retries, options.retryCallback);\n\n if (Logger.isEnabled(loggerCategory, LogLevel.Trace))\n sareq = sareq.use(logRequest);\n\n if (options.headers)\n sareq = sareq.set(options.headers);\n\n Logger.logInfo(loggerCategory, url);\n\n if (options.accept)\n sareq = sareq.accept(options.accept);\n\n if (options.body)\n sareq = sareq.send(options.body);\n\n if (options.timeout)\n sareq = sareq.timeout(options.timeout);\n\n if (options.responseType)\n sareq = sareq.responseType(options.responseType);\n\n if (options.redirects)\n sareq = sareq.redirects(options.redirects);\n else\n sareq = sareq.redirects(0);\n\n if (options.buffer)\n sareq = sareq.buffer(options.buffer);\n\n if (options.parser)\n sareq = sareq.parse(options.parser);\n\n /** Default to any globally supplied proxy, unless an agent is specified in this call */\n if (options.agent)\n sareq = sareq.agent(options.agent);\n\n if (options.progressCallback) {\n sareq = sareq.on(\"progress\", (event: sarequest.ProgressEvent) => {\n if (event) {\n options.progressCallback!({\n loaded: event.loaded,\n total: event.total,\n percent: event.percent,\n });\n }\n });\n }\n\n const errorCallback = options.errorCallback ? options.errorCallback : (response: any) => ResponseError.parse(response);\n\n if (options.readStream) {\n if (typeof window !== \"undefined\")\n throw new Error(\"This option is not supported on browsers\");\n\n return new Promise<Response>((resolve, reject) => {\n sareq = sareq.type(\"blob\");\n options\n .readStream\n .pipe(sareq)\n .on(\"error\", (error: any) => {\n const parsedError = errorCallback(error);\n reject(parsedError);\n })\n .on(\"end\", () => {\n const retResponse: Response = {\n status: 201,\n header: undefined,\n body: undefined,\n text: undefined,\n };\n resolve(retResponse);\n });\n });\n }\n\n if (options.stream) {\n if (typeof window !== \"undefined\")\n throw new Error(\"This option is not supported on browsers\");\n\n return new Promise<Response>((resolve, reject) => {\n sareq\n .on(\"response\", (res: any) => {\n if (res.statusCode !== 200) {\n const parsedError = errorCallback(res);\n reject(parsedError);\n return;\n }\n })\n .pipe(options.stream)\n .on(\"error\", (error: any) => {\n const parsedError = errorCallback(error);\n reject(parsedError);\n })\n .on(\"finish\", () => {\n const retResponse: Response = {\n status: 200,\n header: undefined,\n body: undefined,\n text: undefined,\n };\n resolve(retResponse);\n });\n });\n }\n\n // console.log(\"%s %s %s\", url, options.method, queryStr);\n\n /**\n * Note:\n * Javascript's fetch returns status.OK if error is between 200-299 inclusive, and doesn't reject in this case.\n * Fetch only rejects if there's some network issue (permissions issue or similar)\n * Superagent rejects network issues, and errors outside the range of 200-299. We are currently using\n * superagent, but may eventually switch to JavaScript's fetch library.\n */\n try {\n const response = await sareq;\n const retResponse: Response = {\n body: response.body,\n text: response.text,\n header: response.header,\n status: response.status,\n };\n return retResponse;\n } catch (error) {\n const parsedError = errorCallback(error);\n throw parsedError;\n }\n}\n\n/**\n * fetch json from HTTP request\n * @param url server URL to address the request\n * @internal\n */\nexport async function getJson(url: string): Promise<any> {\n const options: RequestOptions = {\n method: \"GET\",\n responseType: \"json\",\n };\n const data = await request(url, options);\n return data.body;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MobileAppChannel.js","sourceRoot":"","sources":["../../../src/common/MobileAppChannel.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,gBAAgB;AACH,QAAA,gBAAgB,GAAG;IAC9B,gBAAgB,EAAE,wBAAwB;IAC1C,eAAe,EAAE,+BAA+B;CACxC,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\r\n/** @internal */\r\nexport const mobileAppStrings = {\r\n mobileAppChannel: \"itwinjs-core/mobileApp\",\r\n mobileAppNotify: \"itwinjs-core/mobileApp-notify\",\r\n} as const;\r\n"]}
1
+ {"version":3,"file":"MobileAppChannel.js","sourceRoot":"","sources":["../../../src/common/MobileAppChannel.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,gBAAgB;AACH,QAAA,gBAAgB,GAAG;IAC9B,gBAAgB,EAAE,wBAAwB;IAC1C,eAAe,EAAE,+BAA+B;CACxC,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\n/** @internal */\nexport const mobileAppStrings = {\n mobileAppChannel: \"itwinjs-core/mobileApp\",\n mobileAppNotify: \"itwinjs-core/mobileApp-notify\",\n} as const;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MobileAppProps.js","sourceRoot":"","sources":["../../../src/common/MobileAppProps.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAI/F,YAAY;AACZ,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,2BAAX,WAAW,QAQtB;AAED,YAAY;AACZ,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,qDAAW,CAAA;IACX,yDAAa,CAAA;IACb,uDAAY,CAAA;IACZ,+CAAQ,CAAA;AACV,CAAC,EALW,YAAY,4BAAZ,YAAY,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\nimport { AccessToken } from \"@itwin/core-bentley\";\r\n\r\n/** @beta */\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\n/** @beta */\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\n/** @beta */\r\nexport interface MobileNotifications {\r\n notifyMemoryWarning: () => void;\r\n notifyOrientationChanged: () => void;\r\n notifyWillTerminate: () => void;\r\n notifyAuthAccessTokenChanged: (accessToken: string | undefined, expirationDate: string | undefined) => void;\r\n}\r\n\r\n/** @beta */\r\nexport type DeviceEvents = \"memoryWarning\" | \"orientationChanged\" | \"enterForeground\" | \"enterBackground\" | \"willTerminate\" | \"authAccessTokenChanged\";\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* @beta\r\n*/\r\nexport interface MobileAppFunctions {\r\n reconnect: (connection: number) => Promise<void>;\r\n getAccessToken: () => Promise<[AccessToken, string]>;\r\n}\r\n"]}
1
+ {"version":3,"file":"MobileAppProps.js","sourceRoot":"","sources":["../../../src/common/MobileAppProps.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAI/F,YAAY;AACZ,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,2BAAX,WAAW,QAQtB;AAED,YAAY;AACZ,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,qDAAW,CAAA;IACX,yDAAa,CAAA;IACb,uDAAY,CAAA;IACZ,+CAAQ,CAAA;AACV,CAAC,EALW,YAAY,4BAAZ,YAAY,QAKvB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { AccessToken } from \"@itwin/core-bentley\";\n\n/** @beta */\nexport enum Orientation {\n Unknown = 0,\n Portrait = 0x1,\n PortraitUpsideDown = 0x2,\n LandscapeLeft = 0x4,\n LandscapeRight = 0x8,\n FaceUp = 0x10,\n FaceDown = 0x20,\n}\n\n/** @beta */\nexport enum BatteryState {\n Unknown = 0,\n Unplugged = 1,\n Charging = 2,\n Full = 3,\n}\n\n/** @beta */\nexport interface MobileNotifications {\n notifyMemoryWarning: () => void;\n notifyOrientationChanged: () => void;\n notifyWillTerminate: () => void;\n notifyAuthAccessTokenChanged: (accessToken: string | undefined, expirationDate: string | undefined) => void;\n}\n\n/** @beta */\nexport type DeviceEvents = \"memoryWarning\" | \"orientationChanged\" | \"enterForeground\" | \"enterBackground\" | \"willTerminate\" | \"authAccessTokenChanged\";\n\n/**\n* The methods that may be invoked via Ipc from the frontend of a Mobile App that are implemented on its backend.\n* @beta\n*/\nexport interface MobileAppFunctions {\n reconnect: (connection: number) => Promise<void>;\n getAccessToken: () => Promise<[AccessToken, string]>;\n}\n"]}
@@ -10,6 +10,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.MobileEventLoop = void 0;
11
11
  /** @internal */
12
12
  class MobileEventLoop {
13
+ static _activeTasks = 0;
14
+ static _idleCallback = null;
13
15
  static addTask() {
14
16
  ++this._activeTasks;
15
17
  if (this._idleCallback === null) {
@@ -26,6 +28,4 @@ class MobileEventLoop {
26
28
  static _idleHandler() { }
27
29
  }
28
30
  exports.MobileEventLoop = MobileEventLoop;
29
- MobileEventLoop._activeTasks = 0;
30
- MobileEventLoop._idleCallback = null;
31
31
  //# sourceMappingURL=MobileEventLoop.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MobileEventLoop.js","sourceRoot":"","sources":["../../../src/common/MobileEventLoop.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,gBAAgB;AAChB,MAAa,eAAe;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":["/*---------------------------------------------------------------------------------------------\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.Timeout | 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"]}
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":"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,MA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3DD,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);\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 sendToFrontend(message: IpcWebSocketMessage) {\r\n MobileEventLoop.addTask();\r\n const result = 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"]}
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,C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,CAAC,aAAa,CAAC,OAA4B;;;YACtD,MAAM,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"]}
@@ -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":["/*---------------------------------------------------------------------------------------------\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 = 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"]}
1
+ {"version":3,"file":"MobilePush.js","sourceRoot":"","sources":["../../../src/common/MobilePush.ts"],"names":[],"mappings":";A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,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"]}
@@ -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":"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AO,CAAE,MAAc,CAAC,iBAAiB,EAAE,CAAC;gBAC1C,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1C,CAAC;YAED,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,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":["/*---------------------------------------------------------------------------------------------\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 { RpcConfiguration, RpcEndpoint, RpcInterfaceDefinition } from \"@itwin/core-common\";\r\nimport { MobileRpcProtocol } from \"./MobileRpcProtocol\";\r\n\r\n/* eslint-disable @typescript-eslint/no-deprecated */\r\n\r\n/** RPC supported mobile platforms.\r\n * @internal\r\n */\r\nexport enum RpcMobilePlatform {\r\n Unknown,\r\n Android,\r\n iOS,\r\n}\r\n\r\n/** Holds configuration for the RpcInterfaces used by the application.\r\n * @internal\r\n */\r\nexport abstract class MobileRpcConfiguration extends RpcConfiguration {\r\n /** @internal */\r\n public static setup = {\r\n obtainPort: () => 0,\r\n checkPlatform: () => typeof (process) !== \"undefined\" && (process.platform as any) === \"ios\",\r\n };\r\n\r\n public abstract override protocol: MobileRpcProtocol;\r\n private static _args: any;\r\n private static getArgs(): any {\r\n if (typeof window !== \"object\" || typeof window.location !== \"object\" || typeof window.location.hash !== \"string\") {\r\n return Object.freeze({});\r\n }\r\n const queryArgs: any = {};\r\n try {\r\n const matches = window.location.hash.match(/([^#=&]+)(=([^&]*))?/g);\r\n if (matches) {\r\n for (const comp of matches) {\r\n const array = comp.split(\"=\");\r\n if (array.length === 2) {\r\n const key = decodeURIComponent(array[0]);\r\n const val = decodeURIComponent(array[1]);\r\n queryArgs[key] = val;\r\n }\r\n }\r\n }\r\n } catch { }\r\n return Object.freeze(queryArgs);\r\n }\r\n private static getMobilePlatform(): RpcMobilePlatform {\r\n if (!MobileRpcConfiguration.args.platform)\r\n return RpcMobilePlatform.Unknown;\r\n\r\n const win: any = window;\r\n if (/android/i.test(MobileRpcConfiguration.args.platform)) {\r\n return RpcMobilePlatform.Android;\r\n }\r\n\r\n if (/iOS|iPadOS/i.test(MobileRpcConfiguration.args.platform) && !win.MSStream) {\r\n return RpcMobilePlatform.iOS;\r\n }\r\n\r\n return RpcMobilePlatform.Unknown;\r\n }\r\n /** Read the mobile rpc args */\r\n public static get args(): any {\r\n if (!this._args) {\r\n this._args = MobileRpcConfiguration.getArgs();\r\n }\r\n return this._args;\r\n }\r\n\r\n /** Return type of mobile platform using browser userAgent */\r\n public static get platform(): RpcMobilePlatform { return MobileRpcConfiguration.getMobilePlatform(); }\r\n}\r\n\r\n/** Coordinates usage of RPC interfaces for an Mobile-based application.\r\n * @internal\r\n */\r\nexport class MobileRpcManager {\r\n /** @internal */\r\n public static async ready() {\r\n return new Promise<void>(async (resolve) => {\r\n while (!(global as any).__iTwinJsRpcReady) {\r\n await new Promise((r) => setTimeout(r));\r\n }\r\n\r\n resolve();\r\n });\r\n }\r\n\r\n private static performInitialization(interfaces: RpcInterfaceDefinition[], endPoint: RpcEndpoint): MobileRpcConfiguration {\r\n const config = class extends MobileRpcConfiguration {\r\n public interfaces = () => interfaces;\r\n public protocol: MobileRpcProtocol = new MobileRpcProtocol(this, endPoint);\r\n };\r\n\r\n for (const def of interfaces) {\r\n RpcConfiguration.assign(def, () => config);\r\n }\r\n\r\n const instance = RpcConfiguration.obtain(config);\r\n RpcConfiguration.initializeInterfaces(instance);\r\n\r\n return instance;\r\n }\r\n\r\n /** Initializes MobileRpcManager for the frontend of an application. */\r\n public static initializeClient(interfaces: RpcInterfaceDefinition[]): MobileRpcConfiguration {\r\n return MobileRpcManager.performInitialization(interfaces, RpcEndpoint.Frontend);\r\n }\r\n /** Initializes MobileRpcManager for the backend of an application. */\r\n public static initializeImpl(interfaces: RpcInterfaceDefinition[]): MobileRpcConfiguration {\r\n return MobileRpcManager.performInitialization(interfaces, RpcEndpoint.Backend);\r\n }\r\n}\r\n\r\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,Q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AoC,EAAE,QAAqB;QAC9F,MAAM,MAAM,GAAG,KAAM,SAAQ,sBAAsB;YAC1C,UAAU,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC;YAC9B,QAAQ,GAAsB,IAAI,qCAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;SAC5E,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"]}
@@ -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,OAAyB;QACzD,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAC7D,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC;QACxC,UAAU,CAAC,UAAU,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAU,CAAC;QACpE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;IAC/C,CAAC;IAEM,MAAM,CAAC,cAAc,CAAC,WAAkC;QAC7D,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC;QACrC,WAAW,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAU,CAAC;QACjE,MAAM,GAAG,GAAG,WAAW,CAAC,SAAS,CAAC;QAClC,WAAW,CAAC,SAAS,GAAG,SAAS,CAAC;QAClC,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,WA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AAG,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":["/*---------------------------------------------------------------------------------------------\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 { BentleyStatus } from \"@itwin/core-bentley\";\r\nimport {\r\n IModelError, IpcWebSocket, RpcEndpoint, RpcProtocol, RpcPushChannel, RpcPushConnection, RpcRequest, RpcRequestFulfillment, RpcSerializedValue,\r\n SerializedRpcRequest,\r\n} from \"@itwin/core-common\";\r\nimport { MobileEventLoop } from \"./MobileEventLoop\";\r\nimport { MobileIpcTransport } from \"./MobileIpc\";\r\nimport { MobilePushConnection, MobilePushTransport } from \"./MobilePush\";\r\nimport { MobileRpcConfiguration } from \"./MobileRpcManager\";\r\nimport { MobileRpcRequest } from \"./MobileRpcRequest\";\r\n\r\n/* eslint-disable @typescript-eslint/no-deprecated */\r\n\r\n/** @internal */\r\nexport type MobileRpcChunks = Array<string | Uint8Array>;\r\n\r\n/** @internal */\r\nexport interface MobileRpcGateway {\r\n handler: (payload: ArrayBuffer | string, connectionId: number) => void;\r\n sendString: (message: string, connectionId: number) => void;\r\n sendBinary: (message: Uint8Array, connectionId: number) => void;\r\n port: number;\r\n connectionId: number;\r\n}\r\n\r\n/** RPC interface protocol for an Mobile-based application.\r\n * @internal\r\n */\r\nexport class MobileRpcProtocol extends RpcProtocol {\r\n public socket: WebSocket = (undefined as any);\r\n public requests: Map<string, MobileRpcRequest> = new Map();\r\n private _pending: MobileRpcChunks[] = [];\r\n private _capacity: number = Number.MAX_SAFE_INTEGER;\r\n private _sendInterval: number | undefined = undefined;\r\n private _sendIntervalHandler = () => this.trySend();\r\n public readonly requestType = MobileRpcRequest;\r\n private _partialRequest: SerializedRpcRequest | undefined = undefined;\r\n private _partialFulfillment: RpcRequestFulfillment | undefined = undefined;\r\n private _partialData: Uint8Array[] = [];\r\n private _port: number = 0;\r\n private _transport?: MobilePushTransport;\r\n private _ipc: MobileIpcTransport;\r\n public static obtainInterop(): MobileRpcGateway { throw new IModelError(BentleyStatus.ERROR, \"Not implemented.\"); }\r\n\r\n public static async encodeRequest(request: MobileRpcRequest): Promise<MobileRpcChunks> {\r\n const serialized = await request.protocol.serialize(request);\r\n const data = serialized.parameters.data;\r\n serialized.parameters.data = data.map((v) => v.byteLength) as any[];\r\n return [JSON.stringify(serialized), ...data];\r\n }\r\n\r\n public static encodeResponse(fulfillment: RpcRequestFulfillment): MobileRpcChunks {\r\n const data = fulfillment.result.data;\r\n fulfillment.result.data = data.map((v) => v.byteLength) as any[];\r\n const raw = fulfillment.rawResult;\r\n fulfillment.rawResult = undefined;\r\n const encoded = [JSON.stringify(fulfillment), ...data];\r\n fulfillment.rawResult = raw;\r\n return encoded;\r\n }\r\n\r\n constructor(configuration: MobileRpcConfiguration, endPoint: RpcEndpoint) {\r\n super(configuration);\r\n\r\n if (endPoint === RpcEndpoint.Frontend) {\r\n this.initializeFrontend();\r\n } else if (endPoint === RpcEndpoint.Backend) {\r\n this.initializeBackend();\r\n }\r\n\r\n this._ipc = new MobileIpcTransport(this);\r\n IpcWebSocket.transport = this._ipc;\r\n }\r\n\r\n private initializeFrontend() {\r\n if (typeof (WebSocket) === \"undefined\") {\r\n throw new IModelError(BentleyStatus.ERROR, \"MobileRpcProtocol on frontend require websocket to work\");\r\n }\r\n if (!MobileRpcConfiguration.args.port) {\r\n throw new IModelError(BentleyStatus.ERROR, \"MobileRpcProtocol require 'port' parameter\");\r\n }\r\n\r\n this._port = MobileRpcConfiguration.args.port;\r\n this.connect(this._port, false);\r\n\r\n (window as any)._imodeljs_rpc_reconnect = (port: number) => {\r\n this.socket.close();\r\n window.location.hash = window.location.hash.replace(`port=${this._port}`, `port=${port}`);\r\n this._port = port;\r\n this.connect(port, true);\r\n };\r\n\r\n const transport = new MobilePushTransport(this);\r\n this._transport = transport;\r\n RpcPushChannel.setup(transport);\r\n }\r\n\r\n private connect(port: number, reset: boolean) {\r\n const socket = new WebSocket(`ws://localhost:${port}`);\r\n socket.binaryType = \"arraybuffer\";\r\n this.connectMessageHandler(socket);\r\n this.connectOpenHandler(socket, reset);\r\n this.connectErrorHandler(socket);\r\n this.socket = socket;\r\n }\r\n\r\n private connectMessageHandler(socket: WebSocket) {\r\n socket.addEventListener(\"message\", async (event) => {\r\n if (this.socket !== socket) {\r\n return;\r\n }\r\n\r\n this.handleMessageFromBackend(event.data);\r\n });\r\n }\r\n\r\n private connectOpenHandler(socket: WebSocket, reset: boolean) {\r\n socket.addEventListener(\"open\", (_event) => {\r\n if (this.socket !== socket) {\r\n return;\r\n }\r\n\r\n if (reset) {\r\n this.reset();\r\n\r\n const requests = new Map(RpcRequest.activeRequests);\r\n requests.forEach((req) => {\r\n req.cancel();\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n req.submit();\r\n });\r\n }\r\n\r\n this.scheduleSend();\r\n });\r\n }\r\n\r\n private connectErrorHandler(socket: WebSocket) {\r\n socket.addEventListener(\"error\", (_event) => {\r\n if (this.socket !== socket) {\r\n return;\r\n }\r\n\r\n throw new IModelError(BentleyStatus.ERROR, \"Socket error.\");\r\n });\r\n }\r\n\r\n private reset() {\r\n this.requests.clear();\r\n this._capacity = Number.MAX_SAFE_INTEGER;\r\n\r\n if (typeof (this._sendInterval) !== \"undefined\") {\r\n window.clearInterval(this._sendInterval);\r\n this._sendInterval = undefined;\r\n }\r\n\r\n this._partialRequest = undefined;\r\n this._partialFulfillment = undefined;\r\n this._partialData.length = 0;\r\n }\r\n\r\n private scheduleSend() {\r\n if (!this._pending.length) {\r\n return;\r\n }\r\n\r\n this.trySend();\r\n\r\n if (this._pending.length && typeof (this._sendInterval) === \"undefined\") {\r\n this._sendInterval = window.setInterval(this._sendIntervalHandler, 0);\r\n }\r\n }\r\n\r\n private trySend() {\r\n if (this.socket.readyState !== WebSocket.OPEN) {\r\n return;\r\n }\r\n\r\n while (this._capacity !== 0 && this._pending.length) {\r\n --this._capacity;\r\n const next = this._pending.shift()!;\r\n for (const chunk of next) {\r\n this.socket.send(chunk);\r\n }\r\n }\r\n\r\n if (!this._pending.length && typeof (this._sendInterval) !== \"undefined\") {\r\n window.clearInterval(this._sendInterval);\r\n this._sendInterval = undefined;\r\n }\r\n }\r\n\r\n private handleMessageFromBackend(data: string | ArrayBuffer) {\r\n if (typeof (data) === \"string\") {\r\n this.handleStringFromBackend(data);\r\n } else {\r\n this.handleBinaryFromBackend(data);\r\n }\r\n }\r\n\r\n private handleStringFromBackend(data: string) {\r\n if (this._partialFulfillment) {\r\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (already receiving response).\");\r\n }\r\n\r\n const response = JSON.parse(data) as RpcRequestFulfillment;\r\n this._partialFulfillment = response;\r\n\r\n if (!response.result.data.length) {\r\n this.notifyResponse();\r\n }\r\n }\r\n\r\n private handleBinaryFromBackend(data: ArrayBuffer) {\r\n const fulfillment = this._partialFulfillment;\r\n if (!fulfillment) {\r\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (no response received).\");\r\n }\r\n\r\n this._partialData.push(new Uint8Array(data));\r\n if (this._partialData.length === fulfillment.result.data.length) {\r\n this.notifyResponse();\r\n }\r\n }\r\n\r\n private notifyResponse() {\r\n const response = this._partialFulfillment;\r\n if (!response) {\r\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (no response exists).\");\r\n }\r\n\r\n ++this._capacity;\r\n this.consumePartialData(response.result);\r\n this._partialFulfillment = undefined;\r\n\r\n if (this._transport && this._transport.consume(response)) {\r\n return;\r\n }\r\n\r\n if (this._ipc.consumeResponse(response)) {\r\n return;\r\n }\r\n\r\n const request = this.requests.get(response.id) as MobileRpcRequest;\r\n this.requests.delete(response.id);\r\n request.notifyResponse(response);\r\n }\r\n\r\n private consumePartialData(value: RpcSerializedValue) {\r\n for (let i = 0, l = value.data.length; i !== l; ++i) {\r\n value.data[i] = this._partialData[i];\r\n }\r\n\r\n this._partialData.length = 0;\r\n }\r\n\r\n private initializeBackend() {\r\n const mobilegateway = MobileRpcProtocol.obtainInterop();\r\n if (mobilegateway === undefined || mobilegateway == null) {\r\n throw new IModelError(BentleyStatus.ERROR, \"MobileRpcProtocol on backend require native bridge to be setup\");\r\n }\r\n\r\n mobilegateway.handler = (payload, connectionId) => this.handleMessageFromFrontend(payload, connectionId);\r\n RpcPushConnection.for = (channel, client) => new MobilePushConnection(channel, client, this);\r\n RpcPushChannel.enabled = true;\r\n }\r\n\r\n private handleMessageFromFrontend(data: string | ArrayBuffer, connectionId: number) {\r\n if (typeof (data) === \"string\") {\r\n this.handleStringFromFrontend(data, connectionId);\r\n } else {\r\n this.handleBinaryFromFrontend(data, connectionId);\r\n }\r\n }\r\n\r\n private handleStringFromFrontend(data: string, connection: number) {\r\n if (this._partialRequest) {\r\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (already receiving request).\");\r\n }\r\n\r\n const request = JSON.parse(data) as SerializedRpcRequest;\r\n this._partialRequest = request;\r\n\r\n if (!request.parameters.data.length) {\r\n this.notifyRequest(connection); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n }\r\n\r\n private handleBinaryFromFrontend(data: ArrayBuffer, connection: number) {\r\n const request = this._partialRequest;\r\n if (!request) {\r\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (no request received).\");\r\n }\r\n\r\n this._partialData.push(new Uint8Array(data));\r\n if (this._partialData.length === request.parameters.data.length) {\r\n this.notifyRequest(connection); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }\r\n }\r\n\r\n private async notifyRequest(connection: number) {\r\n const request = this._partialRequest;\r\n if (!request) {\r\n throw new IModelError(BentleyStatus.ERROR, \"Invalid state (no request exists).\");\r\n }\r\n\r\n this.consumePartialData(request.parameters);\r\n this._partialRequest = undefined;\r\n\r\n if (this._ipc.consumeRequest(request)) {\r\n return;\r\n }\r\n\r\n MobileEventLoop.addTask();\r\n const fulfillment = await this.fulfill(request);\r\n MobileEventLoop.removeTask();\r\n\r\n const response = MobileRpcProtocol.encodeResponse(fulfillment);\r\n this.sendToFrontend(response, connection);\r\n }\r\n\r\n public sendToBackend(message: MobileRpcChunks): void {\r\n this._pending.push(message);\r\n this.scheduleSend();\r\n }\r\n\r\n public sendToFrontend(message: MobileRpcChunks, connection?: number): void {\r\n const mobilegateway = MobileRpcProtocol.obtainInterop();\r\n\r\n for (const chunk of message) {\r\n if (typeof (chunk) === \"string\") {\r\n mobilegateway.sendString(chunk, connection || mobilegateway.connectionId);\r\n } else {\r\n mobilegateway.sendBinary(chunk, connection || mobilegateway.connectionId);\r\n }\r\n }\r\n }\r\n}\r\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,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BAAW,CAAC,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"]}
@@ -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":["/*---------------------------------------------------------------------------------------------\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 { RpcRequest, RpcRequestFulfillment, RpcSerializedValue } from \"@itwin/core-common\";\r\nimport { MobileRpcProtocol } from \"./MobileRpcProtocol\";\r\n\r\n/** @internal */\r\nexport class MobileRpcRequest extends RpcRequest {\r\n private _res: (value: number) => void = () => undefined;\r\n private _fulfillment: RpcRequestFulfillment | undefined = undefined;\r\n\r\n /** Convenience access to the protocol of this request. */\r\n public override readonly protocol: MobileRpcProtocol = this.client.configuration.protocol as any;\r\n\r\n /** Sends the request. */\r\n protected async send(): Promise<number> {\r\n this.protocol.requests.set(this.id, this);\r\n const parts = await MobileRpcProtocol.encodeRequest(this);\r\n this.protocol.sendToBackend(parts);\r\n return new Promise<number>((resolve) => {\r\n this._res = resolve;\r\n });\r\n }\r\n\r\n /** Loads the request. */\r\n protected async load(): Promise<RpcSerializedValue> {\r\n const fulfillment = this._fulfillment;\r\n if (!fulfillment) {\r\n throw new Error(\"No request fulfillment available.\");\r\n }\r\n\r\n return fulfillment.result;\r\n }\r\n\r\n /** Sets request header values. */\r\n protected setHeader(_name: string, _value: string): void {\r\n // No implementation\r\n }\r\n\r\n /** @internal */\r\n public notifyResponse(fulfillment: RpcRequestFulfillment) {\r\n this._fulfillment = fulfillment;\r\n this._res(fulfillment.status);\r\n }\r\n}\r\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"]}