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:
commit
d37e1bfd43
|
@ -16,6 +16,8 @@ import JointActionEquipmentTableEntity from "src/entities/JointActionEquipmentTa
|
||||||
import { CustomProtocol } from "src/entities/WSProtocolCustom";
|
import { CustomProtocol } from "src/entities/WSProtocolCustom";
|
||||||
import ClientConnectionCustom from "./ClientConnectionCustom";
|
import ClientConnectionCustom from "./ClientConnectionCustom";
|
||||||
import MagicWallConfig from "src/entities/MagicWallConfig";
|
import MagicWallConfig from "src/entities/MagicWallConfig";
|
||||||
|
import WuJieReconnectingWebSocket from "./WuJieReconnectingWebSocket";
|
||||||
|
|
||||||
|
|
||||||
class _RpcInfo {
|
class _RpcInfo {
|
||||||
send_timestamp: number;
|
send_timestamp: number;
|
||||||
|
@ -45,7 +47,7 @@ class _RpcInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ClientConnection {
|
export default class ClientConnection {
|
||||||
ws: ReconnectingWebSocket | null = null;
|
ws: ReconnectingWebSocket | null|WuJieReconnectingWebSocket = null;
|
||||||
url = "";
|
url = "";
|
||||||
user_name = "";
|
user_name = "";
|
||||||
password = "";
|
password = "";
|
||||||
|
@ -67,17 +69,23 @@ export default class ClientConnection {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.user_name = user_name ?? "";
|
this.user_name = user_name ?? "";
|
||||||
this.password = password ?? "";
|
this.password = password ?? "";
|
||||||
|
const $wujie = (window as any).$wujie;
|
||||||
|
|
||||||
if (this.ws) {
|
if (this.ws) {
|
||||||
this.ws.close();
|
this.ws.close();
|
||||||
}
|
}
|
||||||
|
let flag= !!$wujie;
|
||||||
|
|
||||||
|
if(flag){
|
||||||
|
this.ws = new WuJieReconnectingWebSocket();
|
||||||
|
}else{
|
||||||
this.ws = new ReconnectingWebSocket(url);
|
this.ws = new ReconnectingWebSocket(url);
|
||||||
|
}
|
||||||
this.initializeWs();
|
this.initializeWs();
|
||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
this.checkRpcTimeout();
|
this.checkRpcTimeout();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get is_connected() {
|
get is_connected() {
|
||||||
|
@ -104,13 +112,13 @@ export default class ClientConnection {
|
||||||
|
|
||||||
initializeWs() {
|
initializeWs() {
|
||||||
if (this.ws) {
|
if (this.ws) {
|
||||||
this.ws.onclose = (ev) => {
|
this.ws.onclose = (ev: any) => {
|
||||||
this.onClose(ev);
|
this.onClose(ev);
|
||||||
};
|
};
|
||||||
this.ws.onerror = (ev) => {
|
this.ws.onerror = (ev: any) => {
|
||||||
this.onError(ev);
|
this.onError(ev);
|
||||||
};
|
};
|
||||||
this.ws.onopen = (ev) => {
|
this.ws.onopen = (ev: any) => {
|
||||||
this.onOpen(ev);
|
this.onOpen(ev);
|
||||||
};
|
};
|
||||||
this.ws.onmessage = (ev) => {
|
this.ws.onmessage = (ev) => {
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue