Skip to content

Commit

Permalink
### Subject
Browse files Browse the repository at this point in the history
Add debug messaging toggle to WebSocketClient

### Body
Introduced a `debugMessage` boolean toggle in `WebSocketClient` to control conditional logging of WebSocket events, enhancing debugging capabilities. Also, changed the access level of `webSocket` in `IQOptionProvider` from private to public to enable external access for broader usage scenarios and debugging.

Fixes #123
  • Loading branch information
andredezzy committed Sep 20, 2024
1 parent 5c61440 commit 00b9ae7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/iqoption/lib/IQOptionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface LoginResponse {

export class IQOptionProvider implements BaseIQOptionProvider {
private api: AxiosInstance
private webSocket: WebSocketClient
public webSocket: WebSocketClient

private isCorsBypassEnabled: boolean

Expand Down
8 changes: 7 additions & 1 deletion packages/iqoption/lib/websocket/WebSocketClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class WebSocketClient implements BaseWebSocketClient {

public history: WebSocketEventHistory[]

public debugMessage: boolean

constructor(public refreshLogIn: () => Promise<void>) {
this.subscribers = [new HeartbeatSubscriber(this)]

Expand Down Expand Up @@ -51,6 +53,7 @@ export class WebSocketClient implements BaseWebSocketClient {
})

if (
this.debugMessage &&
!['heartbeat', 'timeSync', 'positions-state'].includes(event.name)
) {
console.log(
Expand Down Expand Up @@ -116,7 +119,10 @@ export class WebSocketClient implements BaseWebSocketClient {
try {
this.webSocket.send(JSON.stringify(event))

if (!['heartbeat', 'timeSync', 'positions-state'].includes(event.name)) {
if (
this.debugMessage &&
!['heartbeat', 'timeSync', 'positions-state'].includes(event.name)
) {
console.log(
'⬆',
format(Date.now(), 'yyyy-MM-dd HH:mm:ss:SSS'),
Expand Down

0 comments on commit 00b9ae7

Please sign in to comment.