-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support connection / disconnection callback functions #126
Changes from all commits
6dd76ae
62b0470
6297ecf
455ca14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { ConnectionCallback, DisconnectionCallback } from "@ainblockchain/ain-js/lib/types"; | ||
import AinModule from "../ain"; | ||
import _ from "lodash"; | ||
|
||
|
@@ -23,9 +24,9 @@ export default class Handler { | |
return this.ain.getEventManager().isConnected(); | ||
} | ||
|
||
async connect() { | ||
async connect(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback) { | ||
this.checkEventManager(); | ||
await this.ain.getEventManager().connect(this.disconnectedCb.bind(this)); | ||
await this.ain.getEventManager().connect(connectionCb, this.connectionRetryCb.bind(this, connectionCb, disconnectionCb)); | ||
console.log('connected'); | ||
}; | ||
|
||
|
@@ -35,12 +36,15 @@ export default class Handler { | |
console.log('Disconnected'); | ||
} | ||
|
||
private async disconnectedCb() { | ||
private async connectionRetryCb(connectionCb?: ConnectionCallback, disconnectionCb?: DisconnectionCallback, webSocket?: any) { | ||
try { | ||
if (disconnectionCb) { | ||
disconnectionCb(webSocket); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's the last param of connectionRetryCb(). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
const address = await AinModule.getInstance().getAddress(); | ||
if (address) { | ||
console.log('Disconnected. Reconnecting...'); | ||
await this.connect(); | ||
await this.connect(connectionCb, disconnectionCb); | ||
} | ||
} catch (_) { | ||
return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@platfowner shouldn't add a
disconnectioncb
when logging out?(ref: https://github.com/ainize-team/ainize-js/pull/126/files#diff-18ba27879b90f0b7bcdc2205d931b9f01b9889c799fbdb63d430be0c013f7f01L61 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked that the disconnection function in ain-js does not have a callback option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(discussed offline) A disconnection callback can be added with login functions.