Skip to content

Commit

Permalink
mayuran/DPROD-2759/ws_improvements (binary-com#7070)
Browse files Browse the repository at this point in the history
* fix: wip

* fix: dummy initial

* fix: check socket

* fix: added conditionsa

* fix: ws call

* fix: ws reconnect

* fix: check api manager

* chore: trigger vercel

* fix: ws socket calls

* fix: session storage

* fix: window added

* fix: addded window

* fix: remove unwanted code

* fix: check

* fix: kogs

* fix: ready state

* fix: code clear

* fix: added logs

* fix: minor issue in reconnect

* fix: loading changed logic

* fix: remove session storage

* Revert "fix: remove session storage"

This reverts commit abb84c3.

* fix: remove session storage

* fix: improvement of use WS
  • Loading branch information
mayuran-deriv authored and hasan-deriv committed Mar 12, 2024
1 parent fdce4b7 commit 50942bc
Show file tree
Hide file tree
Showing 23 changed files with 4,245 additions and 4,217 deletions.
5 changes: 5 additions & 0 deletions themes/gatsby-theme-deriv/src/common/websocket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class ApiManager {
public init(lang?: string) {
if (!this.ready) {
if (!this.socket) {
console.log('WS connecting...')
const language = lang === 'ach' ? getCrowdin() : lang?.replace('-', '_')
const socket_url = getSocketURL()
const app_id = getAppId()
Expand All @@ -51,10 +52,12 @@ export class ApiManager {
}
this.derivApi = new DerivAPIBasic({ connection: this.socket })
this.socket.addEventListener('open', () => {
console.log('WS connected.')
this.setReadyState(this?.socket?.readyState)
})

this.socket.addEventListener('close', () => {
console.log('WS closed')
this.derivApi.disconnect()
this.ready = null
this.setReadyState(null)
Expand All @@ -64,12 +67,14 @@ export class ApiManager {
}

public reconnectIfNotConnected(lang?: string): Promise<void> {
console.log('WS reconnecting....')
return new Promise((resolve, reject) => {
if (this?.socket?.readyState !== 1) {
this.socket = null
this.ready = null
this.init(lang)
this?.socket?.addEventListener?.('open', () => {
console.log('WS connected using reconnect method.')
resolve()
})
} else {
Expand Down
Loading

0 comments on commit 50942bc

Please sign in to comment.