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 dc02dd4c05cd6ffac286b11e91ccc0bb8b9124ec
parent 8254301c51eb607b883a8c591d0e726a50170593
Author: Johan Lindskogen <johan.lindskogen@gmail.com>
Date:   Mon,  2 Apr 2018 21:46:16 +0200

Store connection info in state

Diffstat:
Msrc/lib/weechat/connection.ts | 11++++++++---
Asrc/store/connection-info.ts | 23+++++++++++++++++++++++
2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/src/lib/weechat/connection.ts b/src/lib/weechat/connection.ts @@ -5,7 +5,7 @@ const protocol = new WeeChatProtocol(); export default class WeechatConnection { dispatch: any; - host: string; + hostname: string; password: string; compressed: boolean; websocket: WebSocket; @@ -16,10 +16,10 @@ export default class WeechatConnection { } connect(host, password = "", onSuccess, onError) { - this.host = host; + this.hostname = host; this.password = password; - this.websocket = new WebSocket(this.host); + this.websocket = new WebSocket(this.hostname); this.websocket.onopen = () => this.onopen(onSuccess); this.websocket.onmessage = event => this.onmessage(event); @@ -27,6 +27,11 @@ export default class WeechatConnection { } onopen(callback) { + this.dispatch({ + type: "SET_CONNECTION_INFO", + hostname: this.hostname, + password: this.password + }); this.send( `init password=${this.password},compression=${ this.compressed ? "zlib" : "off" diff --git a/src/store/connection-info.ts b/src/store/connection-info.ts @@ -0,0 +1,23 @@ +export type ConnectionInfo = { + hostname: string | null; + password: string | null; +}; + +const initialState: ConnectionInfo = { + hostname: null, + password: null +}; + +export default (state: ConnectionInfo = initialState, action) => { + switch (action.type) { + case "SET_CONNECTION_INFO": + return { + hostname: action.hostname, + password: action.password + }; + case "CLEAR_CONNECTION_INFO": + return initialState; + default: + return state; + } +};