try conn
This commit is contained in:
parent
a1b29106ad
commit
229211689a
1 changed files with 9 additions and 5 deletions
14
src/lib.rs
14
src/lib.rs
|
@ -18,10 +18,14 @@ pub struct QuadWs {
|
||||||
channel: WsChannnel,
|
channel: WsChannnel,
|
||||||
}
|
}
|
||||||
impl QuadWs {
|
impl QuadWs {
|
||||||
pub fn new(url: String) -> Self {
|
pub fn new(url: String) -> Option<Self> {
|
||||||
Self {
|
let conn = ws_open_rust(url);
|
||||||
channel: ws_open_rust(url).unwrap()
|
if conn.is_none() {
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
|
Some(Self {
|
||||||
|
channel: conn.unwrap(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
pub fn write(&mut self, data: Vec<u8>) -> bool {
|
pub fn write(&mut self, data: Vec<u8>) -> bool {
|
||||||
ws_write_rust(&mut self.channel, data)
|
ws_write_rust(&mut self.channel, data)
|
||||||
|
@ -33,12 +37,12 @@ impl QuadWs {
|
||||||
ws_read_rust(&mut self.channel)
|
ws_read_rust(&mut self.channel)
|
||||||
}
|
}
|
||||||
pub fn connected(&mut self) -> bool {
|
pub fn connected(&mut self) -> bool {
|
||||||
if let QuadWsState::WsConnected = self.state(){
|
if let QuadWsState::WsConnected = self.state() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
pub fn revive(&mut self){
|
pub fn revive(&mut self) {
|
||||||
ws_revive_rust(&mut self.channel);
|
ws_revive_rust(&mut self.channel);
|
||||||
}
|
}
|
||||||
pub fn state(&mut self) -> QuadWsState {
|
pub fn state(&mut self) -> QuadWsState {
|
||||||
|
|
Loading…
Reference in a new issue