Merge pull request '添加无界连接对象' (#1) from iswebserve into master

Reviewed-on: http://www.cloudview.work/git/fangxiang/media_player_client/pulls/1
This commit is contained in:
方 向 2023-01-16 09:34:41 +08:00
commit d37e1bfd43
2 changed files with 1524 additions and 1455 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,61 @@
import { IWuJieInterface } from './../store/index';
import { store } from 'quasar/wrappers';
export default class WuJieReconnectingWebSocket {
readyState: number ;
$wujie : IWuJieInterface;
constructor() {
this.readyState=WebSocket.OPEN;
this.onclose=(ev:any)=>{}
this.onerror=(ev:any)=>{}
this.onmessage=(ev:any)=>{}
this.onopen=(ev:any)=>{}
this.$wujie = (window as any).$wujie;
if(this.$wujie){
this.$wujie.bus.$on("onclose",this.onclose)
this.$wujie.bus.$on("onerror",this.onerror)
this.$wujie.bus.$on("onmessage", (ev:any)=>{
if(this.onmessage) {
this.onmessage(ev)
}
})
this.$wujie.bus.$on("onopen",this.onopen)
setTimeout(() => {
if(this.onopen){
this.onopen(null);
}
},1000);
}
}
onclose: ((event: any) => void) | null;
/**
* An event listener to be called when an error occurs
*/
onerror: ((event: any) => void) | null;
/**
* An event listener to be called when a message is received from the server
*/
onmessage: ((event: MessageEvent) => void) | null;
/**
* An event listener to be called when the WebSocket connection's readyState changes to OPEN;
* this indicates that the connection is ready to send and receive data
*/
onopen: ((event: any) => void) | null;
/**
* Closes the WebSocket connection or connection attempt, if any. If the connection is already
* CLOSED, this method does nothing
*/
close(code?: number, reason?: string){
}
/**
* Enqueue specified data to be transmitted to the server over the WebSocket connection
*/
send(data: string) {
if(this.$wujie){
this.$wujie.bus.$emit("send_to",data)
}
}
}