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 dfd51c5f8495ad6c231aee1528f086f6ef71d503
parent 9834f564f3b5a53aeb16f1acf56f8c2a31cd0c5b
Author: Johan Lindskogen <johan.lindskogen@gmail.com>
Date:   Sun,  1 Apr 2018 19:51:15 +0200

Move init connection to class

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

diff --git a/src/lib/weechat/connection.ts b/src/lib/weechat/connection.ts @@ -7,12 +7,14 @@ export default class WeechatConnection { dispatch: any; host: string; password: string; + compressed: boolean; websocket: WebSocket; - constructor(dispatch, host, password = "") { + constructor(dispatch, host, password = "", compressed = false) { this.dispatch = dispatch; this.host = host; this.password = password; + this.compressed = compressed; this.websocket = null; } @@ -20,12 +22,22 @@ export default class WeechatConnection { return new Promise((resolve, reject) => { this.websocket = new WebSocket(this.host); - this.websocket.onopen = () => resolve(this); + this.websocket.onopen = () => this.onopen(resolve); this.websocket.onmessage = event => this.onmessage(event); this.websocket.onerror = reject; }); } + onopen(callback) { + this.send( + `init password=${this.password},compression=${ + this.compressed ? "zlib" : "off" + }\n` + ); + this.send("(version) info version"); + callback(this); + } + onmessage(event) { const parsed = protocol.parse(event.data) as WeechatResponse<any>; diff --git a/src/usecase/Root.tsx b/src/usecase/Root.tsx @@ -10,18 +10,18 @@ import store from "../store"; import App from "./App"; import ConnectionGate from "./ConnectionGate"; -const connection = new WeechatConnection(store.dispatch, HOSTNAME, PASSWORD); +const compressed = false; +const connection = new WeechatConnection( + store.dispatch, + HOSTNAME, + PASSWORD, + compressed +); export default class WeechatNative extends React.Component { componentWillMount() { - const compressed = false; - connection.connect().then( conn => { - conn.send( - `init password=${PASSWORD},compression=${compressed ? "zlib" : "off"}` - ); - conn.send("(version) info version"); // conn.send("(hotlist) hdata hotlist:gui_hotlist(*)"); conn.send( "(buffers) hdata buffer:gui_buffers(*) local_variables,notify,number,full_name,short_name,title,hidden,type"