mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-22 21:59:44 +03:00
Added logger to WS
This commit is contained in:
@@ -26,6 +26,13 @@ module.exports = {
|
|||||||
'@typescript-eslint',
|
'@typescript-eslint',
|
||||||
],
|
],
|
||||||
rules: {
|
rules: {
|
||||||
|
"no-param-reassign": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"props": true,
|
||||||
|
"ignorePropertyModificationsFor": ["acc", "prev"]
|
||||||
|
}
|
||||||
|
],
|
||||||
"camelcase": "off",
|
"camelcase": "off",
|
||||||
'@typescript-eslint/consistent-type-assertions': [
|
'@typescript-eslint/consistent-type-assertions': [
|
||||||
'error',
|
'error',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@orionprotocol/sdk",
|
"name": "@orionprotocol/sdk",
|
||||||
"version": "0.12.14",
|
"version": "0.12.15",
|
||||||
"description": "Orion Protocol SDK",
|
"description": "Orion Protocol SDK",
|
||||||
"main": "./lib/esm/index.js",
|
"main": "./lib/esm/index.js",
|
||||||
"module": "./lib/esm/index.js",
|
"module": "./lib/esm/index.js",
|
||||||
|
|||||||
@@ -158,10 +158,13 @@ class OrionAggregatorWS {
|
|||||||
|
|
||||||
public onError?: (err: string) => void;
|
public onError?: (err: string) => void;
|
||||||
|
|
||||||
|
private logger?: (message: string) => void;
|
||||||
|
|
||||||
private readonly wsUrl: string;
|
private readonly wsUrl: string;
|
||||||
|
|
||||||
constructor(wsUrl: string, onInit?: () => void, onError?: (err: string) => void) {
|
constructor(wsUrl: string, logger?: (msg: string) => void, onInit?: () => void, onError?: (err: string) => void) {
|
||||||
this.wsUrl = wsUrl;
|
this.wsUrl = wsUrl;
|
||||||
|
this.logger = logger;
|
||||||
this.onInit = onInit;
|
this.onInit = onInit;
|
||||||
this.onError = onError;
|
this.onError = onError;
|
||||||
}
|
}
|
||||||
@@ -268,7 +271,11 @@ class OrionAggregatorWS {
|
|||||||
init(isReconnect = false) {
|
init(isReconnect = false) {
|
||||||
this.isClosedIntentionally = false;
|
this.isClosedIntentionally = false;
|
||||||
this.ws = new WebSocket(this.wsUrl);
|
this.ws = new WebSocket(this.wsUrl);
|
||||||
|
this.ws.onerror = (err) => {
|
||||||
|
this.logger?.(`OrionAggregatorWS: ${err.message}`);
|
||||||
|
};
|
||||||
this.ws.onclose = () => {
|
this.ws.onclose = () => {
|
||||||
|
this.logger?.(`OrionAggregatorWS: connection closed ${this.isClosedIntentionally ? 'intentionally' : ''}`);
|
||||||
if (!this.isClosedIntentionally) this.init(true);
|
if (!this.isClosedIntentionally) this.init(true);
|
||||||
};
|
};
|
||||||
this.ws.onopen = () => {
|
this.ws.onopen = () => {
|
||||||
@@ -286,9 +293,11 @@ class OrionAggregatorWS {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this.logger?.(`OrionAggregatorWS: connection opened${isReconnect ? ' (reconnect)' : ''}`);
|
||||||
};
|
};
|
||||||
this.ws.onmessage = (e) => {
|
this.ws.onmessage = (e) => {
|
||||||
const { data } = e;
|
const { data } = e;
|
||||||
|
this.logger?.(`OrionAggregatorWS: received message: ${e.data.toString()}`);
|
||||||
const rawJson: unknown = JSON.parse(data.toString());
|
const rawJson: unknown = JSON.parse(data.toString());
|
||||||
|
|
||||||
const messageSchema = z.union([
|
const messageSchema = z.union([
|
||||||
|
|||||||
Reference in New Issue
Block a user