@factoringplus/pl-components-pack-v3 0.4.88 → 0.4.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pl-components-pack-v3.es.js +2571 -142
- package/dist/pl-components-pack-v3.umd.js +24 -24
- package/dist/style.css +1 -1
- package/package.json +2 -1
|
@@ -36287,7 +36287,7 @@ function isUndefined(val) {
|
|
|
36287
36287
|
function isBuffer(val) {
|
|
36288
36288
|
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor) && typeof val.constructor.isBuffer === "function" && val.constructor.isBuffer(val);
|
|
36289
36289
|
}
|
|
36290
|
-
function isArrayBuffer(val) {
|
|
36290
|
+
function isArrayBuffer$1(val) {
|
|
36291
36291
|
return toString.call(val) === "[object ArrayBuffer]";
|
|
36292
36292
|
}
|
|
36293
36293
|
function isFormData(val) {
|
|
@@ -36298,7 +36298,7 @@ function isArrayBufferView(val) {
|
|
|
36298
36298
|
if (typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView) {
|
|
36299
36299
|
result = ArrayBuffer.isView(val);
|
|
36300
36300
|
} else {
|
|
36301
|
-
result = val && val.buffer && isArrayBuffer(val.buffer);
|
|
36301
|
+
result = val && val.buffer && isArrayBuffer$1(val.buffer);
|
|
36302
36302
|
}
|
|
36303
36303
|
return result;
|
|
36304
36304
|
}
|
|
@@ -36400,7 +36400,7 @@ function stripBOM(content) {
|
|
|
36400
36400
|
}
|
|
36401
36401
|
var utils$e = {
|
|
36402
36402
|
isArray,
|
|
36403
|
-
isArrayBuffer,
|
|
36403
|
+
isArrayBuffer: isArrayBuffer$1,
|
|
36404
36404
|
isBuffer,
|
|
36405
36405
|
isFormData,
|
|
36406
36406
|
isArrayBufferView,
|
|
@@ -37045,7 +37045,7 @@ var mergeConfig$2 = function mergeConfig2(config1, config2) {
|
|
|
37045
37045
|
var data = {
|
|
37046
37046
|
"version": "0.26.1"
|
|
37047
37047
|
};
|
|
37048
|
-
var VERSION = data.version;
|
|
37048
|
+
var VERSION$1 = data.version;
|
|
37049
37049
|
var validators$1 = {};
|
|
37050
37050
|
["object", "boolean", "number", "function", "string", "symbol"].forEach(function(type4, i2) {
|
|
37051
37051
|
validators$1[type4] = function validator2(thing) {
|
|
@@ -37055,7 +37055,7 @@ var validators$1 = {};
|
|
|
37055
37055
|
var deprecatedWarnings = {};
|
|
37056
37056
|
validators$1.transitional = function transitional2(validator2, version, message2) {
|
|
37057
37057
|
function formatMessage(opt, desc) {
|
|
37058
|
-
return "[Axios v" + VERSION + "] Transitional option '" + opt + "'" + desc + (message2 ? ". " + message2 : "");
|
|
37058
|
+
return "[Axios v" + VERSION$1 + "] Transitional option '" + opt + "'" + desc + (message2 ? ". " + message2 : "");
|
|
37059
37059
|
}
|
|
37060
37060
|
return function(value, opt, opts) {
|
|
37061
37061
|
if (validator2 === false) {
|
|
@@ -41857,158 +41857,2587 @@ const PlCheckboxPlugin = {
|
|
|
41857
41857
|
app.component("PlCheckbox", _sfc_main$1);
|
|
41858
41858
|
}
|
|
41859
41859
|
};
|
|
41860
|
-
|
|
41861
|
-
|
|
41862
|
-
|
|
41863
|
-
|
|
41864
|
-
|
|
41865
|
-
|
|
41866
|
-
getToken(token) {
|
|
41867
|
-
this.token = token;
|
|
41868
|
-
},
|
|
41869
|
-
getBaseUrl(url2) {
|
|
41870
|
-
this.baseUrl = url2;
|
|
41871
|
-
},
|
|
41872
|
-
api(optionsRequest) {
|
|
41873
|
-
return ApiJs(optionsRequest, false, `Bearer ${this.token}`, true);
|
|
41874
|
-
}
|
|
41860
|
+
class HttpError extends Error {
|
|
41861
|
+
constructor(errorMessage, statusCode) {
|
|
41862
|
+
const trueProto = new.target.prototype;
|
|
41863
|
+
super(`${errorMessage}: Status code '${statusCode}'`);
|
|
41864
|
+
this.statusCode = statusCode;
|
|
41865
|
+
this.__proto__ = trueProto;
|
|
41875
41866
|
}
|
|
41876
|
-
}
|
|
41877
|
-
|
|
41878
|
-
|
|
41879
|
-
|
|
41880
|
-
|
|
41867
|
+
}
|
|
41868
|
+
class TimeoutError extends Error {
|
|
41869
|
+
constructor(errorMessage = "A timeout occurred.") {
|
|
41870
|
+
const trueProto = new.target.prototype;
|
|
41871
|
+
super(errorMessage);
|
|
41872
|
+
this.__proto__ = trueProto;
|
|
41873
|
+
}
|
|
41874
|
+
}
|
|
41875
|
+
class AbortError extends Error {
|
|
41876
|
+
constructor(errorMessage = "An abort occurred.") {
|
|
41877
|
+
const trueProto = new.target.prototype;
|
|
41878
|
+
super(errorMessage);
|
|
41879
|
+
this.__proto__ = trueProto;
|
|
41880
|
+
}
|
|
41881
|
+
}
|
|
41882
|
+
class UnsupportedTransportError extends Error {
|
|
41883
|
+
constructor(message2, transport) {
|
|
41884
|
+
const trueProto = new.target.prototype;
|
|
41885
|
+
super(message2);
|
|
41886
|
+
this.transport = transport;
|
|
41887
|
+
this.errorType = "UnsupportedTransportError";
|
|
41888
|
+
this.__proto__ = trueProto;
|
|
41889
|
+
}
|
|
41890
|
+
}
|
|
41891
|
+
class DisabledTransportError extends Error {
|
|
41892
|
+
constructor(message2, transport) {
|
|
41893
|
+
const trueProto = new.target.prototype;
|
|
41894
|
+
super(message2);
|
|
41895
|
+
this.transport = transport;
|
|
41896
|
+
this.errorType = "DisabledTransportError";
|
|
41897
|
+
this.__proto__ = trueProto;
|
|
41898
|
+
}
|
|
41899
|
+
}
|
|
41900
|
+
class FailedToStartTransportError extends Error {
|
|
41901
|
+
constructor(message2, transport) {
|
|
41902
|
+
const trueProto = new.target.prototype;
|
|
41903
|
+
super(message2);
|
|
41904
|
+
this.transport = transport;
|
|
41905
|
+
this.errorType = "FailedToStartTransportError";
|
|
41906
|
+
this.__proto__ = trueProto;
|
|
41907
|
+
}
|
|
41908
|
+
}
|
|
41909
|
+
class FailedToNegotiateWithServerError extends Error {
|
|
41910
|
+
constructor(message2) {
|
|
41911
|
+
const trueProto = new.target.prototype;
|
|
41912
|
+
super(message2);
|
|
41913
|
+
this.errorType = "FailedToNegotiateWithServerError";
|
|
41914
|
+
this.__proto__ = trueProto;
|
|
41915
|
+
}
|
|
41916
|
+
}
|
|
41917
|
+
class AggregateErrors extends Error {
|
|
41918
|
+
constructor(message2, innerErrors) {
|
|
41919
|
+
const trueProto = new.target.prototype;
|
|
41920
|
+
super(message2);
|
|
41921
|
+
this.innerErrors = innerErrors;
|
|
41922
|
+
this.__proto__ = trueProto;
|
|
41923
|
+
}
|
|
41924
|
+
}
|
|
41925
|
+
class HttpResponse {
|
|
41926
|
+
constructor(statusCode, statusText, content) {
|
|
41927
|
+
this.statusCode = statusCode;
|
|
41928
|
+
this.statusText = statusText;
|
|
41929
|
+
this.content = content;
|
|
41930
|
+
}
|
|
41931
|
+
}
|
|
41932
|
+
class HttpClient {
|
|
41933
|
+
get(url2, options) {
|
|
41934
|
+
return this.send({
|
|
41935
|
+
...options,
|
|
41881
41936
|
method: "GET",
|
|
41882
|
-
|
|
41883
|
-
"x-group-id": "FLINE"
|
|
41884
|
-
},
|
|
41885
|
-
params: {
|
|
41886
|
-
count: count2
|
|
41887
|
-
}
|
|
41937
|
+
url: url2
|
|
41888
41938
|
});
|
|
41889
|
-
}
|
|
41890
|
-
|
|
41891
|
-
return
|
|
41892
|
-
|
|
41893
|
-
method: "
|
|
41894
|
-
|
|
41895
|
-
"x-group-id": "FLINE"
|
|
41896
|
-
}
|
|
41939
|
+
}
|
|
41940
|
+
post(url2, options) {
|
|
41941
|
+
return this.send({
|
|
41942
|
+
...options,
|
|
41943
|
+
method: "POST",
|
|
41944
|
+
url: url2
|
|
41897
41945
|
});
|
|
41898
|
-
}
|
|
41899
|
-
|
|
41900
|
-
return
|
|
41901
|
-
|
|
41902
|
-
method: "
|
|
41903
|
-
|
|
41904
|
-
"x-group-id": "FLINE"
|
|
41905
|
-
}
|
|
41946
|
+
}
|
|
41947
|
+
delete(url2, options) {
|
|
41948
|
+
return this.send({
|
|
41949
|
+
...options,
|
|
41950
|
+
method: "DELETE",
|
|
41951
|
+
url: url2
|
|
41906
41952
|
});
|
|
41907
41953
|
}
|
|
41908
|
-
|
|
41909
|
-
|
|
41910
|
-
|
|
41911
|
-
|
|
41912
|
-
|
|
41913
|
-
|
|
41914
|
-
|
|
41915
|
-
|
|
41916
|
-
|
|
41917
|
-
|
|
41918
|
-
|
|
41954
|
+
getCookieString(url2) {
|
|
41955
|
+
return "";
|
|
41956
|
+
}
|
|
41957
|
+
}
|
|
41958
|
+
var LogLevel;
|
|
41959
|
+
(function(LogLevel2) {
|
|
41960
|
+
LogLevel2[LogLevel2["Trace"] = 0] = "Trace";
|
|
41961
|
+
LogLevel2[LogLevel2["Debug"] = 1] = "Debug";
|
|
41962
|
+
LogLevel2[LogLevel2["Information"] = 2] = "Information";
|
|
41963
|
+
LogLevel2[LogLevel2["Warning"] = 3] = "Warning";
|
|
41964
|
+
LogLevel2[LogLevel2["Error"] = 4] = "Error";
|
|
41965
|
+
LogLevel2[LogLevel2["Critical"] = 5] = "Critical";
|
|
41966
|
+
LogLevel2[LogLevel2["None"] = 6] = "None";
|
|
41967
|
+
})(LogLevel || (LogLevel = {}));
|
|
41968
|
+
class NullLogger {
|
|
41969
|
+
constructor() {
|
|
41970
|
+
}
|
|
41971
|
+
log(_logLevel, _message) {
|
|
41972
|
+
}
|
|
41973
|
+
}
|
|
41974
|
+
NullLogger.instance = new NullLogger();
|
|
41975
|
+
const VERSION = "7.0.0";
|
|
41976
|
+
class Arg {
|
|
41977
|
+
static isRequired(val, name) {
|
|
41978
|
+
if (val === null || val === void 0) {
|
|
41979
|
+
throw new Error(`The '${name}' argument is required.`);
|
|
41919
41980
|
}
|
|
41920
41981
|
}
|
|
41921
|
-
|
|
41922
|
-
|
|
41923
|
-
|
|
41924
|
-
channels: [],
|
|
41925
|
-
unreadChannels: {},
|
|
41926
|
-
groups: []
|
|
41927
|
-
}),
|
|
41928
|
-
getters: {
|
|
41929
|
-
api() {
|
|
41930
|
-
const configStore = useConfigStore();
|
|
41931
|
-
return configStore.api;
|
|
41932
|
-
},
|
|
41933
|
-
baseUrl() {
|
|
41934
|
-
const configStore = useConfigStore();
|
|
41935
|
-
return configStore.baseUrl;
|
|
41982
|
+
static isNotEmpty(val, name) {
|
|
41983
|
+
if (!val || val.match(/^\s*$/)) {
|
|
41984
|
+
throw new Error(`The '${name}' argument should not be empty.`);
|
|
41936
41985
|
}
|
|
41937
|
-
}
|
|
41938
|
-
|
|
41939
|
-
|
|
41940
|
-
|
|
41941
|
-
|
|
41942
|
-
|
|
41943
|
-
|
|
41944
|
-
|
|
41945
|
-
|
|
41946
|
-
|
|
41947
|
-
|
|
41948
|
-
|
|
41949
|
-
|
|
41950
|
-
|
|
41951
|
-
|
|
41952
|
-
|
|
41953
|
-
|
|
41954
|
-
|
|
41986
|
+
}
|
|
41987
|
+
static isIn(val, values, name) {
|
|
41988
|
+
if (!(val in values)) {
|
|
41989
|
+
throw new Error(`Unknown ${name} value: ${val}.`);
|
|
41990
|
+
}
|
|
41991
|
+
}
|
|
41992
|
+
}
|
|
41993
|
+
class Platform {
|
|
41994
|
+
static get isBrowser() {
|
|
41995
|
+
return typeof window === "object" && typeof window.document === "object";
|
|
41996
|
+
}
|
|
41997
|
+
static get isWebWorker() {
|
|
41998
|
+
return typeof self === "object" && "importScripts" in self;
|
|
41999
|
+
}
|
|
42000
|
+
static get isReactNative() {
|
|
42001
|
+
return typeof window === "object" && typeof window.document === "undefined";
|
|
42002
|
+
}
|
|
42003
|
+
static get isNode() {
|
|
42004
|
+
return !this.isBrowser && !this.isWebWorker && !this.isReactNative;
|
|
42005
|
+
}
|
|
42006
|
+
}
|
|
42007
|
+
function getDataDetail(data2, includeContent) {
|
|
42008
|
+
let detail = "";
|
|
42009
|
+
if (isArrayBuffer(data2)) {
|
|
42010
|
+
detail = `Binary data of length ${data2.byteLength}`;
|
|
42011
|
+
if (includeContent) {
|
|
42012
|
+
detail += `. Content: '${formatArrayBuffer(data2)}'`;
|
|
42013
|
+
}
|
|
42014
|
+
} else if (typeof data2 === "string") {
|
|
42015
|
+
detail = `String data of length ${data2.length}`;
|
|
42016
|
+
if (includeContent) {
|
|
42017
|
+
detail += `. Content: '${data2}'`;
|
|
42018
|
+
}
|
|
42019
|
+
}
|
|
42020
|
+
return detail;
|
|
42021
|
+
}
|
|
42022
|
+
function formatArrayBuffer(data2) {
|
|
42023
|
+
const view = new Uint8Array(data2);
|
|
42024
|
+
let str2 = "";
|
|
42025
|
+
view.forEach((num) => {
|
|
42026
|
+
const pad = num < 16 ? "0" : "";
|
|
42027
|
+
str2 += `0x${pad}${num.toString(16)} `;
|
|
42028
|
+
});
|
|
42029
|
+
return str2.substr(0, str2.length - 1);
|
|
42030
|
+
}
|
|
42031
|
+
function isArrayBuffer(val) {
|
|
42032
|
+
return val && typeof ArrayBuffer !== "undefined" && (val instanceof ArrayBuffer || val.constructor && val.constructor.name === "ArrayBuffer");
|
|
42033
|
+
}
|
|
42034
|
+
async function sendMessage(logger, transportName, httpClient, url2, content, options) {
|
|
42035
|
+
const headers = {};
|
|
42036
|
+
const [name, value] = getUserAgentHeader();
|
|
42037
|
+
headers[name] = value;
|
|
42038
|
+
logger.log(LogLevel.Trace, `(${transportName} transport) sending data. ${getDataDetail(content, options.logMessageContent)}.`);
|
|
42039
|
+
const responseType = isArrayBuffer(content) ? "arraybuffer" : "text";
|
|
42040
|
+
const response2 = await httpClient.post(url2, {
|
|
42041
|
+
content,
|
|
42042
|
+
headers: { ...headers, ...options.headers },
|
|
42043
|
+
responseType,
|
|
42044
|
+
timeout: options.timeout,
|
|
42045
|
+
withCredentials: options.withCredentials
|
|
42046
|
+
});
|
|
42047
|
+
logger.log(LogLevel.Trace, `(${transportName} transport) request complete. Response status: ${response2.statusCode}.`);
|
|
42048
|
+
}
|
|
42049
|
+
function createLogger(logger) {
|
|
42050
|
+
if (logger === void 0) {
|
|
42051
|
+
return new ConsoleLogger(LogLevel.Information);
|
|
42052
|
+
}
|
|
42053
|
+
if (logger === null) {
|
|
42054
|
+
return NullLogger.instance;
|
|
42055
|
+
}
|
|
42056
|
+
if (logger.log !== void 0) {
|
|
42057
|
+
return logger;
|
|
42058
|
+
}
|
|
42059
|
+
return new ConsoleLogger(logger);
|
|
42060
|
+
}
|
|
42061
|
+
class SubjectSubscription {
|
|
42062
|
+
constructor(subject, observer) {
|
|
42063
|
+
this._subject = subject;
|
|
42064
|
+
this._observer = observer;
|
|
42065
|
+
}
|
|
42066
|
+
dispose() {
|
|
42067
|
+
const index = this._subject.observers.indexOf(this._observer);
|
|
42068
|
+
if (index > -1) {
|
|
42069
|
+
this._subject.observers.splice(index, 1);
|
|
42070
|
+
}
|
|
42071
|
+
if (this._subject.observers.length === 0 && this._subject.cancelCallback) {
|
|
42072
|
+
this._subject.cancelCallback().catch((_2) => {
|
|
42073
|
+
});
|
|
42074
|
+
}
|
|
42075
|
+
}
|
|
42076
|
+
}
|
|
42077
|
+
class ConsoleLogger {
|
|
42078
|
+
constructor(minimumLogLevel) {
|
|
42079
|
+
this._minLevel = minimumLogLevel;
|
|
42080
|
+
this.out = console;
|
|
42081
|
+
}
|
|
42082
|
+
log(logLevel, message2) {
|
|
42083
|
+
if (logLevel >= this._minLevel) {
|
|
42084
|
+
const msg = `[${new Date().toISOString()}] ${LogLevel[logLevel]}: ${message2}`;
|
|
42085
|
+
switch (logLevel) {
|
|
42086
|
+
case LogLevel.Critical:
|
|
42087
|
+
case LogLevel.Error:
|
|
42088
|
+
this.out.error(msg);
|
|
42089
|
+
break;
|
|
42090
|
+
case LogLevel.Warning:
|
|
42091
|
+
this.out.warn(msg);
|
|
42092
|
+
break;
|
|
42093
|
+
case LogLevel.Information:
|
|
42094
|
+
this.out.info(msg);
|
|
42095
|
+
break;
|
|
42096
|
+
default:
|
|
42097
|
+
this.out.log(msg);
|
|
42098
|
+
break;
|
|
41955
42099
|
}
|
|
41956
|
-
}
|
|
41957
|
-
|
|
41958
|
-
|
|
41959
|
-
|
|
41960
|
-
|
|
41961
|
-
|
|
42100
|
+
}
|
|
42101
|
+
}
|
|
42102
|
+
}
|
|
42103
|
+
function getUserAgentHeader() {
|
|
42104
|
+
let userAgentHeaderName = "X-SignalR-User-Agent";
|
|
42105
|
+
if (Platform.isNode) {
|
|
42106
|
+
userAgentHeaderName = "User-Agent";
|
|
42107
|
+
}
|
|
42108
|
+
return [userAgentHeaderName, constructUserAgent(VERSION, getOsName(), getRuntime(), getRuntimeVersion())];
|
|
42109
|
+
}
|
|
42110
|
+
function constructUserAgent(version, os, runtime, runtimeVersion) {
|
|
42111
|
+
let userAgent = "Microsoft SignalR/";
|
|
42112
|
+
const majorAndMinor = version.split(".");
|
|
42113
|
+
userAgent += `${majorAndMinor[0]}.${majorAndMinor[1]}`;
|
|
42114
|
+
userAgent += ` (${version}; `;
|
|
42115
|
+
if (os && os !== "") {
|
|
42116
|
+
userAgent += `${os}; `;
|
|
42117
|
+
} else {
|
|
42118
|
+
userAgent += "Unknown OS; ";
|
|
42119
|
+
}
|
|
42120
|
+
userAgent += `${runtime}`;
|
|
42121
|
+
if (runtimeVersion) {
|
|
42122
|
+
userAgent += `; ${runtimeVersion}`;
|
|
42123
|
+
} else {
|
|
42124
|
+
userAgent += "; Unknown Runtime Version";
|
|
42125
|
+
}
|
|
42126
|
+
userAgent += ")";
|
|
42127
|
+
return userAgent;
|
|
42128
|
+
}
|
|
42129
|
+
function getOsName() {
|
|
42130
|
+
if (Platform.isNode) {
|
|
42131
|
+
switch (process.platform) {
|
|
42132
|
+
case "win32":
|
|
42133
|
+
return "Windows NT";
|
|
42134
|
+
case "darwin":
|
|
42135
|
+
return "macOS";
|
|
42136
|
+
case "linux":
|
|
42137
|
+
return "Linux";
|
|
42138
|
+
default:
|
|
42139
|
+
return process.platform;
|
|
42140
|
+
}
|
|
42141
|
+
} else {
|
|
42142
|
+
return "";
|
|
42143
|
+
}
|
|
42144
|
+
}
|
|
42145
|
+
function getRuntimeVersion() {
|
|
42146
|
+
if (Platform.isNode) {
|
|
42147
|
+
return process.versions.node;
|
|
42148
|
+
}
|
|
42149
|
+
return void 0;
|
|
42150
|
+
}
|
|
42151
|
+
function getRuntime() {
|
|
42152
|
+
if (Platform.isNode) {
|
|
42153
|
+
return "NodeJS";
|
|
42154
|
+
} else {
|
|
42155
|
+
return "Browser";
|
|
42156
|
+
}
|
|
42157
|
+
}
|
|
42158
|
+
function getErrorString(e2) {
|
|
42159
|
+
if (e2.stack) {
|
|
42160
|
+
return e2.stack;
|
|
42161
|
+
} else if (e2.message) {
|
|
42162
|
+
return e2.message;
|
|
42163
|
+
}
|
|
42164
|
+
return `${e2}`;
|
|
42165
|
+
}
|
|
42166
|
+
function getGlobalThis() {
|
|
42167
|
+
if (typeof globalThis !== "undefined") {
|
|
42168
|
+
return globalThis;
|
|
42169
|
+
}
|
|
42170
|
+
if (typeof self !== "undefined") {
|
|
42171
|
+
return self;
|
|
42172
|
+
}
|
|
42173
|
+
if (typeof window !== "undefined") {
|
|
42174
|
+
return window;
|
|
42175
|
+
}
|
|
42176
|
+
if (typeof global !== "undefined") {
|
|
42177
|
+
return global;
|
|
42178
|
+
}
|
|
42179
|
+
throw new Error("could not find global");
|
|
42180
|
+
}
|
|
42181
|
+
class FetchHttpClient extends HttpClient {
|
|
42182
|
+
constructor(logger) {
|
|
42183
|
+
super();
|
|
42184
|
+
this._logger = logger;
|
|
42185
|
+
if (typeof fetch === "undefined") {
|
|
42186
|
+
const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
|
|
42187
|
+
this._jar = new (requireFunc("tough-cookie")).CookieJar();
|
|
42188
|
+
this._fetchType = requireFunc("node-fetch");
|
|
42189
|
+
this._fetchType = requireFunc("fetch-cookie")(this._fetchType, this._jar);
|
|
42190
|
+
} else {
|
|
42191
|
+
this._fetchType = fetch.bind(getGlobalThis());
|
|
42192
|
+
}
|
|
42193
|
+
if (typeof AbortController === "undefined") {
|
|
42194
|
+
const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
|
|
42195
|
+
this._abortControllerType = requireFunc("abort-controller");
|
|
42196
|
+
} else {
|
|
42197
|
+
this._abortControllerType = AbortController;
|
|
42198
|
+
}
|
|
42199
|
+
}
|
|
42200
|
+
async send(request2) {
|
|
42201
|
+
if (request2.abortSignal && request2.abortSignal.aborted) {
|
|
42202
|
+
throw new AbortError();
|
|
42203
|
+
}
|
|
42204
|
+
if (!request2.method) {
|
|
42205
|
+
throw new Error("No method defined.");
|
|
42206
|
+
}
|
|
42207
|
+
if (!request2.url) {
|
|
42208
|
+
throw new Error("No url defined.");
|
|
42209
|
+
}
|
|
42210
|
+
const abortController = new this._abortControllerType();
|
|
42211
|
+
let error2;
|
|
42212
|
+
if (request2.abortSignal) {
|
|
42213
|
+
request2.abortSignal.onabort = () => {
|
|
42214
|
+
abortController.abort();
|
|
42215
|
+
error2 = new AbortError();
|
|
42216
|
+
};
|
|
42217
|
+
}
|
|
42218
|
+
let timeoutId = null;
|
|
42219
|
+
if (request2.timeout) {
|
|
42220
|
+
const msTimeout = request2.timeout;
|
|
42221
|
+
timeoutId = setTimeout(() => {
|
|
42222
|
+
abortController.abort();
|
|
42223
|
+
this._logger.log(LogLevel.Warning, `Timeout from HTTP request.`);
|
|
42224
|
+
error2 = new TimeoutError();
|
|
42225
|
+
}, msTimeout);
|
|
42226
|
+
}
|
|
42227
|
+
if (request2.content === "") {
|
|
42228
|
+
request2.content = void 0;
|
|
42229
|
+
}
|
|
42230
|
+
if (request2.content) {
|
|
42231
|
+
request2.headers = request2.headers || {};
|
|
42232
|
+
if (isArrayBuffer(request2.content)) {
|
|
42233
|
+
request2.headers["Content-Type"] = "application/octet-stream";
|
|
42234
|
+
} else {
|
|
42235
|
+
request2.headers["Content-Type"] = "text/plain;charset=UTF-8";
|
|
41962
42236
|
}
|
|
41963
|
-
}
|
|
41964
|
-
|
|
41965
|
-
|
|
41966
|
-
|
|
41967
|
-
|
|
41968
|
-
|
|
42237
|
+
}
|
|
42238
|
+
let response2;
|
|
42239
|
+
try {
|
|
42240
|
+
response2 = await this._fetchType(request2.url, {
|
|
42241
|
+
body: request2.content,
|
|
42242
|
+
cache: "no-cache",
|
|
42243
|
+
credentials: request2.withCredentials === true ? "include" : "same-origin",
|
|
42244
|
+
headers: {
|
|
42245
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
42246
|
+
...request2.headers
|
|
42247
|
+
},
|
|
42248
|
+
method: request2.method,
|
|
42249
|
+
mode: "cors",
|
|
42250
|
+
redirect: "follow",
|
|
42251
|
+
signal: abortController.signal
|
|
42252
|
+
});
|
|
42253
|
+
} catch (e2) {
|
|
42254
|
+
if (error2) {
|
|
42255
|
+
throw error2;
|
|
42256
|
+
}
|
|
42257
|
+
this._logger.log(LogLevel.Warning, `Error from HTTP request. ${e2}.`);
|
|
42258
|
+
throw e2;
|
|
42259
|
+
} finally {
|
|
42260
|
+
if (timeoutId) {
|
|
42261
|
+
clearTimeout(timeoutId);
|
|
42262
|
+
}
|
|
42263
|
+
if (request2.abortSignal) {
|
|
42264
|
+
request2.abortSignal.onabort = null;
|
|
41969
42265
|
}
|
|
41970
42266
|
}
|
|
42267
|
+
if (!response2.ok) {
|
|
42268
|
+
const errorMessage = await deserializeContent(response2, "text");
|
|
42269
|
+
throw new HttpError(errorMessage || response2.statusText, response2.status);
|
|
42270
|
+
}
|
|
42271
|
+
const content = deserializeContent(response2, request2.responseType);
|
|
42272
|
+
const payload = await content;
|
|
42273
|
+
return new HttpResponse(response2.status, response2.statusText, payload);
|
|
41971
42274
|
}
|
|
41972
|
-
|
|
41973
|
-
|
|
41974
|
-
|
|
41975
|
-
|
|
41976
|
-
token: {
|
|
41977
|
-
type: String,
|
|
41978
|
-
default: ""
|
|
41979
|
-
},
|
|
41980
|
-
baseUrl: {
|
|
41981
|
-
type: String,
|
|
41982
|
-
default: ""
|
|
42275
|
+
getCookieString(url2) {
|
|
42276
|
+
let cookies2 = "";
|
|
42277
|
+
if (Platform.isNode && this._jar) {
|
|
42278
|
+
this._jar.getCookies(url2, (e2, c2) => cookies2 = c2.join("; "));
|
|
41983
42279
|
}
|
|
41984
|
-
|
|
41985
|
-
|
|
41986
|
-
|
|
41987
|
-
|
|
41988
|
-
|
|
41989
|
-
|
|
41990
|
-
|
|
41991
|
-
|
|
41992
|
-
|
|
41993
|
-
|
|
41994
|
-
|
|
41995
|
-
|
|
41996
|
-
|
|
41997
|
-
|
|
41998
|
-
|
|
41999
|
-
|
|
42000
|
-
|
|
42001
|
-
|
|
42002
|
-
|
|
42003
|
-
|
|
42004
|
-
|
|
42005
|
-
|
|
42006
|
-
|
|
42007
|
-
|
|
42008
|
-
|
|
42009
|
-
|
|
42010
|
-
|
|
42011
|
-
|
|
42280
|
+
return cookies2;
|
|
42281
|
+
}
|
|
42282
|
+
}
|
|
42283
|
+
function deserializeContent(response2, responseType) {
|
|
42284
|
+
let content;
|
|
42285
|
+
switch (responseType) {
|
|
42286
|
+
case "arraybuffer":
|
|
42287
|
+
content = response2.arrayBuffer();
|
|
42288
|
+
break;
|
|
42289
|
+
case "text":
|
|
42290
|
+
content = response2.text();
|
|
42291
|
+
break;
|
|
42292
|
+
case "blob":
|
|
42293
|
+
case "document":
|
|
42294
|
+
case "json":
|
|
42295
|
+
throw new Error(`${responseType} is not supported.`);
|
|
42296
|
+
default:
|
|
42297
|
+
content = response2.text();
|
|
42298
|
+
break;
|
|
42299
|
+
}
|
|
42300
|
+
return content;
|
|
42301
|
+
}
|
|
42302
|
+
class XhrHttpClient extends HttpClient {
|
|
42303
|
+
constructor(logger) {
|
|
42304
|
+
super();
|
|
42305
|
+
this._logger = logger;
|
|
42306
|
+
}
|
|
42307
|
+
send(request2) {
|
|
42308
|
+
if (request2.abortSignal && request2.abortSignal.aborted) {
|
|
42309
|
+
return Promise.reject(new AbortError());
|
|
42310
|
+
}
|
|
42311
|
+
if (!request2.method) {
|
|
42312
|
+
return Promise.reject(new Error("No method defined."));
|
|
42313
|
+
}
|
|
42314
|
+
if (!request2.url) {
|
|
42315
|
+
return Promise.reject(new Error("No url defined."));
|
|
42316
|
+
}
|
|
42317
|
+
return new Promise((resolve, reject) => {
|
|
42318
|
+
const xhr2 = new XMLHttpRequest();
|
|
42319
|
+
xhr2.open(request2.method, request2.url, true);
|
|
42320
|
+
xhr2.withCredentials = request2.withCredentials === void 0 ? true : request2.withCredentials;
|
|
42321
|
+
xhr2.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
|
42322
|
+
if (request2.content === "") {
|
|
42323
|
+
request2.content = void 0;
|
|
42324
|
+
}
|
|
42325
|
+
if (request2.content) {
|
|
42326
|
+
if (isArrayBuffer(request2.content)) {
|
|
42327
|
+
xhr2.setRequestHeader("Content-Type", "application/octet-stream");
|
|
42328
|
+
} else {
|
|
42329
|
+
xhr2.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
|
|
42330
|
+
}
|
|
42331
|
+
}
|
|
42332
|
+
const headers = request2.headers;
|
|
42333
|
+
if (headers) {
|
|
42334
|
+
Object.keys(headers).forEach((header) => {
|
|
42335
|
+
xhr2.setRequestHeader(header, headers[header]);
|
|
42336
|
+
});
|
|
42337
|
+
}
|
|
42338
|
+
if (request2.responseType) {
|
|
42339
|
+
xhr2.responseType = request2.responseType;
|
|
42340
|
+
}
|
|
42341
|
+
if (request2.abortSignal) {
|
|
42342
|
+
request2.abortSignal.onabort = () => {
|
|
42343
|
+
xhr2.abort();
|
|
42344
|
+
reject(new AbortError());
|
|
42345
|
+
};
|
|
42346
|
+
}
|
|
42347
|
+
if (request2.timeout) {
|
|
42348
|
+
xhr2.timeout = request2.timeout;
|
|
42349
|
+
}
|
|
42350
|
+
xhr2.onload = () => {
|
|
42351
|
+
if (request2.abortSignal) {
|
|
42352
|
+
request2.abortSignal.onabort = null;
|
|
42353
|
+
}
|
|
42354
|
+
if (xhr2.status >= 200 && xhr2.status < 300) {
|
|
42355
|
+
resolve(new HttpResponse(xhr2.status, xhr2.statusText, xhr2.response || xhr2.responseText));
|
|
42356
|
+
} else {
|
|
42357
|
+
reject(new HttpError(xhr2.response || xhr2.responseText || xhr2.statusText, xhr2.status));
|
|
42358
|
+
}
|
|
42359
|
+
};
|
|
42360
|
+
xhr2.onerror = () => {
|
|
42361
|
+
this._logger.log(LogLevel.Warning, `Error from HTTP request. ${xhr2.status}: ${xhr2.statusText}.`);
|
|
42362
|
+
reject(new HttpError(xhr2.statusText, xhr2.status));
|
|
42363
|
+
};
|
|
42364
|
+
xhr2.ontimeout = () => {
|
|
42365
|
+
this._logger.log(LogLevel.Warning, `Timeout from HTTP request.`);
|
|
42366
|
+
reject(new TimeoutError());
|
|
42367
|
+
};
|
|
42368
|
+
xhr2.send(request2.content);
|
|
42369
|
+
});
|
|
42370
|
+
}
|
|
42371
|
+
}
|
|
42372
|
+
class DefaultHttpClient extends HttpClient {
|
|
42373
|
+
constructor(logger) {
|
|
42374
|
+
super();
|
|
42375
|
+
if (typeof fetch !== "undefined" || Platform.isNode) {
|
|
42376
|
+
this._httpClient = new FetchHttpClient(logger);
|
|
42377
|
+
} else if (typeof XMLHttpRequest !== "undefined") {
|
|
42378
|
+
this._httpClient = new XhrHttpClient(logger);
|
|
42379
|
+
} else {
|
|
42380
|
+
throw new Error("No usable HttpClient found.");
|
|
42381
|
+
}
|
|
42382
|
+
}
|
|
42383
|
+
send(request2) {
|
|
42384
|
+
if (request2.abortSignal && request2.abortSignal.aborted) {
|
|
42385
|
+
return Promise.reject(new AbortError());
|
|
42386
|
+
}
|
|
42387
|
+
if (!request2.method) {
|
|
42388
|
+
return Promise.reject(new Error("No method defined."));
|
|
42389
|
+
}
|
|
42390
|
+
if (!request2.url) {
|
|
42391
|
+
return Promise.reject(new Error("No url defined."));
|
|
42392
|
+
}
|
|
42393
|
+
return this._httpClient.send(request2);
|
|
42394
|
+
}
|
|
42395
|
+
getCookieString(url2) {
|
|
42396
|
+
return this._httpClient.getCookieString(url2);
|
|
42397
|
+
}
|
|
42398
|
+
}
|
|
42399
|
+
class TextMessageFormat {
|
|
42400
|
+
static write(output) {
|
|
42401
|
+
return `${output}${TextMessageFormat.RecordSeparator}`;
|
|
42402
|
+
}
|
|
42403
|
+
static parse(input2) {
|
|
42404
|
+
if (input2[input2.length - 1] !== TextMessageFormat.RecordSeparator) {
|
|
42405
|
+
throw new Error("Message is incomplete.");
|
|
42406
|
+
}
|
|
42407
|
+
const messages2 = input2.split(TextMessageFormat.RecordSeparator);
|
|
42408
|
+
messages2.pop();
|
|
42409
|
+
return messages2;
|
|
42410
|
+
}
|
|
42411
|
+
}
|
|
42412
|
+
TextMessageFormat.RecordSeparatorCode = 30;
|
|
42413
|
+
TextMessageFormat.RecordSeparator = String.fromCharCode(TextMessageFormat.RecordSeparatorCode);
|
|
42414
|
+
class HandshakeProtocol {
|
|
42415
|
+
writeHandshakeRequest(handshakeRequest) {
|
|
42416
|
+
return TextMessageFormat.write(JSON.stringify(handshakeRequest));
|
|
42417
|
+
}
|
|
42418
|
+
parseHandshakeResponse(data2) {
|
|
42419
|
+
let messageData;
|
|
42420
|
+
let remainingData;
|
|
42421
|
+
if (isArrayBuffer(data2)) {
|
|
42422
|
+
const binaryData = new Uint8Array(data2);
|
|
42423
|
+
const separatorIndex = binaryData.indexOf(TextMessageFormat.RecordSeparatorCode);
|
|
42424
|
+
if (separatorIndex === -1) {
|
|
42425
|
+
throw new Error("Message is incomplete.");
|
|
42426
|
+
}
|
|
42427
|
+
const responseLength = separatorIndex + 1;
|
|
42428
|
+
messageData = String.fromCharCode.apply(null, Array.prototype.slice.call(binaryData.slice(0, responseLength)));
|
|
42429
|
+
remainingData = binaryData.byteLength > responseLength ? binaryData.slice(responseLength).buffer : null;
|
|
42430
|
+
} else {
|
|
42431
|
+
const textData = data2;
|
|
42432
|
+
const separatorIndex = textData.indexOf(TextMessageFormat.RecordSeparator);
|
|
42433
|
+
if (separatorIndex === -1) {
|
|
42434
|
+
throw new Error("Message is incomplete.");
|
|
42435
|
+
}
|
|
42436
|
+
const responseLength = separatorIndex + 1;
|
|
42437
|
+
messageData = textData.substring(0, responseLength);
|
|
42438
|
+
remainingData = textData.length > responseLength ? textData.substring(responseLength) : null;
|
|
42439
|
+
}
|
|
42440
|
+
const messages2 = TextMessageFormat.parse(messageData);
|
|
42441
|
+
const response2 = JSON.parse(messages2[0]);
|
|
42442
|
+
if (response2.type) {
|
|
42443
|
+
throw new Error("Expected a handshake response from the server.");
|
|
42444
|
+
}
|
|
42445
|
+
const responseMessage = response2;
|
|
42446
|
+
return [remainingData, responseMessage];
|
|
42447
|
+
}
|
|
42448
|
+
}
|
|
42449
|
+
var MessageType;
|
|
42450
|
+
(function(MessageType2) {
|
|
42451
|
+
MessageType2[MessageType2["Invocation"] = 1] = "Invocation";
|
|
42452
|
+
MessageType2[MessageType2["StreamItem"] = 2] = "StreamItem";
|
|
42453
|
+
MessageType2[MessageType2["Completion"] = 3] = "Completion";
|
|
42454
|
+
MessageType2[MessageType2["StreamInvocation"] = 4] = "StreamInvocation";
|
|
42455
|
+
MessageType2[MessageType2["CancelInvocation"] = 5] = "CancelInvocation";
|
|
42456
|
+
MessageType2[MessageType2["Ping"] = 6] = "Ping";
|
|
42457
|
+
MessageType2[MessageType2["Close"] = 7] = "Close";
|
|
42458
|
+
})(MessageType || (MessageType = {}));
|
|
42459
|
+
class Subject {
|
|
42460
|
+
constructor() {
|
|
42461
|
+
this.observers = [];
|
|
42462
|
+
}
|
|
42463
|
+
next(item) {
|
|
42464
|
+
for (const observer of this.observers) {
|
|
42465
|
+
observer.next(item);
|
|
42466
|
+
}
|
|
42467
|
+
}
|
|
42468
|
+
error(err) {
|
|
42469
|
+
for (const observer of this.observers) {
|
|
42470
|
+
if (observer.error) {
|
|
42471
|
+
observer.error(err);
|
|
42472
|
+
}
|
|
42473
|
+
}
|
|
42474
|
+
}
|
|
42475
|
+
complete() {
|
|
42476
|
+
for (const observer of this.observers) {
|
|
42477
|
+
if (observer.complete) {
|
|
42478
|
+
observer.complete();
|
|
42479
|
+
}
|
|
42480
|
+
}
|
|
42481
|
+
}
|
|
42482
|
+
subscribe(observer) {
|
|
42483
|
+
this.observers.push(observer);
|
|
42484
|
+
return new SubjectSubscription(this, observer);
|
|
42485
|
+
}
|
|
42486
|
+
}
|
|
42487
|
+
const DEFAULT_TIMEOUT_IN_MS = 30 * 1e3;
|
|
42488
|
+
const DEFAULT_PING_INTERVAL_IN_MS = 15 * 1e3;
|
|
42489
|
+
var HubConnectionState;
|
|
42490
|
+
(function(HubConnectionState2) {
|
|
42491
|
+
HubConnectionState2["Disconnected"] = "Disconnected";
|
|
42492
|
+
HubConnectionState2["Connecting"] = "Connecting";
|
|
42493
|
+
HubConnectionState2["Connected"] = "Connected";
|
|
42494
|
+
HubConnectionState2["Disconnecting"] = "Disconnecting";
|
|
42495
|
+
HubConnectionState2["Reconnecting"] = "Reconnecting";
|
|
42496
|
+
})(HubConnectionState || (HubConnectionState = {}));
|
|
42497
|
+
class HubConnection {
|
|
42498
|
+
constructor(connection, logger, protocol, reconnectPolicy) {
|
|
42499
|
+
this._nextKeepAlive = 0;
|
|
42500
|
+
this._freezeEventListener = () => {
|
|
42501
|
+
this._logger.log(LogLevel.Warning, "The page is being frozen, this will likely lead to the connection being closed and messages being lost. For more information see the docs at https://docs.microsoft.com/aspnet/core/signalr/javascript-client#bsleep");
|
|
42502
|
+
};
|
|
42503
|
+
Arg.isRequired(connection, "connection");
|
|
42504
|
+
Arg.isRequired(logger, "logger");
|
|
42505
|
+
Arg.isRequired(protocol, "protocol");
|
|
42506
|
+
this.serverTimeoutInMilliseconds = DEFAULT_TIMEOUT_IN_MS;
|
|
42507
|
+
this.keepAliveIntervalInMilliseconds = DEFAULT_PING_INTERVAL_IN_MS;
|
|
42508
|
+
this._logger = logger;
|
|
42509
|
+
this._protocol = protocol;
|
|
42510
|
+
this.connection = connection;
|
|
42511
|
+
this._reconnectPolicy = reconnectPolicy;
|
|
42512
|
+
this._handshakeProtocol = new HandshakeProtocol();
|
|
42513
|
+
this.connection.onreceive = (data2) => this._processIncomingData(data2);
|
|
42514
|
+
this.connection.onclose = (error2) => this._connectionClosed(error2);
|
|
42515
|
+
this._callbacks = {};
|
|
42516
|
+
this._methods = {};
|
|
42517
|
+
this._closedCallbacks = [];
|
|
42518
|
+
this._reconnectingCallbacks = [];
|
|
42519
|
+
this._reconnectedCallbacks = [];
|
|
42520
|
+
this._invocationId = 0;
|
|
42521
|
+
this._receivedHandshakeResponse = false;
|
|
42522
|
+
this._connectionState = HubConnectionState.Disconnected;
|
|
42523
|
+
this._connectionStarted = false;
|
|
42524
|
+
this._cachedPingMessage = this._protocol.writeMessage({ type: MessageType.Ping });
|
|
42525
|
+
}
|
|
42526
|
+
static create(connection, logger, protocol, reconnectPolicy) {
|
|
42527
|
+
return new HubConnection(connection, logger, protocol, reconnectPolicy);
|
|
42528
|
+
}
|
|
42529
|
+
get state() {
|
|
42530
|
+
return this._connectionState;
|
|
42531
|
+
}
|
|
42532
|
+
get connectionId() {
|
|
42533
|
+
return this.connection ? this.connection.connectionId || null : null;
|
|
42534
|
+
}
|
|
42535
|
+
get baseUrl() {
|
|
42536
|
+
return this.connection.baseUrl || "";
|
|
42537
|
+
}
|
|
42538
|
+
set baseUrl(url2) {
|
|
42539
|
+
if (this._connectionState !== HubConnectionState.Disconnected && this._connectionState !== HubConnectionState.Reconnecting) {
|
|
42540
|
+
throw new Error("The HubConnection must be in the Disconnected or Reconnecting state to change the url.");
|
|
42541
|
+
}
|
|
42542
|
+
if (!url2) {
|
|
42543
|
+
throw new Error("The HubConnection url must be a valid url.");
|
|
42544
|
+
}
|
|
42545
|
+
this.connection.baseUrl = url2;
|
|
42546
|
+
}
|
|
42547
|
+
start() {
|
|
42548
|
+
this._startPromise = this._startWithStateTransitions();
|
|
42549
|
+
return this._startPromise;
|
|
42550
|
+
}
|
|
42551
|
+
async _startWithStateTransitions() {
|
|
42552
|
+
if (this._connectionState !== HubConnectionState.Disconnected) {
|
|
42553
|
+
return Promise.reject(new Error("Cannot start a HubConnection that is not in the 'Disconnected' state."));
|
|
42554
|
+
}
|
|
42555
|
+
this._connectionState = HubConnectionState.Connecting;
|
|
42556
|
+
this._logger.log(LogLevel.Debug, "Starting HubConnection.");
|
|
42557
|
+
try {
|
|
42558
|
+
await this._startInternal();
|
|
42559
|
+
if (Platform.isBrowser) {
|
|
42560
|
+
window.document.addEventListener("freeze", this._freezeEventListener);
|
|
42561
|
+
}
|
|
42562
|
+
this._connectionState = HubConnectionState.Connected;
|
|
42563
|
+
this._connectionStarted = true;
|
|
42564
|
+
this._logger.log(LogLevel.Debug, "HubConnection connected successfully.");
|
|
42565
|
+
} catch (e2) {
|
|
42566
|
+
this._connectionState = HubConnectionState.Disconnected;
|
|
42567
|
+
this._logger.log(LogLevel.Debug, `HubConnection failed to start successfully because of error '${e2}'.`);
|
|
42568
|
+
return Promise.reject(e2);
|
|
42569
|
+
}
|
|
42570
|
+
}
|
|
42571
|
+
async _startInternal() {
|
|
42572
|
+
this._stopDuringStartError = void 0;
|
|
42573
|
+
this._receivedHandshakeResponse = false;
|
|
42574
|
+
const handshakePromise = new Promise((resolve, reject) => {
|
|
42575
|
+
this._handshakeResolver = resolve;
|
|
42576
|
+
this._handshakeRejecter = reject;
|
|
42577
|
+
});
|
|
42578
|
+
await this.connection.start(this._protocol.transferFormat);
|
|
42579
|
+
try {
|
|
42580
|
+
const handshakeRequest = {
|
|
42581
|
+
protocol: this._protocol.name,
|
|
42582
|
+
version: this._protocol.version
|
|
42583
|
+
};
|
|
42584
|
+
this._logger.log(LogLevel.Debug, "Sending handshake request.");
|
|
42585
|
+
await this._sendMessage(this._handshakeProtocol.writeHandshakeRequest(handshakeRequest));
|
|
42586
|
+
this._logger.log(LogLevel.Information, `Using HubProtocol '${this._protocol.name}'.`);
|
|
42587
|
+
this._cleanupTimeout();
|
|
42588
|
+
this._resetTimeoutPeriod();
|
|
42589
|
+
this._resetKeepAliveInterval();
|
|
42590
|
+
await handshakePromise;
|
|
42591
|
+
if (this._stopDuringStartError) {
|
|
42592
|
+
throw this._stopDuringStartError;
|
|
42593
|
+
}
|
|
42594
|
+
if (!this.connection.features.inherentKeepAlive) {
|
|
42595
|
+
await this._sendMessage(this._cachedPingMessage);
|
|
42596
|
+
}
|
|
42597
|
+
} catch (e2) {
|
|
42598
|
+
this._logger.log(LogLevel.Debug, `Hub handshake failed with error '${e2}' during start(). Stopping HubConnection.`);
|
|
42599
|
+
this._cleanupTimeout();
|
|
42600
|
+
this._cleanupPingTimer();
|
|
42601
|
+
await this.connection.stop(e2);
|
|
42602
|
+
throw e2;
|
|
42603
|
+
}
|
|
42604
|
+
}
|
|
42605
|
+
async stop() {
|
|
42606
|
+
const startPromise = this._startPromise;
|
|
42607
|
+
this._stopPromise = this._stopInternal();
|
|
42608
|
+
await this._stopPromise;
|
|
42609
|
+
try {
|
|
42610
|
+
await startPromise;
|
|
42611
|
+
} catch (e2) {
|
|
42612
|
+
}
|
|
42613
|
+
}
|
|
42614
|
+
_stopInternal(error2) {
|
|
42615
|
+
if (this._connectionState === HubConnectionState.Disconnected) {
|
|
42616
|
+
this._logger.log(LogLevel.Debug, `Call to HubConnection.stop(${error2}) ignored because it is already in the disconnected state.`);
|
|
42617
|
+
return Promise.resolve();
|
|
42618
|
+
}
|
|
42619
|
+
if (this._connectionState === HubConnectionState.Disconnecting) {
|
|
42620
|
+
this._logger.log(LogLevel.Debug, `Call to HttpConnection.stop(${error2}) ignored because the connection is already in the disconnecting state.`);
|
|
42621
|
+
return this._stopPromise;
|
|
42622
|
+
}
|
|
42623
|
+
this._connectionState = HubConnectionState.Disconnecting;
|
|
42624
|
+
this._logger.log(LogLevel.Debug, "Stopping HubConnection.");
|
|
42625
|
+
if (this._reconnectDelayHandle) {
|
|
42626
|
+
this._logger.log(LogLevel.Debug, "Connection stopped during reconnect delay. Done reconnecting.");
|
|
42627
|
+
clearTimeout(this._reconnectDelayHandle);
|
|
42628
|
+
this._reconnectDelayHandle = void 0;
|
|
42629
|
+
this._completeClose();
|
|
42630
|
+
return Promise.resolve();
|
|
42631
|
+
}
|
|
42632
|
+
this._cleanupTimeout();
|
|
42633
|
+
this._cleanupPingTimer();
|
|
42634
|
+
this._stopDuringStartError = error2 || new AbortError("The connection was stopped before the hub handshake could complete.");
|
|
42635
|
+
return this.connection.stop(error2);
|
|
42636
|
+
}
|
|
42637
|
+
stream(methodName, ...args) {
|
|
42638
|
+
const [streams, streamIds] = this._replaceStreamingParams(args);
|
|
42639
|
+
const invocationDescriptor = this._createStreamInvocation(methodName, args, streamIds);
|
|
42640
|
+
let promiseQueue;
|
|
42641
|
+
const subject = new Subject();
|
|
42642
|
+
subject.cancelCallback = () => {
|
|
42643
|
+
const cancelInvocation = this._createCancelInvocation(invocationDescriptor.invocationId);
|
|
42644
|
+
delete this._callbacks[invocationDescriptor.invocationId];
|
|
42645
|
+
return promiseQueue.then(() => {
|
|
42646
|
+
return this._sendWithProtocol(cancelInvocation);
|
|
42647
|
+
});
|
|
42648
|
+
};
|
|
42649
|
+
this._callbacks[invocationDescriptor.invocationId] = (invocationEvent, error2) => {
|
|
42650
|
+
if (error2) {
|
|
42651
|
+
subject.error(error2);
|
|
42652
|
+
return;
|
|
42653
|
+
} else if (invocationEvent) {
|
|
42654
|
+
if (invocationEvent.type === MessageType.Completion) {
|
|
42655
|
+
if (invocationEvent.error) {
|
|
42656
|
+
subject.error(new Error(invocationEvent.error));
|
|
42657
|
+
} else {
|
|
42658
|
+
subject.complete();
|
|
42659
|
+
}
|
|
42660
|
+
} else {
|
|
42661
|
+
subject.next(invocationEvent.item);
|
|
42662
|
+
}
|
|
42663
|
+
}
|
|
42664
|
+
};
|
|
42665
|
+
promiseQueue = this._sendWithProtocol(invocationDescriptor).catch((e2) => {
|
|
42666
|
+
subject.error(e2);
|
|
42667
|
+
delete this._callbacks[invocationDescriptor.invocationId];
|
|
42668
|
+
});
|
|
42669
|
+
this._launchStreams(streams, promiseQueue);
|
|
42670
|
+
return subject;
|
|
42671
|
+
}
|
|
42672
|
+
_sendMessage(message2) {
|
|
42673
|
+
this._resetKeepAliveInterval();
|
|
42674
|
+
return this.connection.send(message2);
|
|
42675
|
+
}
|
|
42676
|
+
_sendWithProtocol(message2) {
|
|
42677
|
+
return this._sendMessage(this._protocol.writeMessage(message2));
|
|
42678
|
+
}
|
|
42679
|
+
send(methodName, ...args) {
|
|
42680
|
+
const [streams, streamIds] = this._replaceStreamingParams(args);
|
|
42681
|
+
const sendPromise = this._sendWithProtocol(this._createInvocation(methodName, args, true, streamIds));
|
|
42682
|
+
this._launchStreams(streams, sendPromise);
|
|
42683
|
+
return sendPromise;
|
|
42684
|
+
}
|
|
42685
|
+
invoke(methodName, ...args) {
|
|
42686
|
+
const [streams, streamIds] = this._replaceStreamingParams(args);
|
|
42687
|
+
const invocationDescriptor = this._createInvocation(methodName, args, false, streamIds);
|
|
42688
|
+
const p2 = new Promise((resolve, reject) => {
|
|
42689
|
+
this._callbacks[invocationDescriptor.invocationId] = (invocationEvent, error2) => {
|
|
42690
|
+
if (error2) {
|
|
42691
|
+
reject(error2);
|
|
42692
|
+
return;
|
|
42693
|
+
} else if (invocationEvent) {
|
|
42694
|
+
if (invocationEvent.type === MessageType.Completion) {
|
|
42695
|
+
if (invocationEvent.error) {
|
|
42696
|
+
reject(new Error(invocationEvent.error));
|
|
42697
|
+
} else {
|
|
42698
|
+
resolve(invocationEvent.result);
|
|
42699
|
+
}
|
|
42700
|
+
} else {
|
|
42701
|
+
reject(new Error(`Unexpected message type: ${invocationEvent.type}`));
|
|
42702
|
+
}
|
|
42703
|
+
}
|
|
42704
|
+
};
|
|
42705
|
+
const promiseQueue = this._sendWithProtocol(invocationDescriptor).catch((e2) => {
|
|
42706
|
+
reject(e2);
|
|
42707
|
+
delete this._callbacks[invocationDescriptor.invocationId];
|
|
42708
|
+
});
|
|
42709
|
+
this._launchStreams(streams, promiseQueue);
|
|
42710
|
+
});
|
|
42711
|
+
return p2;
|
|
42712
|
+
}
|
|
42713
|
+
on(methodName, newMethod) {
|
|
42714
|
+
if (!methodName || !newMethod) {
|
|
42715
|
+
return;
|
|
42716
|
+
}
|
|
42717
|
+
methodName = methodName.toLowerCase();
|
|
42718
|
+
if (!this._methods[methodName]) {
|
|
42719
|
+
this._methods[methodName] = [];
|
|
42720
|
+
}
|
|
42721
|
+
if (this._methods[methodName].indexOf(newMethod) !== -1) {
|
|
42722
|
+
return;
|
|
42723
|
+
}
|
|
42724
|
+
this._methods[methodName].push(newMethod);
|
|
42725
|
+
}
|
|
42726
|
+
off(methodName, method4) {
|
|
42727
|
+
if (!methodName) {
|
|
42728
|
+
return;
|
|
42729
|
+
}
|
|
42730
|
+
methodName = methodName.toLowerCase();
|
|
42731
|
+
const handlers = this._methods[methodName];
|
|
42732
|
+
if (!handlers) {
|
|
42733
|
+
return;
|
|
42734
|
+
}
|
|
42735
|
+
if (method4) {
|
|
42736
|
+
const removeIdx = handlers.indexOf(method4);
|
|
42737
|
+
if (removeIdx !== -1) {
|
|
42738
|
+
handlers.splice(removeIdx, 1);
|
|
42739
|
+
if (handlers.length === 0) {
|
|
42740
|
+
delete this._methods[methodName];
|
|
42741
|
+
}
|
|
42742
|
+
}
|
|
42743
|
+
} else {
|
|
42744
|
+
delete this._methods[methodName];
|
|
42745
|
+
}
|
|
42746
|
+
}
|
|
42747
|
+
onclose(callback) {
|
|
42748
|
+
if (callback) {
|
|
42749
|
+
this._closedCallbacks.push(callback);
|
|
42750
|
+
}
|
|
42751
|
+
}
|
|
42752
|
+
onreconnecting(callback) {
|
|
42753
|
+
if (callback) {
|
|
42754
|
+
this._reconnectingCallbacks.push(callback);
|
|
42755
|
+
}
|
|
42756
|
+
}
|
|
42757
|
+
onreconnected(callback) {
|
|
42758
|
+
if (callback) {
|
|
42759
|
+
this._reconnectedCallbacks.push(callback);
|
|
42760
|
+
}
|
|
42761
|
+
}
|
|
42762
|
+
_processIncomingData(data2) {
|
|
42763
|
+
this._cleanupTimeout();
|
|
42764
|
+
if (!this._receivedHandshakeResponse) {
|
|
42765
|
+
data2 = this._processHandshakeResponse(data2);
|
|
42766
|
+
this._receivedHandshakeResponse = true;
|
|
42767
|
+
}
|
|
42768
|
+
if (data2) {
|
|
42769
|
+
const messages2 = this._protocol.parseMessages(data2, this._logger);
|
|
42770
|
+
for (const message2 of messages2) {
|
|
42771
|
+
switch (message2.type) {
|
|
42772
|
+
case MessageType.Invocation:
|
|
42773
|
+
this._invokeClientMethod(message2);
|
|
42774
|
+
break;
|
|
42775
|
+
case MessageType.StreamItem:
|
|
42776
|
+
case MessageType.Completion: {
|
|
42777
|
+
const callback = this._callbacks[message2.invocationId];
|
|
42778
|
+
if (callback) {
|
|
42779
|
+
if (message2.type === MessageType.Completion) {
|
|
42780
|
+
delete this._callbacks[message2.invocationId];
|
|
42781
|
+
}
|
|
42782
|
+
try {
|
|
42783
|
+
callback(message2);
|
|
42784
|
+
} catch (e2) {
|
|
42785
|
+
this._logger.log(LogLevel.Error, `Stream callback threw error: ${getErrorString(e2)}`);
|
|
42786
|
+
}
|
|
42787
|
+
}
|
|
42788
|
+
break;
|
|
42789
|
+
}
|
|
42790
|
+
case MessageType.Ping:
|
|
42791
|
+
break;
|
|
42792
|
+
case MessageType.Close: {
|
|
42793
|
+
this._logger.log(LogLevel.Information, "Close message received from server.");
|
|
42794
|
+
const error2 = message2.error ? new Error("Server returned an error on close: " + message2.error) : void 0;
|
|
42795
|
+
if (message2.allowReconnect === true) {
|
|
42796
|
+
this.connection.stop(error2);
|
|
42797
|
+
} else {
|
|
42798
|
+
this._stopPromise = this._stopInternal(error2);
|
|
42799
|
+
}
|
|
42800
|
+
break;
|
|
42801
|
+
}
|
|
42802
|
+
default:
|
|
42803
|
+
this._logger.log(LogLevel.Warning, `Invalid message type: ${message2.type}.`);
|
|
42804
|
+
break;
|
|
42805
|
+
}
|
|
42806
|
+
}
|
|
42807
|
+
}
|
|
42808
|
+
this._resetTimeoutPeriod();
|
|
42809
|
+
}
|
|
42810
|
+
_processHandshakeResponse(data2) {
|
|
42811
|
+
let responseMessage;
|
|
42812
|
+
let remainingData;
|
|
42813
|
+
try {
|
|
42814
|
+
[remainingData, responseMessage] = this._handshakeProtocol.parseHandshakeResponse(data2);
|
|
42815
|
+
} catch (e2) {
|
|
42816
|
+
const message2 = "Error parsing handshake response: " + e2;
|
|
42817
|
+
this._logger.log(LogLevel.Error, message2);
|
|
42818
|
+
const error2 = new Error(message2);
|
|
42819
|
+
this._handshakeRejecter(error2);
|
|
42820
|
+
throw error2;
|
|
42821
|
+
}
|
|
42822
|
+
if (responseMessage.error) {
|
|
42823
|
+
const message2 = "Server returned handshake error: " + responseMessage.error;
|
|
42824
|
+
this._logger.log(LogLevel.Error, message2);
|
|
42825
|
+
const error2 = new Error(message2);
|
|
42826
|
+
this._handshakeRejecter(error2);
|
|
42827
|
+
throw error2;
|
|
42828
|
+
} else {
|
|
42829
|
+
this._logger.log(LogLevel.Debug, "Server handshake complete.");
|
|
42830
|
+
}
|
|
42831
|
+
this._handshakeResolver();
|
|
42832
|
+
return remainingData;
|
|
42833
|
+
}
|
|
42834
|
+
_resetKeepAliveInterval() {
|
|
42835
|
+
if (this.connection.features.inherentKeepAlive) {
|
|
42836
|
+
return;
|
|
42837
|
+
}
|
|
42838
|
+
this._nextKeepAlive = new Date().getTime() + this.keepAliveIntervalInMilliseconds;
|
|
42839
|
+
this._cleanupPingTimer();
|
|
42840
|
+
}
|
|
42841
|
+
_resetTimeoutPeriod() {
|
|
42842
|
+
if (!this.connection.features || !this.connection.features.inherentKeepAlive) {
|
|
42843
|
+
this._timeoutHandle = setTimeout(() => this.serverTimeout(), this.serverTimeoutInMilliseconds);
|
|
42844
|
+
if (this._pingServerHandle === void 0) {
|
|
42845
|
+
let nextPing = this._nextKeepAlive - new Date().getTime();
|
|
42846
|
+
if (nextPing < 0) {
|
|
42847
|
+
nextPing = 0;
|
|
42848
|
+
}
|
|
42849
|
+
this._pingServerHandle = setTimeout(async () => {
|
|
42850
|
+
if (this._connectionState === HubConnectionState.Connected) {
|
|
42851
|
+
try {
|
|
42852
|
+
await this._sendMessage(this._cachedPingMessage);
|
|
42853
|
+
} catch {
|
|
42854
|
+
this._cleanupPingTimer();
|
|
42855
|
+
}
|
|
42856
|
+
}
|
|
42857
|
+
}, nextPing);
|
|
42858
|
+
}
|
|
42859
|
+
}
|
|
42860
|
+
}
|
|
42861
|
+
serverTimeout() {
|
|
42862
|
+
this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server."));
|
|
42863
|
+
}
|
|
42864
|
+
async _invokeClientMethod(invocationMessage) {
|
|
42865
|
+
const methodName = invocationMessage.target.toLowerCase();
|
|
42866
|
+
const methods = this._methods[methodName];
|
|
42867
|
+
if (!methods) {
|
|
42868
|
+
this._logger.log(LogLevel.Warning, `No client method with the name '${methodName}' found.`);
|
|
42869
|
+
if (invocationMessage.invocationId) {
|
|
42870
|
+
this._logger.log(LogLevel.Warning, `No result given for '${methodName}' method and invocation ID '${invocationMessage.invocationId}'.`);
|
|
42871
|
+
await this._sendWithProtocol(this._createCompletionMessage(invocationMessage.invocationId, "Client didn't provide a result.", null));
|
|
42872
|
+
}
|
|
42873
|
+
return;
|
|
42874
|
+
}
|
|
42875
|
+
const methodsCopy = methods.slice();
|
|
42876
|
+
const expectsResponse = invocationMessage.invocationId ? true : false;
|
|
42877
|
+
let res;
|
|
42878
|
+
let exception;
|
|
42879
|
+
let completionMessage;
|
|
42880
|
+
for (const m2 of methodsCopy) {
|
|
42881
|
+
try {
|
|
42882
|
+
const prevRes = res;
|
|
42883
|
+
res = await m2.apply(this, invocationMessage.arguments);
|
|
42884
|
+
if (expectsResponse && res && prevRes) {
|
|
42885
|
+
this._logger.log(LogLevel.Error, `Multiple results provided for '${methodName}'. Sending error to server.`);
|
|
42886
|
+
completionMessage = this._createCompletionMessage(invocationMessage.invocationId, `Client provided multiple results.`, null);
|
|
42887
|
+
}
|
|
42888
|
+
exception = void 0;
|
|
42889
|
+
} catch (e2) {
|
|
42890
|
+
exception = e2;
|
|
42891
|
+
this._logger.log(LogLevel.Error, `A callback for the method '${methodName}' threw error '${e2}'.`);
|
|
42892
|
+
}
|
|
42893
|
+
}
|
|
42894
|
+
if (completionMessage) {
|
|
42895
|
+
await this._sendWithProtocol(completionMessage);
|
|
42896
|
+
} else if (expectsResponse) {
|
|
42897
|
+
if (exception) {
|
|
42898
|
+
completionMessage = this._createCompletionMessage(invocationMessage.invocationId, `${exception}`, null);
|
|
42899
|
+
} else if (res !== void 0) {
|
|
42900
|
+
completionMessage = this._createCompletionMessage(invocationMessage.invocationId, null, res);
|
|
42901
|
+
} else {
|
|
42902
|
+
this._logger.log(LogLevel.Warning, `No result given for '${methodName}' method and invocation ID '${invocationMessage.invocationId}'.`);
|
|
42903
|
+
completionMessage = this._createCompletionMessage(invocationMessage.invocationId, "Client didn't provide a result.", null);
|
|
42904
|
+
}
|
|
42905
|
+
await this._sendWithProtocol(completionMessage);
|
|
42906
|
+
} else {
|
|
42907
|
+
if (res) {
|
|
42908
|
+
this._logger.log(LogLevel.Error, `Result given for '${methodName}' method but server is not expecting a result.`);
|
|
42909
|
+
}
|
|
42910
|
+
}
|
|
42911
|
+
}
|
|
42912
|
+
_connectionClosed(error2) {
|
|
42913
|
+
this._logger.log(LogLevel.Debug, `HubConnection.connectionClosed(${error2}) called while in state ${this._connectionState}.`);
|
|
42914
|
+
this._stopDuringStartError = this._stopDuringStartError || error2 || new AbortError("The underlying connection was closed before the hub handshake could complete.");
|
|
42915
|
+
if (this._handshakeResolver) {
|
|
42916
|
+
this._handshakeResolver();
|
|
42917
|
+
}
|
|
42918
|
+
this._cancelCallbacksWithError(error2 || new Error("Invocation canceled due to the underlying connection being closed."));
|
|
42919
|
+
this._cleanupTimeout();
|
|
42920
|
+
this._cleanupPingTimer();
|
|
42921
|
+
if (this._connectionState === HubConnectionState.Disconnecting) {
|
|
42922
|
+
this._completeClose(error2);
|
|
42923
|
+
} else if (this._connectionState === HubConnectionState.Connected && this._reconnectPolicy) {
|
|
42924
|
+
this._reconnect(error2);
|
|
42925
|
+
} else if (this._connectionState === HubConnectionState.Connected) {
|
|
42926
|
+
this._completeClose(error2);
|
|
42927
|
+
}
|
|
42928
|
+
}
|
|
42929
|
+
_completeClose(error2) {
|
|
42930
|
+
if (this._connectionStarted) {
|
|
42931
|
+
this._connectionState = HubConnectionState.Disconnected;
|
|
42932
|
+
this._connectionStarted = false;
|
|
42933
|
+
if (Platform.isBrowser) {
|
|
42934
|
+
window.document.removeEventListener("freeze", this._freezeEventListener);
|
|
42935
|
+
}
|
|
42936
|
+
try {
|
|
42937
|
+
this._closedCallbacks.forEach((c2) => c2.apply(this, [error2]));
|
|
42938
|
+
} catch (e2) {
|
|
42939
|
+
this._logger.log(LogLevel.Error, `An onclose callback called with error '${error2}' threw error '${e2}'.`);
|
|
42940
|
+
}
|
|
42941
|
+
}
|
|
42942
|
+
}
|
|
42943
|
+
async _reconnect(error2) {
|
|
42944
|
+
const reconnectStartTime = Date.now();
|
|
42945
|
+
let previousReconnectAttempts = 0;
|
|
42946
|
+
let retryError = error2 !== void 0 ? error2 : new Error("Attempting to reconnect due to a unknown error.");
|
|
42947
|
+
let nextRetryDelay = this._getNextRetryDelay(previousReconnectAttempts++, 0, retryError);
|
|
42948
|
+
if (nextRetryDelay === null) {
|
|
42949
|
+
this._logger.log(LogLevel.Debug, "Connection not reconnecting because the IRetryPolicy returned null on the first reconnect attempt.");
|
|
42950
|
+
this._completeClose(error2);
|
|
42951
|
+
return;
|
|
42952
|
+
}
|
|
42953
|
+
this._connectionState = HubConnectionState.Reconnecting;
|
|
42954
|
+
if (error2) {
|
|
42955
|
+
this._logger.log(LogLevel.Information, `Connection reconnecting because of error '${error2}'.`);
|
|
42956
|
+
} else {
|
|
42957
|
+
this._logger.log(LogLevel.Information, "Connection reconnecting.");
|
|
42958
|
+
}
|
|
42959
|
+
if (this._reconnectingCallbacks.length !== 0) {
|
|
42960
|
+
try {
|
|
42961
|
+
this._reconnectingCallbacks.forEach((c2) => c2.apply(this, [error2]));
|
|
42962
|
+
} catch (e2) {
|
|
42963
|
+
this._logger.log(LogLevel.Error, `An onreconnecting callback called with error '${error2}' threw error '${e2}'.`);
|
|
42964
|
+
}
|
|
42965
|
+
if (this._connectionState !== HubConnectionState.Reconnecting) {
|
|
42966
|
+
this._logger.log(LogLevel.Debug, "Connection left the reconnecting state in onreconnecting callback. Done reconnecting.");
|
|
42967
|
+
return;
|
|
42968
|
+
}
|
|
42969
|
+
}
|
|
42970
|
+
while (nextRetryDelay !== null) {
|
|
42971
|
+
this._logger.log(LogLevel.Information, `Reconnect attempt number ${previousReconnectAttempts} will start in ${nextRetryDelay} ms.`);
|
|
42972
|
+
await new Promise((resolve) => {
|
|
42973
|
+
this._reconnectDelayHandle = setTimeout(resolve, nextRetryDelay);
|
|
42974
|
+
});
|
|
42975
|
+
this._reconnectDelayHandle = void 0;
|
|
42976
|
+
if (this._connectionState !== HubConnectionState.Reconnecting) {
|
|
42977
|
+
this._logger.log(LogLevel.Debug, "Connection left the reconnecting state during reconnect delay. Done reconnecting.");
|
|
42978
|
+
return;
|
|
42979
|
+
}
|
|
42980
|
+
try {
|
|
42981
|
+
await this._startInternal();
|
|
42982
|
+
this._connectionState = HubConnectionState.Connected;
|
|
42983
|
+
this._logger.log(LogLevel.Information, "HubConnection reconnected successfully.");
|
|
42984
|
+
if (this._reconnectedCallbacks.length !== 0) {
|
|
42985
|
+
try {
|
|
42986
|
+
this._reconnectedCallbacks.forEach((c2) => c2.apply(this, [this.connection.connectionId]));
|
|
42987
|
+
} catch (e2) {
|
|
42988
|
+
this._logger.log(LogLevel.Error, `An onreconnected callback called with connectionId '${this.connection.connectionId}; threw error '${e2}'.`);
|
|
42989
|
+
}
|
|
42990
|
+
}
|
|
42991
|
+
return;
|
|
42992
|
+
} catch (e2) {
|
|
42993
|
+
this._logger.log(LogLevel.Information, `Reconnect attempt failed because of error '${e2}'.`);
|
|
42994
|
+
if (this._connectionState !== HubConnectionState.Reconnecting) {
|
|
42995
|
+
this._logger.log(LogLevel.Debug, `Connection moved to the '${this._connectionState}' from the reconnecting state during reconnect attempt. Done reconnecting.`);
|
|
42996
|
+
if (this._connectionState === HubConnectionState.Disconnecting) {
|
|
42997
|
+
this._completeClose();
|
|
42998
|
+
}
|
|
42999
|
+
return;
|
|
43000
|
+
}
|
|
43001
|
+
retryError = e2 instanceof Error ? e2 : new Error(e2.toString());
|
|
43002
|
+
nextRetryDelay = this._getNextRetryDelay(previousReconnectAttempts++, Date.now() - reconnectStartTime, retryError);
|
|
43003
|
+
}
|
|
43004
|
+
}
|
|
43005
|
+
this._logger.log(LogLevel.Information, `Reconnect retries have been exhausted after ${Date.now() - reconnectStartTime} ms and ${previousReconnectAttempts} failed attempts. Connection disconnecting.`);
|
|
43006
|
+
this._completeClose();
|
|
43007
|
+
}
|
|
43008
|
+
_getNextRetryDelay(previousRetryCount, elapsedMilliseconds, retryReason) {
|
|
43009
|
+
try {
|
|
43010
|
+
return this._reconnectPolicy.nextRetryDelayInMilliseconds({
|
|
43011
|
+
elapsedMilliseconds,
|
|
43012
|
+
previousRetryCount,
|
|
43013
|
+
retryReason
|
|
43014
|
+
});
|
|
43015
|
+
} catch (e2) {
|
|
43016
|
+
this._logger.log(LogLevel.Error, `IRetryPolicy.nextRetryDelayInMilliseconds(${previousRetryCount}, ${elapsedMilliseconds}) threw error '${e2}'.`);
|
|
43017
|
+
return null;
|
|
43018
|
+
}
|
|
43019
|
+
}
|
|
43020
|
+
_cancelCallbacksWithError(error2) {
|
|
43021
|
+
const callbacks = this._callbacks;
|
|
43022
|
+
this._callbacks = {};
|
|
43023
|
+
Object.keys(callbacks).forEach((key) => {
|
|
43024
|
+
const callback = callbacks[key];
|
|
43025
|
+
try {
|
|
43026
|
+
callback(null, error2);
|
|
43027
|
+
} catch (e2) {
|
|
43028
|
+
this._logger.log(LogLevel.Error, `Stream 'error' callback called with '${error2}' threw error: ${getErrorString(e2)}`);
|
|
43029
|
+
}
|
|
43030
|
+
});
|
|
43031
|
+
}
|
|
43032
|
+
_cleanupPingTimer() {
|
|
43033
|
+
if (this._pingServerHandle) {
|
|
43034
|
+
clearTimeout(this._pingServerHandle);
|
|
43035
|
+
this._pingServerHandle = void 0;
|
|
43036
|
+
}
|
|
43037
|
+
}
|
|
43038
|
+
_cleanupTimeout() {
|
|
43039
|
+
if (this._timeoutHandle) {
|
|
43040
|
+
clearTimeout(this._timeoutHandle);
|
|
43041
|
+
}
|
|
43042
|
+
}
|
|
43043
|
+
_createInvocation(methodName, args, nonblocking, streamIds) {
|
|
43044
|
+
if (nonblocking) {
|
|
43045
|
+
if (streamIds.length !== 0) {
|
|
43046
|
+
return {
|
|
43047
|
+
arguments: args,
|
|
43048
|
+
streamIds,
|
|
43049
|
+
target: methodName,
|
|
43050
|
+
type: MessageType.Invocation
|
|
43051
|
+
};
|
|
43052
|
+
} else {
|
|
43053
|
+
return {
|
|
43054
|
+
arguments: args,
|
|
43055
|
+
target: methodName,
|
|
43056
|
+
type: MessageType.Invocation
|
|
43057
|
+
};
|
|
43058
|
+
}
|
|
43059
|
+
} else {
|
|
43060
|
+
const invocationId = this._invocationId;
|
|
43061
|
+
this._invocationId++;
|
|
43062
|
+
if (streamIds.length !== 0) {
|
|
43063
|
+
return {
|
|
43064
|
+
arguments: args,
|
|
43065
|
+
invocationId: invocationId.toString(),
|
|
43066
|
+
streamIds,
|
|
43067
|
+
target: methodName,
|
|
43068
|
+
type: MessageType.Invocation
|
|
43069
|
+
};
|
|
43070
|
+
} else {
|
|
43071
|
+
return {
|
|
43072
|
+
arguments: args,
|
|
43073
|
+
invocationId: invocationId.toString(),
|
|
43074
|
+
target: methodName,
|
|
43075
|
+
type: MessageType.Invocation
|
|
43076
|
+
};
|
|
43077
|
+
}
|
|
43078
|
+
}
|
|
43079
|
+
}
|
|
43080
|
+
_launchStreams(streams, promiseQueue) {
|
|
43081
|
+
if (streams.length === 0) {
|
|
43082
|
+
return;
|
|
43083
|
+
}
|
|
43084
|
+
if (!promiseQueue) {
|
|
43085
|
+
promiseQueue = Promise.resolve();
|
|
43086
|
+
}
|
|
43087
|
+
for (const streamId in streams) {
|
|
43088
|
+
streams[streamId].subscribe({
|
|
43089
|
+
complete: () => {
|
|
43090
|
+
promiseQueue = promiseQueue.then(() => this._sendWithProtocol(this._createCompletionMessage(streamId)));
|
|
43091
|
+
},
|
|
43092
|
+
error: (err) => {
|
|
43093
|
+
let message2;
|
|
43094
|
+
if (err instanceof Error) {
|
|
43095
|
+
message2 = err.message;
|
|
43096
|
+
} else if (err && err.toString) {
|
|
43097
|
+
message2 = err.toString();
|
|
43098
|
+
} else {
|
|
43099
|
+
message2 = "Unknown error";
|
|
43100
|
+
}
|
|
43101
|
+
promiseQueue = promiseQueue.then(() => this._sendWithProtocol(this._createCompletionMessage(streamId, message2)));
|
|
43102
|
+
},
|
|
43103
|
+
next: (item) => {
|
|
43104
|
+
promiseQueue = promiseQueue.then(() => this._sendWithProtocol(this._createStreamItemMessage(streamId, item)));
|
|
43105
|
+
}
|
|
43106
|
+
});
|
|
43107
|
+
}
|
|
43108
|
+
}
|
|
43109
|
+
_replaceStreamingParams(args) {
|
|
43110
|
+
const streams = [];
|
|
43111
|
+
const streamIds = [];
|
|
43112
|
+
for (let i2 = 0; i2 < args.length; i2++) {
|
|
43113
|
+
const argument = args[i2];
|
|
43114
|
+
if (this._isObservable(argument)) {
|
|
43115
|
+
const streamId = this._invocationId;
|
|
43116
|
+
this._invocationId++;
|
|
43117
|
+
streams[streamId] = argument;
|
|
43118
|
+
streamIds.push(streamId.toString());
|
|
43119
|
+
args.splice(i2, 1);
|
|
43120
|
+
}
|
|
43121
|
+
}
|
|
43122
|
+
return [streams, streamIds];
|
|
43123
|
+
}
|
|
43124
|
+
_isObservable(arg) {
|
|
43125
|
+
return arg && arg.subscribe && typeof arg.subscribe === "function";
|
|
43126
|
+
}
|
|
43127
|
+
_createStreamInvocation(methodName, args, streamIds) {
|
|
43128
|
+
const invocationId = this._invocationId;
|
|
43129
|
+
this._invocationId++;
|
|
43130
|
+
if (streamIds.length !== 0) {
|
|
43131
|
+
return {
|
|
43132
|
+
arguments: args,
|
|
43133
|
+
invocationId: invocationId.toString(),
|
|
43134
|
+
streamIds,
|
|
43135
|
+
target: methodName,
|
|
43136
|
+
type: MessageType.StreamInvocation
|
|
43137
|
+
};
|
|
43138
|
+
} else {
|
|
43139
|
+
return {
|
|
43140
|
+
arguments: args,
|
|
43141
|
+
invocationId: invocationId.toString(),
|
|
43142
|
+
target: methodName,
|
|
43143
|
+
type: MessageType.StreamInvocation
|
|
43144
|
+
};
|
|
43145
|
+
}
|
|
43146
|
+
}
|
|
43147
|
+
_createCancelInvocation(id) {
|
|
43148
|
+
return {
|
|
43149
|
+
invocationId: id,
|
|
43150
|
+
type: MessageType.CancelInvocation
|
|
43151
|
+
};
|
|
43152
|
+
}
|
|
43153
|
+
_createStreamItemMessage(id, item) {
|
|
43154
|
+
return {
|
|
43155
|
+
invocationId: id,
|
|
43156
|
+
item,
|
|
43157
|
+
type: MessageType.StreamItem
|
|
43158
|
+
};
|
|
43159
|
+
}
|
|
43160
|
+
_createCompletionMessage(id, error2, result) {
|
|
43161
|
+
if (error2) {
|
|
43162
|
+
return {
|
|
43163
|
+
error: error2,
|
|
43164
|
+
invocationId: id,
|
|
43165
|
+
type: MessageType.Completion
|
|
43166
|
+
};
|
|
43167
|
+
}
|
|
43168
|
+
return {
|
|
43169
|
+
invocationId: id,
|
|
43170
|
+
result,
|
|
43171
|
+
type: MessageType.Completion
|
|
43172
|
+
};
|
|
43173
|
+
}
|
|
43174
|
+
}
|
|
43175
|
+
const DEFAULT_RETRY_DELAYS_IN_MILLISECONDS = [0, 2e3, 1e4, 3e4, null];
|
|
43176
|
+
class DefaultReconnectPolicy {
|
|
43177
|
+
constructor(retryDelays) {
|
|
43178
|
+
this._retryDelays = retryDelays !== void 0 ? [...retryDelays, null] : DEFAULT_RETRY_DELAYS_IN_MILLISECONDS;
|
|
43179
|
+
}
|
|
43180
|
+
nextRetryDelayInMilliseconds(retryContext) {
|
|
43181
|
+
return this._retryDelays[retryContext.previousRetryCount];
|
|
43182
|
+
}
|
|
43183
|
+
}
|
|
43184
|
+
class HeaderNames {
|
|
43185
|
+
}
|
|
43186
|
+
HeaderNames.Authorization = "Authorization";
|
|
43187
|
+
HeaderNames.Cookie = "Cookie";
|
|
43188
|
+
class AccessTokenHttpClient extends HttpClient {
|
|
43189
|
+
constructor(innerClient, accessTokenFactory) {
|
|
43190
|
+
super();
|
|
43191
|
+
this._innerClient = innerClient;
|
|
43192
|
+
this._accessTokenFactory = accessTokenFactory;
|
|
43193
|
+
}
|
|
43194
|
+
async send(request2) {
|
|
43195
|
+
let allowRetry = true;
|
|
43196
|
+
if (this._accessTokenFactory && (!this._accessToken || request2.url && request2.url.indexOf("/negotiate?") > 0)) {
|
|
43197
|
+
allowRetry = false;
|
|
43198
|
+
this._accessToken = await this._accessTokenFactory();
|
|
43199
|
+
}
|
|
43200
|
+
this._setAuthorizationHeader(request2);
|
|
43201
|
+
const response2 = await this._innerClient.send(request2);
|
|
43202
|
+
if (allowRetry && response2.statusCode === 401 && this._accessTokenFactory) {
|
|
43203
|
+
this._accessToken = await this._accessTokenFactory();
|
|
43204
|
+
this._setAuthorizationHeader(request2);
|
|
43205
|
+
return await this._innerClient.send(request2);
|
|
43206
|
+
}
|
|
43207
|
+
return response2;
|
|
43208
|
+
}
|
|
43209
|
+
_setAuthorizationHeader(request2) {
|
|
43210
|
+
if (!request2.headers) {
|
|
43211
|
+
request2.headers = {};
|
|
43212
|
+
}
|
|
43213
|
+
if (this._accessToken) {
|
|
43214
|
+
request2.headers[HeaderNames.Authorization] = `Bearer ${this._accessToken}`;
|
|
43215
|
+
} else if (this._accessTokenFactory) {
|
|
43216
|
+
if (request2.headers[HeaderNames.Authorization]) {
|
|
43217
|
+
delete request2.headers[HeaderNames.Authorization];
|
|
43218
|
+
}
|
|
43219
|
+
}
|
|
43220
|
+
}
|
|
43221
|
+
getCookieString(url2) {
|
|
43222
|
+
return this._innerClient.getCookieString(url2);
|
|
43223
|
+
}
|
|
43224
|
+
}
|
|
43225
|
+
var HttpTransportType;
|
|
43226
|
+
(function(HttpTransportType2) {
|
|
43227
|
+
HttpTransportType2[HttpTransportType2["None"] = 0] = "None";
|
|
43228
|
+
HttpTransportType2[HttpTransportType2["WebSockets"] = 1] = "WebSockets";
|
|
43229
|
+
HttpTransportType2[HttpTransportType2["ServerSentEvents"] = 2] = "ServerSentEvents";
|
|
43230
|
+
HttpTransportType2[HttpTransportType2["LongPolling"] = 4] = "LongPolling";
|
|
43231
|
+
})(HttpTransportType || (HttpTransportType = {}));
|
|
43232
|
+
var TransferFormat;
|
|
43233
|
+
(function(TransferFormat2) {
|
|
43234
|
+
TransferFormat2[TransferFormat2["Text"] = 1] = "Text";
|
|
43235
|
+
TransferFormat2[TransferFormat2["Binary"] = 2] = "Binary";
|
|
43236
|
+
})(TransferFormat || (TransferFormat = {}));
|
|
43237
|
+
class AbortController$1 {
|
|
43238
|
+
constructor() {
|
|
43239
|
+
this._isAborted = false;
|
|
43240
|
+
this.onabort = null;
|
|
43241
|
+
}
|
|
43242
|
+
abort() {
|
|
43243
|
+
if (!this._isAborted) {
|
|
43244
|
+
this._isAborted = true;
|
|
43245
|
+
if (this.onabort) {
|
|
43246
|
+
this.onabort();
|
|
43247
|
+
}
|
|
43248
|
+
}
|
|
43249
|
+
}
|
|
43250
|
+
get signal() {
|
|
43251
|
+
return this;
|
|
43252
|
+
}
|
|
43253
|
+
get aborted() {
|
|
43254
|
+
return this._isAborted;
|
|
43255
|
+
}
|
|
43256
|
+
}
|
|
43257
|
+
class LongPollingTransport {
|
|
43258
|
+
constructor(httpClient, logger, options) {
|
|
43259
|
+
this._httpClient = httpClient;
|
|
43260
|
+
this._logger = logger;
|
|
43261
|
+
this._pollAbort = new AbortController$1();
|
|
43262
|
+
this._options = options;
|
|
43263
|
+
this._running = false;
|
|
43264
|
+
this.onreceive = null;
|
|
43265
|
+
this.onclose = null;
|
|
43266
|
+
}
|
|
43267
|
+
get pollAborted() {
|
|
43268
|
+
return this._pollAbort.aborted;
|
|
43269
|
+
}
|
|
43270
|
+
async connect(url2, transferFormat) {
|
|
43271
|
+
Arg.isRequired(url2, "url");
|
|
43272
|
+
Arg.isRequired(transferFormat, "transferFormat");
|
|
43273
|
+
Arg.isIn(transferFormat, TransferFormat, "transferFormat");
|
|
43274
|
+
this._url = url2;
|
|
43275
|
+
this._logger.log(LogLevel.Trace, "(LongPolling transport) Connecting.");
|
|
43276
|
+
if (transferFormat === TransferFormat.Binary && (typeof XMLHttpRequest !== "undefined" && typeof new XMLHttpRequest().responseType !== "string")) {
|
|
43277
|
+
throw new Error("Binary protocols over XmlHttpRequest not implementing advanced features are not supported.");
|
|
43278
|
+
}
|
|
43279
|
+
const [name, value] = getUserAgentHeader();
|
|
43280
|
+
const headers = { [name]: value, ...this._options.headers };
|
|
43281
|
+
const pollOptions = {
|
|
43282
|
+
abortSignal: this._pollAbort.signal,
|
|
43283
|
+
headers,
|
|
43284
|
+
timeout: 1e5,
|
|
43285
|
+
withCredentials: this._options.withCredentials
|
|
43286
|
+
};
|
|
43287
|
+
if (transferFormat === TransferFormat.Binary) {
|
|
43288
|
+
pollOptions.responseType = "arraybuffer";
|
|
43289
|
+
}
|
|
43290
|
+
const pollUrl = `${url2}&_=${Date.now()}`;
|
|
43291
|
+
this._logger.log(LogLevel.Trace, `(LongPolling transport) polling: ${pollUrl}.`);
|
|
43292
|
+
const response2 = await this._httpClient.get(pollUrl, pollOptions);
|
|
43293
|
+
if (response2.statusCode !== 200) {
|
|
43294
|
+
this._logger.log(LogLevel.Error, `(LongPolling transport) Unexpected response code: ${response2.statusCode}.`);
|
|
43295
|
+
this._closeError = new HttpError(response2.statusText || "", response2.statusCode);
|
|
43296
|
+
this._running = false;
|
|
43297
|
+
} else {
|
|
43298
|
+
this._running = true;
|
|
43299
|
+
}
|
|
43300
|
+
this._receiving = this._poll(this._url, pollOptions);
|
|
43301
|
+
}
|
|
43302
|
+
async _poll(url2, pollOptions) {
|
|
43303
|
+
try {
|
|
43304
|
+
while (this._running) {
|
|
43305
|
+
try {
|
|
43306
|
+
const pollUrl = `${url2}&_=${Date.now()}`;
|
|
43307
|
+
this._logger.log(LogLevel.Trace, `(LongPolling transport) polling: ${pollUrl}.`);
|
|
43308
|
+
const response2 = await this._httpClient.get(pollUrl, pollOptions);
|
|
43309
|
+
if (response2.statusCode === 204) {
|
|
43310
|
+
this._logger.log(LogLevel.Information, "(LongPolling transport) Poll terminated by server.");
|
|
43311
|
+
this._running = false;
|
|
43312
|
+
} else if (response2.statusCode !== 200) {
|
|
43313
|
+
this._logger.log(LogLevel.Error, `(LongPolling transport) Unexpected response code: ${response2.statusCode}.`);
|
|
43314
|
+
this._closeError = new HttpError(response2.statusText || "", response2.statusCode);
|
|
43315
|
+
this._running = false;
|
|
43316
|
+
} else {
|
|
43317
|
+
if (response2.content) {
|
|
43318
|
+
this._logger.log(LogLevel.Trace, `(LongPolling transport) data received. ${getDataDetail(response2.content, this._options.logMessageContent)}.`);
|
|
43319
|
+
if (this.onreceive) {
|
|
43320
|
+
this.onreceive(response2.content);
|
|
43321
|
+
}
|
|
43322
|
+
} else {
|
|
43323
|
+
this._logger.log(LogLevel.Trace, "(LongPolling transport) Poll timed out, reissuing.");
|
|
43324
|
+
}
|
|
43325
|
+
}
|
|
43326
|
+
} catch (e2) {
|
|
43327
|
+
if (!this._running) {
|
|
43328
|
+
this._logger.log(LogLevel.Trace, `(LongPolling transport) Poll errored after shutdown: ${e2.message}`);
|
|
43329
|
+
} else {
|
|
43330
|
+
if (e2 instanceof TimeoutError) {
|
|
43331
|
+
this._logger.log(LogLevel.Trace, "(LongPolling transport) Poll timed out, reissuing.");
|
|
43332
|
+
} else {
|
|
43333
|
+
this._closeError = e2;
|
|
43334
|
+
this._running = false;
|
|
43335
|
+
}
|
|
43336
|
+
}
|
|
43337
|
+
}
|
|
43338
|
+
}
|
|
43339
|
+
} finally {
|
|
43340
|
+
this._logger.log(LogLevel.Trace, "(LongPolling transport) Polling complete.");
|
|
43341
|
+
if (!this.pollAborted) {
|
|
43342
|
+
this._raiseOnClose();
|
|
43343
|
+
}
|
|
43344
|
+
}
|
|
43345
|
+
}
|
|
43346
|
+
async send(data2) {
|
|
43347
|
+
if (!this._running) {
|
|
43348
|
+
return Promise.reject(new Error("Cannot send until the transport is connected"));
|
|
43349
|
+
}
|
|
43350
|
+
return sendMessage(this._logger, "LongPolling", this._httpClient, this._url, data2, this._options);
|
|
43351
|
+
}
|
|
43352
|
+
async stop() {
|
|
43353
|
+
this._logger.log(LogLevel.Trace, "(LongPolling transport) Stopping polling.");
|
|
43354
|
+
this._running = false;
|
|
43355
|
+
this._pollAbort.abort();
|
|
43356
|
+
try {
|
|
43357
|
+
await this._receiving;
|
|
43358
|
+
this._logger.log(LogLevel.Trace, `(LongPolling transport) sending DELETE request to ${this._url}.`);
|
|
43359
|
+
const headers = {};
|
|
43360
|
+
const [name, value] = getUserAgentHeader();
|
|
43361
|
+
headers[name] = value;
|
|
43362
|
+
const deleteOptions = {
|
|
43363
|
+
headers: { ...headers, ...this._options.headers },
|
|
43364
|
+
timeout: this._options.timeout,
|
|
43365
|
+
withCredentials: this._options.withCredentials
|
|
43366
|
+
};
|
|
43367
|
+
await this._httpClient.delete(this._url, deleteOptions);
|
|
43368
|
+
this._logger.log(LogLevel.Trace, "(LongPolling transport) DELETE request sent.");
|
|
43369
|
+
} finally {
|
|
43370
|
+
this._logger.log(LogLevel.Trace, "(LongPolling transport) Stop finished.");
|
|
43371
|
+
this._raiseOnClose();
|
|
43372
|
+
}
|
|
43373
|
+
}
|
|
43374
|
+
_raiseOnClose() {
|
|
43375
|
+
if (this.onclose) {
|
|
43376
|
+
let logMessage = "(LongPolling transport) Firing onclose event.";
|
|
43377
|
+
if (this._closeError) {
|
|
43378
|
+
logMessage += " Error: " + this._closeError;
|
|
43379
|
+
}
|
|
43380
|
+
this._logger.log(LogLevel.Trace, logMessage);
|
|
43381
|
+
this.onclose(this._closeError);
|
|
43382
|
+
}
|
|
43383
|
+
}
|
|
43384
|
+
}
|
|
43385
|
+
class ServerSentEventsTransport {
|
|
43386
|
+
constructor(httpClient, accessToken, logger, options) {
|
|
43387
|
+
this._httpClient = httpClient;
|
|
43388
|
+
this._accessToken = accessToken;
|
|
43389
|
+
this._logger = logger;
|
|
43390
|
+
this._options = options;
|
|
43391
|
+
this.onreceive = null;
|
|
43392
|
+
this.onclose = null;
|
|
43393
|
+
}
|
|
43394
|
+
async connect(url2, transferFormat) {
|
|
43395
|
+
Arg.isRequired(url2, "url");
|
|
43396
|
+
Arg.isRequired(transferFormat, "transferFormat");
|
|
43397
|
+
Arg.isIn(transferFormat, TransferFormat, "transferFormat");
|
|
43398
|
+
this._logger.log(LogLevel.Trace, "(SSE transport) Connecting.");
|
|
43399
|
+
this._url = url2;
|
|
43400
|
+
if (this._accessToken) {
|
|
43401
|
+
url2 += (url2.indexOf("?") < 0 ? "?" : "&") + `access_token=${encodeURIComponent(this._accessToken)}`;
|
|
43402
|
+
}
|
|
43403
|
+
return new Promise((resolve, reject) => {
|
|
43404
|
+
let opened = false;
|
|
43405
|
+
if (transferFormat !== TransferFormat.Text) {
|
|
43406
|
+
reject(new Error("The Server-Sent Events transport only supports the 'Text' transfer format"));
|
|
43407
|
+
return;
|
|
43408
|
+
}
|
|
43409
|
+
let eventSource;
|
|
43410
|
+
if (Platform.isBrowser || Platform.isWebWorker) {
|
|
43411
|
+
eventSource = new this._options.EventSource(url2, { withCredentials: this._options.withCredentials });
|
|
43412
|
+
} else {
|
|
43413
|
+
const cookies2 = this._httpClient.getCookieString(url2);
|
|
43414
|
+
const headers = {};
|
|
43415
|
+
headers.Cookie = cookies2;
|
|
43416
|
+
const [name, value] = getUserAgentHeader();
|
|
43417
|
+
headers[name] = value;
|
|
43418
|
+
eventSource = new this._options.EventSource(url2, { withCredentials: this._options.withCredentials, headers: { ...headers, ...this._options.headers } });
|
|
43419
|
+
}
|
|
43420
|
+
try {
|
|
43421
|
+
eventSource.onmessage = (e2) => {
|
|
43422
|
+
if (this.onreceive) {
|
|
43423
|
+
try {
|
|
43424
|
+
this._logger.log(LogLevel.Trace, `(SSE transport) data received. ${getDataDetail(e2.data, this._options.logMessageContent)}.`);
|
|
43425
|
+
this.onreceive(e2.data);
|
|
43426
|
+
} catch (error2) {
|
|
43427
|
+
this._close(error2);
|
|
43428
|
+
return;
|
|
43429
|
+
}
|
|
43430
|
+
}
|
|
43431
|
+
};
|
|
43432
|
+
eventSource.onerror = (e2) => {
|
|
43433
|
+
if (opened) {
|
|
43434
|
+
this._close();
|
|
43435
|
+
} else {
|
|
43436
|
+
reject(new Error("EventSource failed to connect. The connection could not be found on the server, either the connection ID is not present on the server, or a proxy is refusing/buffering the connection. If you have multiple servers check that sticky sessions are enabled."));
|
|
43437
|
+
}
|
|
43438
|
+
};
|
|
43439
|
+
eventSource.onopen = () => {
|
|
43440
|
+
this._logger.log(LogLevel.Information, `SSE connected to ${this._url}`);
|
|
43441
|
+
this._eventSource = eventSource;
|
|
43442
|
+
opened = true;
|
|
43443
|
+
resolve();
|
|
43444
|
+
};
|
|
43445
|
+
} catch (e2) {
|
|
43446
|
+
reject(e2);
|
|
43447
|
+
return;
|
|
43448
|
+
}
|
|
43449
|
+
});
|
|
43450
|
+
}
|
|
43451
|
+
async send(data2) {
|
|
43452
|
+
if (!this._eventSource) {
|
|
43453
|
+
return Promise.reject(new Error("Cannot send until the transport is connected"));
|
|
43454
|
+
}
|
|
43455
|
+
return sendMessage(this._logger, "SSE", this._httpClient, this._url, data2, this._options);
|
|
43456
|
+
}
|
|
43457
|
+
stop() {
|
|
43458
|
+
this._close();
|
|
43459
|
+
return Promise.resolve();
|
|
43460
|
+
}
|
|
43461
|
+
_close(e2) {
|
|
43462
|
+
if (this._eventSource) {
|
|
43463
|
+
this._eventSource.close();
|
|
43464
|
+
this._eventSource = void 0;
|
|
43465
|
+
if (this.onclose) {
|
|
43466
|
+
this.onclose(e2);
|
|
43467
|
+
}
|
|
43468
|
+
}
|
|
43469
|
+
}
|
|
43470
|
+
}
|
|
43471
|
+
class WebSocketTransport {
|
|
43472
|
+
constructor(httpClient, accessTokenFactory, logger, logMessageContent, webSocketConstructor, headers) {
|
|
43473
|
+
this._logger = logger;
|
|
43474
|
+
this._accessTokenFactory = accessTokenFactory;
|
|
43475
|
+
this._logMessageContent = logMessageContent;
|
|
43476
|
+
this._webSocketConstructor = webSocketConstructor;
|
|
43477
|
+
this._httpClient = httpClient;
|
|
43478
|
+
this.onreceive = null;
|
|
43479
|
+
this.onclose = null;
|
|
43480
|
+
this._headers = headers;
|
|
43481
|
+
}
|
|
43482
|
+
async connect(url2, transferFormat) {
|
|
43483
|
+
Arg.isRequired(url2, "url");
|
|
43484
|
+
Arg.isRequired(transferFormat, "transferFormat");
|
|
43485
|
+
Arg.isIn(transferFormat, TransferFormat, "transferFormat");
|
|
43486
|
+
this._logger.log(LogLevel.Trace, "(WebSockets transport) Connecting.");
|
|
43487
|
+
let token;
|
|
43488
|
+
if (this._accessTokenFactory) {
|
|
43489
|
+
token = await this._accessTokenFactory();
|
|
43490
|
+
}
|
|
43491
|
+
return new Promise((resolve, reject) => {
|
|
43492
|
+
url2 = url2.replace(/^http/, "ws");
|
|
43493
|
+
let webSocket;
|
|
43494
|
+
const cookies2 = this._httpClient.getCookieString(url2);
|
|
43495
|
+
let opened = false;
|
|
43496
|
+
if (Platform.isNode || Platform.isReactNative) {
|
|
43497
|
+
const headers = {};
|
|
43498
|
+
const [name, value] = getUserAgentHeader();
|
|
43499
|
+
headers[name] = value;
|
|
43500
|
+
if (token) {
|
|
43501
|
+
headers[HeaderNames.Authorization] = `Bearer ${token}`;
|
|
43502
|
+
}
|
|
43503
|
+
if (cookies2) {
|
|
43504
|
+
headers[HeaderNames.Cookie] = cookies2;
|
|
43505
|
+
}
|
|
43506
|
+
webSocket = new this._webSocketConstructor(url2, void 0, {
|
|
43507
|
+
headers: { ...headers, ...this._headers }
|
|
43508
|
+
});
|
|
43509
|
+
} else {
|
|
43510
|
+
if (token) {
|
|
43511
|
+
url2 += (url2.indexOf("?") < 0 ? "?" : "&") + `access_token=${encodeURIComponent(token)}`;
|
|
43512
|
+
}
|
|
43513
|
+
}
|
|
43514
|
+
if (!webSocket) {
|
|
43515
|
+
webSocket = new this._webSocketConstructor(url2);
|
|
43516
|
+
}
|
|
43517
|
+
if (transferFormat === TransferFormat.Binary) {
|
|
43518
|
+
webSocket.binaryType = "arraybuffer";
|
|
43519
|
+
}
|
|
43520
|
+
webSocket.onopen = (_event2) => {
|
|
43521
|
+
this._logger.log(LogLevel.Information, `WebSocket connected to ${url2}.`);
|
|
43522
|
+
this._webSocket = webSocket;
|
|
43523
|
+
opened = true;
|
|
43524
|
+
resolve();
|
|
43525
|
+
};
|
|
43526
|
+
webSocket.onerror = (event) => {
|
|
43527
|
+
let error2 = null;
|
|
43528
|
+
if (typeof ErrorEvent !== "undefined" && event instanceof ErrorEvent) {
|
|
43529
|
+
error2 = event.error;
|
|
43530
|
+
} else {
|
|
43531
|
+
error2 = "There was an error with the transport";
|
|
43532
|
+
}
|
|
43533
|
+
this._logger.log(LogLevel.Information, `(WebSockets transport) ${error2}.`);
|
|
43534
|
+
};
|
|
43535
|
+
webSocket.onmessage = (message2) => {
|
|
43536
|
+
this._logger.log(LogLevel.Trace, `(WebSockets transport) data received. ${getDataDetail(message2.data, this._logMessageContent)}.`);
|
|
43537
|
+
if (this.onreceive) {
|
|
43538
|
+
try {
|
|
43539
|
+
this.onreceive(message2.data);
|
|
43540
|
+
} catch (error2) {
|
|
43541
|
+
this._close(error2);
|
|
43542
|
+
return;
|
|
43543
|
+
}
|
|
43544
|
+
}
|
|
43545
|
+
};
|
|
43546
|
+
webSocket.onclose = (event) => {
|
|
43547
|
+
if (opened) {
|
|
43548
|
+
this._close(event);
|
|
43549
|
+
} else {
|
|
43550
|
+
let error2 = null;
|
|
43551
|
+
if (typeof ErrorEvent !== "undefined" && event instanceof ErrorEvent) {
|
|
43552
|
+
error2 = event.error;
|
|
43553
|
+
} else {
|
|
43554
|
+
error2 = "WebSocket failed to connect. The connection could not be found on the server, either the endpoint may not be a SignalR endpoint, the connection ID is not present on the server, or there is a proxy blocking WebSockets. If you have multiple servers check that sticky sessions are enabled.";
|
|
43555
|
+
}
|
|
43556
|
+
reject(new Error(error2));
|
|
43557
|
+
}
|
|
43558
|
+
};
|
|
43559
|
+
});
|
|
43560
|
+
}
|
|
43561
|
+
send(data2) {
|
|
43562
|
+
if (this._webSocket && this._webSocket.readyState === this._webSocketConstructor.OPEN) {
|
|
43563
|
+
this._logger.log(LogLevel.Trace, `(WebSockets transport) sending data. ${getDataDetail(data2, this._logMessageContent)}.`);
|
|
43564
|
+
this._webSocket.send(data2);
|
|
43565
|
+
return Promise.resolve();
|
|
43566
|
+
}
|
|
43567
|
+
return Promise.reject("WebSocket is not in the OPEN state");
|
|
43568
|
+
}
|
|
43569
|
+
stop() {
|
|
43570
|
+
if (this._webSocket) {
|
|
43571
|
+
this._close(void 0);
|
|
43572
|
+
}
|
|
43573
|
+
return Promise.resolve();
|
|
43574
|
+
}
|
|
43575
|
+
_close(event) {
|
|
43576
|
+
if (this._webSocket) {
|
|
43577
|
+
this._webSocket.onclose = () => {
|
|
43578
|
+
};
|
|
43579
|
+
this._webSocket.onmessage = () => {
|
|
43580
|
+
};
|
|
43581
|
+
this._webSocket.onerror = () => {
|
|
43582
|
+
};
|
|
43583
|
+
this._webSocket.close();
|
|
43584
|
+
this._webSocket = void 0;
|
|
43585
|
+
}
|
|
43586
|
+
this._logger.log(LogLevel.Trace, "(WebSockets transport) socket closed.");
|
|
43587
|
+
if (this.onclose) {
|
|
43588
|
+
if (this._isCloseEvent(event) && (event.wasClean === false || event.code !== 1e3)) {
|
|
43589
|
+
this.onclose(new Error(`WebSocket closed with status code: ${event.code} (${event.reason || "no reason given"}).`));
|
|
43590
|
+
} else if (event instanceof Error) {
|
|
43591
|
+
this.onclose(event);
|
|
43592
|
+
} else {
|
|
43593
|
+
this.onclose();
|
|
43594
|
+
}
|
|
43595
|
+
}
|
|
43596
|
+
}
|
|
43597
|
+
_isCloseEvent(event) {
|
|
43598
|
+
return event && typeof event.wasClean === "boolean" && typeof event.code === "number";
|
|
43599
|
+
}
|
|
43600
|
+
}
|
|
43601
|
+
const MAX_REDIRECTS = 100;
|
|
43602
|
+
class HttpConnection {
|
|
43603
|
+
constructor(url2, options = {}) {
|
|
43604
|
+
this._stopPromiseResolver = () => {
|
|
43605
|
+
};
|
|
43606
|
+
this.features = {};
|
|
43607
|
+
this._negotiateVersion = 1;
|
|
43608
|
+
Arg.isRequired(url2, "url");
|
|
43609
|
+
this._logger = createLogger(options.logger);
|
|
43610
|
+
this.baseUrl = this._resolveUrl(url2);
|
|
43611
|
+
options = options || {};
|
|
43612
|
+
options.logMessageContent = options.logMessageContent === void 0 ? false : options.logMessageContent;
|
|
43613
|
+
if (typeof options.withCredentials === "boolean" || options.withCredentials === void 0) {
|
|
43614
|
+
options.withCredentials = options.withCredentials === void 0 ? true : options.withCredentials;
|
|
43615
|
+
} else {
|
|
43616
|
+
throw new Error("withCredentials option was not a 'boolean' or 'undefined' value");
|
|
43617
|
+
}
|
|
43618
|
+
options.timeout = options.timeout === void 0 ? 100 * 1e3 : options.timeout;
|
|
43619
|
+
let webSocketModule = null;
|
|
43620
|
+
let eventSourceModule = null;
|
|
43621
|
+
if (Platform.isNode && typeof require !== "undefined") {
|
|
43622
|
+
const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
|
|
43623
|
+
webSocketModule = requireFunc("ws");
|
|
43624
|
+
eventSourceModule = requireFunc("eventsource");
|
|
43625
|
+
}
|
|
43626
|
+
if (!Platform.isNode && typeof WebSocket !== "undefined" && !options.WebSocket) {
|
|
43627
|
+
options.WebSocket = WebSocket;
|
|
43628
|
+
} else if (Platform.isNode && !options.WebSocket) {
|
|
43629
|
+
if (webSocketModule) {
|
|
43630
|
+
options.WebSocket = webSocketModule;
|
|
43631
|
+
}
|
|
43632
|
+
}
|
|
43633
|
+
if (!Platform.isNode && typeof EventSource !== "undefined" && !options.EventSource) {
|
|
43634
|
+
options.EventSource = EventSource;
|
|
43635
|
+
} else if (Platform.isNode && !options.EventSource) {
|
|
43636
|
+
if (typeof eventSourceModule !== "undefined") {
|
|
43637
|
+
options.EventSource = eventSourceModule;
|
|
43638
|
+
}
|
|
43639
|
+
}
|
|
43640
|
+
this._httpClient = new AccessTokenHttpClient(options.httpClient || new DefaultHttpClient(this._logger), options.accessTokenFactory);
|
|
43641
|
+
this._connectionState = "Disconnected";
|
|
43642
|
+
this._connectionStarted = false;
|
|
43643
|
+
this._options = options;
|
|
43644
|
+
this.onreceive = null;
|
|
43645
|
+
this.onclose = null;
|
|
43646
|
+
}
|
|
43647
|
+
async start(transferFormat) {
|
|
43648
|
+
transferFormat = transferFormat || TransferFormat.Binary;
|
|
43649
|
+
Arg.isIn(transferFormat, TransferFormat, "transferFormat");
|
|
43650
|
+
this._logger.log(LogLevel.Debug, `Starting connection with transfer format '${TransferFormat[transferFormat]}'.`);
|
|
43651
|
+
if (this._connectionState !== "Disconnected") {
|
|
43652
|
+
return Promise.reject(new Error("Cannot start an HttpConnection that is not in the 'Disconnected' state."));
|
|
43653
|
+
}
|
|
43654
|
+
this._connectionState = "Connecting";
|
|
43655
|
+
this._startInternalPromise = this._startInternal(transferFormat);
|
|
43656
|
+
await this._startInternalPromise;
|
|
43657
|
+
if (this._connectionState === "Disconnecting") {
|
|
43658
|
+
const message2 = "Failed to start the HttpConnection before stop() was called.";
|
|
43659
|
+
this._logger.log(LogLevel.Error, message2);
|
|
43660
|
+
await this._stopPromise;
|
|
43661
|
+
return Promise.reject(new AbortError(message2));
|
|
43662
|
+
} else if (this._connectionState !== "Connected") {
|
|
43663
|
+
const message2 = "HttpConnection.startInternal completed gracefully but didn't enter the connection into the connected state!";
|
|
43664
|
+
this._logger.log(LogLevel.Error, message2);
|
|
43665
|
+
return Promise.reject(new AbortError(message2));
|
|
43666
|
+
}
|
|
43667
|
+
this._connectionStarted = true;
|
|
43668
|
+
}
|
|
43669
|
+
send(data2) {
|
|
43670
|
+
if (this._connectionState !== "Connected") {
|
|
43671
|
+
return Promise.reject(new Error("Cannot send data if the connection is not in the 'Connected' State."));
|
|
43672
|
+
}
|
|
43673
|
+
if (!this._sendQueue) {
|
|
43674
|
+
this._sendQueue = new TransportSendQueue(this.transport);
|
|
43675
|
+
}
|
|
43676
|
+
return this._sendQueue.send(data2);
|
|
43677
|
+
}
|
|
43678
|
+
async stop(error2) {
|
|
43679
|
+
if (this._connectionState === "Disconnected") {
|
|
43680
|
+
this._logger.log(LogLevel.Debug, `Call to HttpConnection.stop(${error2}) ignored because the connection is already in the disconnected state.`);
|
|
43681
|
+
return Promise.resolve();
|
|
43682
|
+
}
|
|
43683
|
+
if (this._connectionState === "Disconnecting") {
|
|
43684
|
+
this._logger.log(LogLevel.Debug, `Call to HttpConnection.stop(${error2}) ignored because the connection is already in the disconnecting state.`);
|
|
43685
|
+
return this._stopPromise;
|
|
43686
|
+
}
|
|
43687
|
+
this._connectionState = "Disconnecting";
|
|
43688
|
+
this._stopPromise = new Promise((resolve) => {
|
|
43689
|
+
this._stopPromiseResolver = resolve;
|
|
43690
|
+
});
|
|
43691
|
+
await this._stopInternal(error2);
|
|
43692
|
+
await this._stopPromise;
|
|
43693
|
+
}
|
|
43694
|
+
async _stopInternal(error2) {
|
|
43695
|
+
this._stopError = error2;
|
|
43696
|
+
try {
|
|
43697
|
+
await this._startInternalPromise;
|
|
43698
|
+
} catch (e2) {
|
|
43699
|
+
}
|
|
43700
|
+
if (this.transport) {
|
|
43701
|
+
try {
|
|
43702
|
+
await this.transport.stop();
|
|
43703
|
+
} catch (e2) {
|
|
43704
|
+
this._logger.log(LogLevel.Error, `HttpConnection.transport.stop() threw error '${e2}'.`);
|
|
43705
|
+
this._stopConnection();
|
|
43706
|
+
}
|
|
43707
|
+
this.transport = void 0;
|
|
43708
|
+
} else {
|
|
43709
|
+
this._logger.log(LogLevel.Debug, "HttpConnection.transport is undefined in HttpConnection.stop() because start() failed.");
|
|
43710
|
+
}
|
|
43711
|
+
}
|
|
43712
|
+
async _startInternal(transferFormat) {
|
|
43713
|
+
let url2 = this.baseUrl;
|
|
43714
|
+
this._accessTokenFactory = this._options.accessTokenFactory;
|
|
43715
|
+
this._httpClient._accessTokenFactory = this._accessTokenFactory;
|
|
43716
|
+
try {
|
|
43717
|
+
if (this._options.skipNegotiation) {
|
|
43718
|
+
if (this._options.transport === HttpTransportType.WebSockets) {
|
|
43719
|
+
this.transport = this._constructTransport(HttpTransportType.WebSockets);
|
|
43720
|
+
await this._startTransport(url2, transferFormat);
|
|
43721
|
+
} else {
|
|
43722
|
+
throw new Error("Negotiation can only be skipped when using the WebSocket transport directly.");
|
|
43723
|
+
}
|
|
43724
|
+
} else {
|
|
43725
|
+
let negotiateResponse = null;
|
|
43726
|
+
let redirects = 0;
|
|
43727
|
+
do {
|
|
43728
|
+
negotiateResponse = await this._getNegotiationResponse(url2);
|
|
43729
|
+
if (this._connectionState === "Disconnecting" || this._connectionState === "Disconnected") {
|
|
43730
|
+
throw new AbortError("The connection was stopped during negotiation.");
|
|
43731
|
+
}
|
|
43732
|
+
if (negotiateResponse.error) {
|
|
43733
|
+
throw new Error(negotiateResponse.error);
|
|
43734
|
+
}
|
|
43735
|
+
if (negotiateResponse.ProtocolVersion) {
|
|
43736
|
+
throw new Error("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.");
|
|
43737
|
+
}
|
|
43738
|
+
if (negotiateResponse.url) {
|
|
43739
|
+
url2 = negotiateResponse.url;
|
|
43740
|
+
}
|
|
43741
|
+
if (negotiateResponse.accessToken) {
|
|
43742
|
+
const accessToken = negotiateResponse.accessToken;
|
|
43743
|
+
this._accessTokenFactory = () => accessToken;
|
|
43744
|
+
this._httpClient._accessToken = accessToken;
|
|
43745
|
+
this._httpClient._accessTokenFactory = void 0;
|
|
43746
|
+
}
|
|
43747
|
+
redirects++;
|
|
43748
|
+
} while (negotiateResponse.url && redirects < MAX_REDIRECTS);
|
|
43749
|
+
if (redirects === MAX_REDIRECTS && negotiateResponse.url) {
|
|
43750
|
+
throw new Error("Negotiate redirection limit exceeded.");
|
|
43751
|
+
}
|
|
43752
|
+
await this._createTransport(url2, this._options.transport, negotiateResponse, transferFormat);
|
|
43753
|
+
}
|
|
43754
|
+
if (this.transport instanceof LongPollingTransport) {
|
|
43755
|
+
this.features.inherentKeepAlive = true;
|
|
43756
|
+
}
|
|
43757
|
+
if (this._connectionState === "Connecting") {
|
|
43758
|
+
this._logger.log(LogLevel.Debug, "The HttpConnection connected successfully.");
|
|
43759
|
+
this._connectionState = "Connected";
|
|
43760
|
+
}
|
|
43761
|
+
} catch (e2) {
|
|
43762
|
+
this._logger.log(LogLevel.Error, "Failed to start the connection: " + e2);
|
|
43763
|
+
this._connectionState = "Disconnected";
|
|
43764
|
+
this.transport = void 0;
|
|
43765
|
+
this._stopPromiseResolver();
|
|
43766
|
+
return Promise.reject(e2);
|
|
43767
|
+
}
|
|
43768
|
+
}
|
|
43769
|
+
async _getNegotiationResponse(url2) {
|
|
43770
|
+
const headers = {};
|
|
43771
|
+
const [name, value] = getUserAgentHeader();
|
|
43772
|
+
headers[name] = value;
|
|
43773
|
+
const negotiateUrl = this._resolveNegotiateUrl(url2);
|
|
43774
|
+
this._logger.log(LogLevel.Debug, `Sending negotiation request: ${negotiateUrl}.`);
|
|
43775
|
+
try {
|
|
43776
|
+
const response2 = await this._httpClient.post(negotiateUrl, {
|
|
43777
|
+
content: "",
|
|
43778
|
+
headers: { ...headers, ...this._options.headers },
|
|
43779
|
+
timeout: this._options.timeout,
|
|
43780
|
+
withCredentials: this._options.withCredentials
|
|
43781
|
+
});
|
|
43782
|
+
if (response2.statusCode !== 200) {
|
|
43783
|
+
return Promise.reject(new Error(`Unexpected status code returned from negotiate '${response2.statusCode}'`));
|
|
43784
|
+
}
|
|
43785
|
+
const negotiateResponse = JSON.parse(response2.content);
|
|
43786
|
+
if (!negotiateResponse.negotiateVersion || negotiateResponse.negotiateVersion < 1) {
|
|
43787
|
+
negotiateResponse.connectionToken = negotiateResponse.connectionId;
|
|
43788
|
+
}
|
|
43789
|
+
return negotiateResponse;
|
|
43790
|
+
} catch (e2) {
|
|
43791
|
+
let errorMessage = "Failed to complete negotiation with the server: " + e2;
|
|
43792
|
+
if (e2 instanceof HttpError) {
|
|
43793
|
+
if (e2.statusCode === 404) {
|
|
43794
|
+
errorMessage = errorMessage + " Either this is not a SignalR endpoint or there is a proxy blocking the connection.";
|
|
43795
|
+
}
|
|
43796
|
+
}
|
|
43797
|
+
this._logger.log(LogLevel.Error, errorMessage);
|
|
43798
|
+
return Promise.reject(new FailedToNegotiateWithServerError(errorMessage));
|
|
43799
|
+
}
|
|
43800
|
+
}
|
|
43801
|
+
_createConnectUrl(url2, connectionToken) {
|
|
43802
|
+
if (!connectionToken) {
|
|
43803
|
+
return url2;
|
|
43804
|
+
}
|
|
43805
|
+
return url2 + (url2.indexOf("?") === -1 ? "?" : "&") + `id=${connectionToken}`;
|
|
43806
|
+
}
|
|
43807
|
+
async _createTransport(url2, requestedTransport, negotiateResponse, requestedTransferFormat) {
|
|
43808
|
+
let connectUrl = this._createConnectUrl(url2, negotiateResponse.connectionToken);
|
|
43809
|
+
if (this._isITransport(requestedTransport)) {
|
|
43810
|
+
this._logger.log(LogLevel.Debug, "Connection was provided an instance of ITransport, using that directly.");
|
|
43811
|
+
this.transport = requestedTransport;
|
|
43812
|
+
await this._startTransport(connectUrl, requestedTransferFormat);
|
|
43813
|
+
this.connectionId = negotiateResponse.connectionId;
|
|
43814
|
+
return;
|
|
43815
|
+
}
|
|
43816
|
+
const transportExceptions = [];
|
|
43817
|
+
const transports = negotiateResponse.availableTransports || [];
|
|
43818
|
+
let negotiate = negotiateResponse;
|
|
43819
|
+
for (const endpoint of transports) {
|
|
43820
|
+
const transportOrError = this._resolveTransportOrError(endpoint, requestedTransport, requestedTransferFormat);
|
|
43821
|
+
if (transportOrError instanceof Error) {
|
|
43822
|
+
transportExceptions.push(`${endpoint.transport} failed:`);
|
|
43823
|
+
transportExceptions.push(transportOrError);
|
|
43824
|
+
} else if (this._isITransport(transportOrError)) {
|
|
43825
|
+
this.transport = transportOrError;
|
|
43826
|
+
if (!negotiate) {
|
|
43827
|
+
try {
|
|
43828
|
+
negotiate = await this._getNegotiationResponse(url2);
|
|
43829
|
+
} catch (ex2) {
|
|
43830
|
+
return Promise.reject(ex2);
|
|
43831
|
+
}
|
|
43832
|
+
connectUrl = this._createConnectUrl(url2, negotiate.connectionToken);
|
|
43833
|
+
}
|
|
43834
|
+
try {
|
|
43835
|
+
await this._startTransport(connectUrl, requestedTransferFormat);
|
|
43836
|
+
this.connectionId = negotiate.connectionId;
|
|
43837
|
+
return;
|
|
43838
|
+
} catch (ex2) {
|
|
43839
|
+
this._logger.log(LogLevel.Error, `Failed to start the transport '${endpoint.transport}': ${ex2}`);
|
|
43840
|
+
negotiate = void 0;
|
|
43841
|
+
transportExceptions.push(new FailedToStartTransportError(`${endpoint.transport} failed: ${ex2}`, HttpTransportType[endpoint.transport]));
|
|
43842
|
+
if (this._connectionState !== "Connecting") {
|
|
43843
|
+
const message2 = "Failed to select transport before stop() was called.";
|
|
43844
|
+
this._logger.log(LogLevel.Debug, message2);
|
|
43845
|
+
return Promise.reject(new AbortError(message2));
|
|
43846
|
+
}
|
|
43847
|
+
}
|
|
43848
|
+
}
|
|
43849
|
+
}
|
|
43850
|
+
if (transportExceptions.length > 0) {
|
|
43851
|
+
return Promise.reject(new AggregateErrors(`Unable to connect to the server with any of the available transports. ${transportExceptions.join(" ")}`, transportExceptions));
|
|
43852
|
+
}
|
|
43853
|
+
return Promise.reject(new Error("None of the transports supported by the client are supported by the server."));
|
|
43854
|
+
}
|
|
43855
|
+
_constructTransport(transport) {
|
|
43856
|
+
switch (transport) {
|
|
43857
|
+
case HttpTransportType.WebSockets:
|
|
43858
|
+
if (!this._options.WebSocket) {
|
|
43859
|
+
throw new Error("'WebSocket' is not supported in your environment.");
|
|
43860
|
+
}
|
|
43861
|
+
return new WebSocketTransport(this._httpClient, this._accessTokenFactory, this._logger, this._options.logMessageContent, this._options.WebSocket, this._options.headers || {});
|
|
43862
|
+
case HttpTransportType.ServerSentEvents:
|
|
43863
|
+
if (!this._options.EventSource) {
|
|
43864
|
+
throw new Error("'EventSource' is not supported in your environment.");
|
|
43865
|
+
}
|
|
43866
|
+
return new ServerSentEventsTransport(this._httpClient, this._httpClient._accessToken, this._logger, this._options);
|
|
43867
|
+
case HttpTransportType.LongPolling:
|
|
43868
|
+
return new LongPollingTransport(this._httpClient, this._logger, this._options);
|
|
43869
|
+
default:
|
|
43870
|
+
throw new Error(`Unknown transport: ${transport}.`);
|
|
43871
|
+
}
|
|
43872
|
+
}
|
|
43873
|
+
_startTransport(url2, transferFormat) {
|
|
43874
|
+
this.transport.onreceive = this.onreceive;
|
|
43875
|
+
this.transport.onclose = (e2) => this._stopConnection(e2);
|
|
43876
|
+
return this.transport.connect(url2, transferFormat);
|
|
43877
|
+
}
|
|
43878
|
+
_resolveTransportOrError(endpoint, requestedTransport, requestedTransferFormat) {
|
|
43879
|
+
const transport = HttpTransportType[endpoint.transport];
|
|
43880
|
+
if (transport === null || transport === void 0) {
|
|
43881
|
+
this._logger.log(LogLevel.Debug, `Skipping transport '${endpoint.transport}' because it is not supported by this client.`);
|
|
43882
|
+
return new Error(`Skipping transport '${endpoint.transport}' because it is not supported by this client.`);
|
|
43883
|
+
} else {
|
|
43884
|
+
if (transportMatches(requestedTransport, transport)) {
|
|
43885
|
+
const transferFormats = endpoint.transferFormats.map((s2) => TransferFormat[s2]);
|
|
43886
|
+
if (transferFormats.indexOf(requestedTransferFormat) >= 0) {
|
|
43887
|
+
if (transport === HttpTransportType.WebSockets && !this._options.WebSocket || transport === HttpTransportType.ServerSentEvents && !this._options.EventSource) {
|
|
43888
|
+
this._logger.log(LogLevel.Debug, `Skipping transport '${HttpTransportType[transport]}' because it is not supported in your environment.'`);
|
|
43889
|
+
return new UnsupportedTransportError(`'${HttpTransportType[transport]}' is not supported in your environment.`, transport);
|
|
43890
|
+
} else {
|
|
43891
|
+
this._logger.log(LogLevel.Debug, `Selecting transport '${HttpTransportType[transport]}'.`);
|
|
43892
|
+
try {
|
|
43893
|
+
return this._constructTransport(transport);
|
|
43894
|
+
} catch (ex2) {
|
|
43895
|
+
return ex2;
|
|
43896
|
+
}
|
|
43897
|
+
}
|
|
43898
|
+
} else {
|
|
43899
|
+
this._logger.log(LogLevel.Debug, `Skipping transport '${HttpTransportType[transport]}' because it does not support the requested transfer format '${TransferFormat[requestedTransferFormat]}'.`);
|
|
43900
|
+
return new Error(`'${HttpTransportType[transport]}' does not support ${TransferFormat[requestedTransferFormat]}.`);
|
|
43901
|
+
}
|
|
43902
|
+
} else {
|
|
43903
|
+
this._logger.log(LogLevel.Debug, `Skipping transport '${HttpTransportType[transport]}' because it was disabled by the client.`);
|
|
43904
|
+
return new DisabledTransportError(`'${HttpTransportType[transport]}' is disabled by the client.`, transport);
|
|
43905
|
+
}
|
|
43906
|
+
}
|
|
43907
|
+
}
|
|
43908
|
+
_isITransport(transport) {
|
|
43909
|
+
return transport && typeof transport === "object" && "connect" in transport;
|
|
43910
|
+
}
|
|
43911
|
+
_stopConnection(error2) {
|
|
43912
|
+
this._logger.log(LogLevel.Debug, `HttpConnection.stopConnection(${error2}) called while in state ${this._connectionState}.`);
|
|
43913
|
+
this.transport = void 0;
|
|
43914
|
+
error2 = this._stopError || error2;
|
|
43915
|
+
this._stopError = void 0;
|
|
43916
|
+
if (this._connectionState === "Disconnected") {
|
|
43917
|
+
this._logger.log(LogLevel.Debug, `Call to HttpConnection.stopConnection(${error2}) was ignored because the connection is already in the disconnected state.`);
|
|
43918
|
+
return;
|
|
43919
|
+
}
|
|
43920
|
+
if (this._connectionState === "Connecting") {
|
|
43921
|
+
this._logger.log(LogLevel.Warning, `Call to HttpConnection.stopConnection(${error2}) was ignored because the connection is still in the connecting state.`);
|
|
43922
|
+
throw new Error(`HttpConnection.stopConnection(${error2}) was called while the connection is still in the connecting state.`);
|
|
43923
|
+
}
|
|
43924
|
+
if (this._connectionState === "Disconnecting") {
|
|
43925
|
+
this._stopPromiseResolver();
|
|
43926
|
+
}
|
|
43927
|
+
if (error2) {
|
|
43928
|
+
this._logger.log(LogLevel.Error, `Connection disconnected with error '${error2}'.`);
|
|
43929
|
+
} else {
|
|
43930
|
+
this._logger.log(LogLevel.Information, "Connection disconnected.");
|
|
43931
|
+
}
|
|
43932
|
+
if (this._sendQueue) {
|
|
43933
|
+
this._sendQueue.stop().catch((e2) => {
|
|
43934
|
+
this._logger.log(LogLevel.Error, `TransportSendQueue.stop() threw error '${e2}'.`);
|
|
43935
|
+
});
|
|
43936
|
+
this._sendQueue = void 0;
|
|
43937
|
+
}
|
|
43938
|
+
this.connectionId = void 0;
|
|
43939
|
+
this._connectionState = "Disconnected";
|
|
43940
|
+
if (this._connectionStarted) {
|
|
43941
|
+
this._connectionStarted = false;
|
|
43942
|
+
try {
|
|
43943
|
+
if (this.onclose) {
|
|
43944
|
+
this.onclose(error2);
|
|
43945
|
+
}
|
|
43946
|
+
} catch (e2) {
|
|
43947
|
+
this._logger.log(LogLevel.Error, `HttpConnection.onclose(${error2}) threw error '${e2}'.`);
|
|
43948
|
+
}
|
|
43949
|
+
}
|
|
43950
|
+
}
|
|
43951
|
+
_resolveUrl(url2) {
|
|
43952
|
+
if (url2.lastIndexOf("https://", 0) === 0 || url2.lastIndexOf("http://", 0) === 0) {
|
|
43953
|
+
return url2;
|
|
43954
|
+
}
|
|
43955
|
+
if (!Platform.isBrowser) {
|
|
43956
|
+
throw new Error(`Cannot resolve '${url2}'.`);
|
|
43957
|
+
}
|
|
43958
|
+
const aTag = window.document.createElement("a");
|
|
43959
|
+
aTag.href = url2;
|
|
43960
|
+
this._logger.log(LogLevel.Information, `Normalizing '${url2}' to '${aTag.href}'.`);
|
|
43961
|
+
return aTag.href;
|
|
43962
|
+
}
|
|
43963
|
+
_resolveNegotiateUrl(url2) {
|
|
43964
|
+
const index = url2.indexOf("?");
|
|
43965
|
+
let negotiateUrl = url2.substring(0, index === -1 ? url2.length : index);
|
|
43966
|
+
if (negotiateUrl[negotiateUrl.length - 1] !== "/") {
|
|
43967
|
+
negotiateUrl += "/";
|
|
43968
|
+
}
|
|
43969
|
+
negotiateUrl += "negotiate";
|
|
43970
|
+
negotiateUrl += index === -1 ? "" : url2.substring(index);
|
|
43971
|
+
if (negotiateUrl.indexOf("negotiateVersion") === -1) {
|
|
43972
|
+
negotiateUrl += index === -1 ? "?" : "&";
|
|
43973
|
+
negotiateUrl += "negotiateVersion=" + this._negotiateVersion;
|
|
43974
|
+
}
|
|
43975
|
+
return negotiateUrl;
|
|
43976
|
+
}
|
|
43977
|
+
}
|
|
43978
|
+
function transportMatches(requestedTransport, actualTransport) {
|
|
43979
|
+
return !requestedTransport || (actualTransport & requestedTransport) !== 0;
|
|
43980
|
+
}
|
|
43981
|
+
class TransportSendQueue {
|
|
43982
|
+
constructor(_transport) {
|
|
43983
|
+
this._transport = _transport;
|
|
43984
|
+
this._buffer = [];
|
|
43985
|
+
this._executing = true;
|
|
43986
|
+
this._sendBufferedData = new PromiseSource();
|
|
43987
|
+
this._transportResult = new PromiseSource();
|
|
43988
|
+
this._sendLoopPromise = this._sendLoop();
|
|
43989
|
+
}
|
|
43990
|
+
send(data2) {
|
|
43991
|
+
this._bufferData(data2);
|
|
43992
|
+
if (!this._transportResult) {
|
|
43993
|
+
this._transportResult = new PromiseSource();
|
|
43994
|
+
}
|
|
43995
|
+
return this._transportResult.promise;
|
|
43996
|
+
}
|
|
43997
|
+
stop() {
|
|
43998
|
+
this._executing = false;
|
|
43999
|
+
this._sendBufferedData.resolve();
|
|
44000
|
+
return this._sendLoopPromise;
|
|
44001
|
+
}
|
|
44002
|
+
_bufferData(data2) {
|
|
44003
|
+
if (this._buffer.length && typeof this._buffer[0] !== typeof data2) {
|
|
44004
|
+
throw new Error(`Expected data to be of type ${typeof this._buffer} but was of type ${typeof data2}`);
|
|
44005
|
+
}
|
|
44006
|
+
this._buffer.push(data2);
|
|
44007
|
+
this._sendBufferedData.resolve();
|
|
44008
|
+
}
|
|
44009
|
+
async _sendLoop() {
|
|
44010
|
+
while (true) {
|
|
44011
|
+
await this._sendBufferedData.promise;
|
|
44012
|
+
if (!this._executing) {
|
|
44013
|
+
if (this._transportResult) {
|
|
44014
|
+
this._transportResult.reject("Connection stopped.");
|
|
44015
|
+
}
|
|
44016
|
+
break;
|
|
44017
|
+
}
|
|
44018
|
+
this._sendBufferedData = new PromiseSource();
|
|
44019
|
+
const transportResult = this._transportResult;
|
|
44020
|
+
this._transportResult = void 0;
|
|
44021
|
+
const data2 = typeof this._buffer[0] === "string" ? this._buffer.join("") : TransportSendQueue._concatBuffers(this._buffer);
|
|
44022
|
+
this._buffer.length = 0;
|
|
44023
|
+
try {
|
|
44024
|
+
await this._transport.send(data2);
|
|
44025
|
+
transportResult.resolve();
|
|
44026
|
+
} catch (error2) {
|
|
44027
|
+
transportResult.reject(error2);
|
|
44028
|
+
}
|
|
44029
|
+
}
|
|
44030
|
+
}
|
|
44031
|
+
static _concatBuffers(arrayBuffers) {
|
|
44032
|
+
const totalLength = arrayBuffers.map((b2) => b2.byteLength).reduce((a2, b2) => a2 + b2);
|
|
44033
|
+
const result = new Uint8Array(totalLength);
|
|
44034
|
+
let offset = 0;
|
|
44035
|
+
for (const item of arrayBuffers) {
|
|
44036
|
+
result.set(new Uint8Array(item), offset);
|
|
44037
|
+
offset += item.byteLength;
|
|
44038
|
+
}
|
|
44039
|
+
return result.buffer;
|
|
44040
|
+
}
|
|
44041
|
+
}
|
|
44042
|
+
class PromiseSource {
|
|
44043
|
+
constructor() {
|
|
44044
|
+
this.promise = new Promise((resolve, reject) => [this._resolver, this._rejecter] = [resolve, reject]);
|
|
44045
|
+
}
|
|
44046
|
+
resolve() {
|
|
44047
|
+
this._resolver();
|
|
44048
|
+
}
|
|
44049
|
+
reject(reason) {
|
|
44050
|
+
this._rejecter(reason);
|
|
44051
|
+
}
|
|
44052
|
+
}
|
|
44053
|
+
const JSON_HUB_PROTOCOL_NAME = "json";
|
|
44054
|
+
class JsonHubProtocol {
|
|
44055
|
+
constructor() {
|
|
44056
|
+
this.name = JSON_HUB_PROTOCOL_NAME;
|
|
44057
|
+
this.version = 1;
|
|
44058
|
+
this.transferFormat = TransferFormat.Text;
|
|
44059
|
+
}
|
|
44060
|
+
parseMessages(input2, logger) {
|
|
44061
|
+
if (typeof input2 !== "string") {
|
|
44062
|
+
throw new Error("Invalid input for JSON hub protocol. Expected a string.");
|
|
44063
|
+
}
|
|
44064
|
+
if (!input2) {
|
|
44065
|
+
return [];
|
|
44066
|
+
}
|
|
44067
|
+
if (logger === null) {
|
|
44068
|
+
logger = NullLogger.instance;
|
|
44069
|
+
}
|
|
44070
|
+
const messages2 = TextMessageFormat.parse(input2);
|
|
44071
|
+
const hubMessages = [];
|
|
44072
|
+
for (const message2 of messages2) {
|
|
44073
|
+
const parsedMessage = JSON.parse(message2);
|
|
44074
|
+
if (typeof parsedMessage.type !== "number") {
|
|
44075
|
+
throw new Error("Invalid payload.");
|
|
44076
|
+
}
|
|
44077
|
+
switch (parsedMessage.type) {
|
|
44078
|
+
case MessageType.Invocation:
|
|
44079
|
+
this._isInvocationMessage(parsedMessage);
|
|
44080
|
+
break;
|
|
44081
|
+
case MessageType.StreamItem:
|
|
44082
|
+
this._isStreamItemMessage(parsedMessage);
|
|
44083
|
+
break;
|
|
44084
|
+
case MessageType.Completion:
|
|
44085
|
+
this._isCompletionMessage(parsedMessage);
|
|
44086
|
+
break;
|
|
44087
|
+
case MessageType.Ping:
|
|
44088
|
+
break;
|
|
44089
|
+
case MessageType.Close:
|
|
44090
|
+
break;
|
|
44091
|
+
default:
|
|
44092
|
+
logger.log(LogLevel.Information, "Unknown message type '" + parsedMessage.type + "' ignored.");
|
|
44093
|
+
continue;
|
|
44094
|
+
}
|
|
44095
|
+
hubMessages.push(parsedMessage);
|
|
44096
|
+
}
|
|
44097
|
+
return hubMessages;
|
|
44098
|
+
}
|
|
44099
|
+
writeMessage(message2) {
|
|
44100
|
+
return TextMessageFormat.write(JSON.stringify(message2));
|
|
44101
|
+
}
|
|
44102
|
+
_isInvocationMessage(message2) {
|
|
44103
|
+
this._assertNotEmptyString(message2.target, "Invalid payload for Invocation message.");
|
|
44104
|
+
if (message2.invocationId !== void 0) {
|
|
44105
|
+
this._assertNotEmptyString(message2.invocationId, "Invalid payload for Invocation message.");
|
|
44106
|
+
}
|
|
44107
|
+
}
|
|
44108
|
+
_isStreamItemMessage(message2) {
|
|
44109
|
+
this._assertNotEmptyString(message2.invocationId, "Invalid payload for StreamItem message.");
|
|
44110
|
+
if (message2.item === void 0) {
|
|
44111
|
+
throw new Error("Invalid payload for StreamItem message.");
|
|
44112
|
+
}
|
|
44113
|
+
}
|
|
44114
|
+
_isCompletionMessage(message2) {
|
|
44115
|
+
if (message2.result && message2.error) {
|
|
44116
|
+
throw new Error("Invalid payload for Completion message.");
|
|
44117
|
+
}
|
|
44118
|
+
if (!message2.result && message2.error) {
|
|
44119
|
+
this._assertNotEmptyString(message2.error, "Invalid payload for Completion message.");
|
|
44120
|
+
}
|
|
44121
|
+
this._assertNotEmptyString(message2.invocationId, "Invalid payload for Completion message.");
|
|
44122
|
+
}
|
|
44123
|
+
_assertNotEmptyString(value, errorMessage) {
|
|
44124
|
+
if (typeof value !== "string" || value === "") {
|
|
44125
|
+
throw new Error(errorMessage);
|
|
44126
|
+
}
|
|
44127
|
+
}
|
|
44128
|
+
}
|
|
44129
|
+
const LogLevelNameMapping = {
|
|
44130
|
+
trace: LogLevel.Trace,
|
|
44131
|
+
debug: LogLevel.Debug,
|
|
44132
|
+
info: LogLevel.Information,
|
|
44133
|
+
information: LogLevel.Information,
|
|
44134
|
+
warn: LogLevel.Warning,
|
|
44135
|
+
warning: LogLevel.Warning,
|
|
44136
|
+
error: LogLevel.Error,
|
|
44137
|
+
critical: LogLevel.Critical,
|
|
44138
|
+
none: LogLevel.None
|
|
44139
|
+
};
|
|
44140
|
+
function parseLogLevel(name) {
|
|
44141
|
+
const mapping = LogLevelNameMapping[name.toLowerCase()];
|
|
44142
|
+
if (typeof mapping !== "undefined") {
|
|
44143
|
+
return mapping;
|
|
44144
|
+
} else {
|
|
44145
|
+
throw new Error(`Unknown log level: ${name}`);
|
|
44146
|
+
}
|
|
44147
|
+
}
|
|
44148
|
+
class HubConnectionBuilder {
|
|
44149
|
+
configureLogging(logging) {
|
|
44150
|
+
Arg.isRequired(logging, "logging");
|
|
44151
|
+
if (isLogger(logging)) {
|
|
44152
|
+
this.logger = logging;
|
|
44153
|
+
} else if (typeof logging === "string") {
|
|
44154
|
+
const logLevel = parseLogLevel(logging);
|
|
44155
|
+
this.logger = new ConsoleLogger(logLevel);
|
|
44156
|
+
} else {
|
|
44157
|
+
this.logger = new ConsoleLogger(logging);
|
|
44158
|
+
}
|
|
44159
|
+
return this;
|
|
44160
|
+
}
|
|
44161
|
+
withUrl(url2, transportTypeOrOptions) {
|
|
44162
|
+
Arg.isRequired(url2, "url");
|
|
44163
|
+
Arg.isNotEmpty(url2, "url");
|
|
44164
|
+
this.url = url2;
|
|
44165
|
+
if (typeof transportTypeOrOptions === "object") {
|
|
44166
|
+
this.httpConnectionOptions = { ...this.httpConnectionOptions, ...transportTypeOrOptions };
|
|
44167
|
+
} else {
|
|
44168
|
+
this.httpConnectionOptions = {
|
|
44169
|
+
...this.httpConnectionOptions,
|
|
44170
|
+
transport: transportTypeOrOptions
|
|
44171
|
+
};
|
|
44172
|
+
}
|
|
44173
|
+
return this;
|
|
44174
|
+
}
|
|
44175
|
+
withHubProtocol(protocol) {
|
|
44176
|
+
Arg.isRequired(protocol, "protocol");
|
|
44177
|
+
this.protocol = protocol;
|
|
44178
|
+
return this;
|
|
44179
|
+
}
|
|
44180
|
+
withAutomaticReconnect(retryDelaysOrReconnectPolicy) {
|
|
44181
|
+
if (this.reconnectPolicy) {
|
|
44182
|
+
throw new Error("A reconnectPolicy has already been set.");
|
|
44183
|
+
}
|
|
44184
|
+
if (!retryDelaysOrReconnectPolicy) {
|
|
44185
|
+
this.reconnectPolicy = new DefaultReconnectPolicy();
|
|
44186
|
+
} else if (Array.isArray(retryDelaysOrReconnectPolicy)) {
|
|
44187
|
+
this.reconnectPolicy = new DefaultReconnectPolicy(retryDelaysOrReconnectPolicy);
|
|
44188
|
+
} else {
|
|
44189
|
+
this.reconnectPolicy = retryDelaysOrReconnectPolicy;
|
|
44190
|
+
}
|
|
44191
|
+
return this;
|
|
44192
|
+
}
|
|
44193
|
+
build() {
|
|
44194
|
+
const httpConnectionOptions = this.httpConnectionOptions || {};
|
|
44195
|
+
if (httpConnectionOptions.logger === void 0) {
|
|
44196
|
+
httpConnectionOptions.logger = this.logger;
|
|
44197
|
+
}
|
|
44198
|
+
if (!this.url) {
|
|
44199
|
+
throw new Error("The 'HubConnectionBuilder.withUrl' method must be called before building the connection.");
|
|
44200
|
+
}
|
|
44201
|
+
const connection = new HttpConnection(this.url, httpConnectionOptions);
|
|
44202
|
+
return HubConnection.create(connection, this.logger || NullLogger.instance, this.protocol || new JsonHubProtocol(), this.reconnectPolicy);
|
|
44203
|
+
}
|
|
44204
|
+
}
|
|
44205
|
+
function isLogger(logger) {
|
|
44206
|
+
return logger.log !== void 0;
|
|
44207
|
+
}
|
|
44208
|
+
const useConfigStore = defineStore("config", {
|
|
44209
|
+
state: () => ({
|
|
44210
|
+
token: "",
|
|
44211
|
+
baseUrl: ""
|
|
44212
|
+
}),
|
|
44213
|
+
actions: {
|
|
44214
|
+
getToken(token) {
|
|
44215
|
+
this.token = token;
|
|
44216
|
+
},
|
|
44217
|
+
getBaseUrl(url2) {
|
|
44218
|
+
this.baseUrl = url2;
|
|
44219
|
+
},
|
|
44220
|
+
api(optionsRequest) {
|
|
44221
|
+
return ApiJs(optionsRequest, false, `Bearer ${this.token}`, true);
|
|
44222
|
+
},
|
|
44223
|
+
channelsConnectionHub() {
|
|
44224
|
+
return new HubConnectionBuilder().withUrl(`${this.baseUrl}/v2/channels`, {
|
|
44225
|
+
accessTokenFactory: () => `${this.token}`
|
|
44226
|
+
}).configureLogging(LogLevel.Information).build();
|
|
44227
|
+
},
|
|
44228
|
+
async connectChannelsSignalR(channelId) {
|
|
44229
|
+
let startedPromise = null;
|
|
44230
|
+
async function start() {
|
|
44231
|
+
startedPromise = await this.channelsConnectionHub.start().catch((err) => {
|
|
44232
|
+
console.error("Failed to connect with hub", err);
|
|
44233
|
+
return new Promise((res, rej) => setTimeout(() => start().then(res).catch(rej), 5e3));
|
|
44234
|
+
});
|
|
44235
|
+
console.log("start $channelsConnectionHub");
|
|
44236
|
+
return startedPromise;
|
|
44237
|
+
}
|
|
44238
|
+
try {
|
|
44239
|
+
await start();
|
|
44240
|
+
await this.channelsConnectionHub.invoke("Join", channelId);
|
|
44241
|
+
} catch (err) {
|
|
44242
|
+
console.error(err.toString());
|
|
44243
|
+
}
|
|
44244
|
+
}
|
|
44245
|
+
}
|
|
44246
|
+
});
|
|
44247
|
+
var apiChat = {
|
|
44248
|
+
getChannels(api, baseUrl, category, count2 = 50) {
|
|
44249
|
+
return api({
|
|
44250
|
+
url: `${baseUrl}/api/channels/issues/${category}`,
|
|
44251
|
+
method: "GET",
|
|
44252
|
+
headers: {
|
|
44253
|
+
"x-group-id": "FLINE"
|
|
44254
|
+
},
|
|
44255
|
+
params: {
|
|
44256
|
+
count: count2
|
|
44257
|
+
}
|
|
44258
|
+
});
|
|
44259
|
+
},
|
|
44260
|
+
getUnreadChannels(api, baseUrl) {
|
|
44261
|
+
return api({
|
|
44262
|
+
url: `${baseUrl}/api/channels/issues/count`,
|
|
44263
|
+
method: "GET",
|
|
44264
|
+
headers: {
|
|
44265
|
+
"x-group-id": "FLINE"
|
|
44266
|
+
}
|
|
44267
|
+
});
|
|
44268
|
+
},
|
|
44269
|
+
getGroups(api, baseUrl) {
|
|
44270
|
+
return api({
|
|
44271
|
+
url: `${baseUrl}/api/groups`,
|
|
44272
|
+
method: "GET",
|
|
44273
|
+
headers: {
|
|
44274
|
+
"x-group-id": "FLINE"
|
|
44275
|
+
}
|
|
44276
|
+
});
|
|
44277
|
+
}
|
|
44278
|
+
};
|
|
44279
|
+
const useCommonStore = defineStore("commonStore", {
|
|
44280
|
+
state: () => ({
|
|
44281
|
+
loadingStatus: "notLoading"
|
|
44282
|
+
}),
|
|
44283
|
+
getters: {
|
|
44284
|
+
isLoading: (state) => state.loadingStatus === "loading"
|
|
44285
|
+
},
|
|
44286
|
+
actions: {
|
|
44287
|
+
setLoadingStatus(status) {
|
|
44288
|
+
this.loadingStatus = status;
|
|
44289
|
+
}
|
|
44290
|
+
}
|
|
44291
|
+
});
|
|
44292
|
+
const useChannelsStore = defineStore("channels", {
|
|
44293
|
+
state: () => ({
|
|
44294
|
+
channels: [],
|
|
44295
|
+
unreadChannels: {},
|
|
44296
|
+
groups: [],
|
|
44297
|
+
channelCategory: "Active",
|
|
44298
|
+
notifications: {
|
|
44299
|
+
messagesRead: null,
|
|
44300
|
+
messageAdded: null,
|
|
44301
|
+
activeChannels: null
|
|
44302
|
+
},
|
|
44303
|
+
selectedChannelInfo: {
|
|
44304
|
+
channelId: "",
|
|
44305
|
+
participant: [],
|
|
44306
|
+
files: [],
|
|
44307
|
+
messages: [],
|
|
44308
|
+
unreadMessagesCount: null,
|
|
44309
|
+
loadingMessages: false,
|
|
44310
|
+
managerConnect: null,
|
|
44311
|
+
afterMessagesLoaded: false,
|
|
44312
|
+
beforeMessagesLoaded: false
|
|
44313
|
+
}
|
|
44314
|
+
}),
|
|
44315
|
+
getters: {
|
|
44316
|
+
api() {
|
|
44317
|
+
const configStore = useConfigStore();
|
|
44318
|
+
return configStore.api;
|
|
44319
|
+
},
|
|
44320
|
+
baseUrl() {
|
|
44321
|
+
const configStore = useConfigStore();
|
|
44322
|
+
return configStore.baseUrl;
|
|
44323
|
+
}
|
|
44324
|
+
},
|
|
44325
|
+
actions: {
|
|
44326
|
+
loading() {
|
|
44327
|
+
const commonStore = useCommonStore();
|
|
44328
|
+
commonStore.setLoadingStatus("loading");
|
|
44329
|
+
},
|
|
44330
|
+
notLoading() {
|
|
44331
|
+
const commonStore = useCommonStore();
|
|
44332
|
+
commonStore.setLoadingStatus("notLoading");
|
|
44333
|
+
},
|
|
44334
|
+
async getChannels(category) {
|
|
44335
|
+
try {
|
|
44336
|
+
this.loading();
|
|
44337
|
+
const channels = await apiChat.getChannels(this.api, this.baseUrl, category);
|
|
44338
|
+
this.channels = channels;
|
|
44339
|
+
if (category === "New") {
|
|
44340
|
+
this.notifications.activeChannels = channels;
|
|
44341
|
+
}
|
|
44342
|
+
} catch (error2) {
|
|
44343
|
+
console.log(error2);
|
|
44344
|
+
} finally {
|
|
44345
|
+
this.notLoading();
|
|
44346
|
+
}
|
|
44347
|
+
},
|
|
44348
|
+
async getUnreadChannels() {
|
|
44349
|
+
try {
|
|
44350
|
+
this.unreadChannels = await apiChat.getUnreadChannels(this.api, this.baseUrl);
|
|
44351
|
+
} catch (error2) {
|
|
44352
|
+
console.log(error2);
|
|
44353
|
+
}
|
|
44354
|
+
},
|
|
44355
|
+
async getGroups() {
|
|
44356
|
+
try {
|
|
44357
|
+
this.groups = await apiChat.getGroups(this.api, this.baseUrl);
|
|
44358
|
+
} catch (error2) {
|
|
44359
|
+
console.log(error2);
|
|
44360
|
+
}
|
|
44361
|
+
}
|
|
44362
|
+
}
|
|
44363
|
+
});
|
|
44364
|
+
var PlChatBtn_vue_vue_type_style_index_0_lang = "";
|
|
44365
|
+
var PlChatPopup_vue_vue_type_style_index_0_lang = "";
|
|
44366
|
+
const _sfc_main = {
|
|
44367
|
+
__name: "pl-chat-manager",
|
|
44368
|
+
props: {
|
|
44369
|
+
token: {
|
|
44370
|
+
type: String,
|
|
44371
|
+
default: ""
|
|
44372
|
+
},
|
|
44373
|
+
baseUrl: {
|
|
44374
|
+
type: String,
|
|
44375
|
+
default: ""
|
|
44376
|
+
}
|
|
44377
|
+
},
|
|
44378
|
+
setup(__props) {
|
|
44379
|
+
const props = __props;
|
|
44380
|
+
const { token, baseUrl } = toRefs(props);
|
|
44381
|
+
const configStore = useConfigStore();
|
|
44382
|
+
const channelsStore = useChannelsStore();
|
|
44383
|
+
useCommonStore();
|
|
44384
|
+
const isHubsConnected = ref(true);
|
|
44385
|
+
const getChannelsInfo = async () => {
|
|
44386
|
+
configStore.getToken(token);
|
|
44387
|
+
configStore.getBaseUrl(baseUrl);
|
|
44388
|
+
await Promise.all([
|
|
44389
|
+
await channelsStore.getChannels("New"),
|
|
44390
|
+
await channelsStore.getUnreadChannels(),
|
|
44391
|
+
await channelsStore.getGroups()
|
|
44392
|
+
]);
|
|
44393
|
+
};
|
|
44394
|
+
const updateChannels = async () => {
|
|
44395
|
+
try {
|
|
44396
|
+
await Promise.all([
|
|
44397
|
+
await channelsStore.getChannels(channelsStore.channelCategory),
|
|
44398
|
+
await channelsStore.getUnreadChannels()
|
|
44399
|
+
]);
|
|
44400
|
+
} catch (error2) {
|
|
44401
|
+
console.log(error2);
|
|
44402
|
+
}
|
|
44403
|
+
};
|
|
44404
|
+
const managerChannelsSignalR = async () => {
|
|
44405
|
+
try {
|
|
44406
|
+
await Promise.all(channelsStore.notifications.activeChannels.map(async (channel) => {
|
|
44407
|
+
await configStore.connectChannelsSignalR(channel.channelId);
|
|
44408
|
+
await configStore.channelsConnectionHub.on("MessageAddedNotification", async (message2) => {
|
|
44409
|
+
console.log("MessageAddedNotificationManager", message2);
|
|
44410
|
+
await updateChannels();
|
|
44411
|
+
});
|
|
44412
|
+
await configStore.channelsConnectionHub.on("MessagesReadNotification", (message2) => {
|
|
44413
|
+
console.log("MessagesReadNotification", message2);
|
|
44414
|
+
updateChannels();
|
|
44415
|
+
});
|
|
44416
|
+
}));
|
|
44417
|
+
} catch (error2) {
|
|
44418
|
+
console.log(error2);
|
|
44419
|
+
}
|
|
44420
|
+
};
|
|
44421
|
+
const chatManagerStart = async () => {
|
|
44422
|
+
try {
|
|
44423
|
+
await Promise.all([
|
|
44424
|
+
getChannelsInfo(),
|
|
44425
|
+
managerChannelsSignalR()
|
|
44426
|
+
]);
|
|
44427
|
+
} catch (error2) {
|
|
44428
|
+
console.log(error2);
|
|
44429
|
+
} finally {
|
|
44430
|
+
isHubsConnected.value = false;
|
|
44431
|
+
}
|
|
44432
|
+
};
|
|
44433
|
+
chatManagerStart();
|
|
44434
|
+
return (_ctx, _cache) => {
|
|
44435
|
+
const _directive_loading = vLoading;
|
|
44436
|
+
return withDirectives((openBlock(), createElementBlock("div", null, [
|
|
44437
|
+
createTextVNode(toDisplayString(unref(channelsStore).notifications.activeChannels), 1)
|
|
44438
|
+
])), [
|
|
44439
|
+
[_directive_loading, isHubsConnected.value]
|
|
44440
|
+
]);
|
|
42012
44441
|
};
|
|
42013
44442
|
}
|
|
42014
44443
|
};
|