weechatRN

Weechat relay client for iOS using websockets https://github.com/mhoran/weechatRN
git clone http://git.hanabi.in/repos/weechatRN.git
Log | Files | Refs | README | LICENSE

commit eb6c13549d7902d7d5f73980f10b464291ff5471
parent d8ade9cb44eff8f0f2e158b4c3cd6f4cbe999473
Author: Matthew Horan <matt@matthoran.com>
Date:   Mon,  7 Jan 2019 20:41:11 -0500

Disable Connect button when reconnecting

There's a race condition if we're trying to reconnect and the connect
button is pushed.

Also fix onclose signature.

Diffstat:
Msrc/lib/weechat/connection.ts | 14++++++++------
Msrc/usecase/Root.tsx | 5++---
2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/lib/weechat/connection.ts b/src/lib/weechat/connection.ts @@ -11,13 +11,14 @@ export default class WeechatConnection { compressed: boolean; websocket: WebSocket; onSuccess: (conn: WeechatConnection) => any; - onError: (event: Event) => any; + onError: (reconnect: boolean) => any; connected: boolean; reconnect: boolean; constructor(dispatch) { this.dispatch = dispatch; this.websocket = null; + this.reconnect = this.connected = false; } connect( @@ -25,7 +26,7 @@ export default class WeechatConnection { password: string = "", ssl: boolean, onSuccess: (conn: WeechatConnection) => any, - onError: (event: Event) => any + onError: (reconnect: boolean) => any ) { this.hostname = host; this.password = password; @@ -44,7 +45,7 @@ export default class WeechatConnection { this.websocket.onopen = () => this.onopen(); this.websocket.onmessage = event => this.onmessage(event); this.websocket.onerror = event => this.handleError(event); - this.websocket.onclose = event => this.close(event); + this.websocket.onclose = () => this.close(); } onopen() { @@ -65,11 +66,12 @@ export default class WeechatConnection { } handleError(event) { - this.reconnect = this.connected && true; - this.onError(event); + console.log(event); + this.reconnect = this.connected; + this.onError(this.reconnect); } - close(event) { + close() { this.connected = false; this.send("quit"); this.websocket.close(); diff --git a/src/usecase/Root.tsx b/src/usecase/Root.tsx @@ -35,9 +35,8 @@ export default class WeechatNative extends React.Component<{}, State> { connection.send("sync"); }; - onConnectionError = error => { - this.setState({ connecting: false }); - console.log(error); + onConnectionError = reconnect => { + this.setState({ connecting: reconnect }); }; disconnect = () => {