同步代码

This commit is contained in:
Yuan 2023-07-31 10:05:26 +08:00
parent 6c9ae09ae8
commit b189c385ae
4 changed files with 58 additions and 41 deletions

@ -1 +1 @@
Subproject commit e521b07d86e7ac10bc6cb96288ae025b677485f7 Subproject commit 91eb4a1d0835a8bc007febaf9054291c27d065ff

View File

@ -31,24 +31,27 @@ export interface MessageCliOption {
* token * token
*/ */
token?: string; token?: string;
/** // /**
* // * 认证失败处理
* @returns // * @returns
*/ // */
onAuthenticationFailed?: () => void; // onAuthenticationFailed?: () => void;
/** // /**
* // * 连接成功处理
* @param ctx // * @param ctx
* @returns // * @returns
*/ // */
onConnected?: (ctx: unknown) => void; // onConnected?: (ctx: unknown) => void;
/** // /**
* // * 端口连接处理
*/ // */
onDisconnected?: (ctx: unknown) => void; // onDisconnected?: (ctx: unknown) => void;
reconnectDelay?: number; // 重连延时默认3秒,设置为0不重连. // // 重连延时默认3秒,设置为0不重连.
heartbeatIncoming?: number; // 服务端过来的心跳间隔默认30秒 // reconnectDelay?: number;
heartbeatOutgoing?: number; // 到服务端的心跳间隔默认30秒 // // 服务端过来的心跳间隔默认30秒
// heartbeatIncoming?: number;
// // 到服务端的心跳间隔默认30秒
// heartbeatOutgoing?: number;
} }
const DefaultStompOption: MessageCliOption = { const DefaultStompOption: MessageCliOption = {
@ -56,9 +59,9 @@ const DefaultStompOption: MessageCliOption = {
protocol: 'protobuf', protocol: 'protobuf',
wsUrl: '', wsUrl: '',
token: '', token: '',
reconnectDelay: 3000, // reconnectDelay: 3000,
heartbeatIncoming: 30000, // heartbeatIncoming: 30000,
heartbeatOutgoing: 30000, // heartbeatOutgoing: 30000,
}; };
export interface IMessageClient extends EventEmitter<MessageClientEvents> { export interface IMessageClient extends EventEmitter<MessageClientEvents> {
@ -69,8 +72,14 @@ export interface IMessageClient extends EventEmitter<MessageClientEvents> {
*/ */
subscribe(destination: string, handle: MessageHandler): ISubscription; subscribe(destination: string, handle: MessageHandler): ISubscription;
/**
*
*/
get connected(): boolean; get connected(): boolean;
/**
*
*/
close(): void; close(): void;
} }
@ -219,6 +228,9 @@ export class AppWsMsgBroker {
this.subscriptions.set(sub.destination, sub); this.subscriptions.set(sub.destination, sub);
} }
/**
*
*/
resubscribe() { resubscribe() {
this.subscriptions.forEach((record) => { this.subscriptions.forEach((record) => {
this.subscribe(record); this.subscribe(record);

View File

@ -6,6 +6,10 @@ import {
MessageHandler, MessageHandler,
} from './BasicMessageClient'; } from './BasicMessageClient';
const ReconnectDelay = 3000;
const HeartbeatIncoming = 30000;
const HeartbeatOutgoing = 30000;
export class StompMessagingClient extends MessageClient { export class StompMessagingClient extends MessageClient {
options: MessageCliOption; options: MessageCliOption;
cli: StompClient; cli: StompClient;
@ -17,9 +21,9 @@ export class StompMessagingClient extends MessageClient {
connectHeaders: { connectHeaders: {
Authorization: options.token ? options.token : '', Authorization: options.token ? options.token : '',
}, },
reconnectDelay: options.reconnectDelay, reconnectDelay: ReconnectDelay,
heartbeatIncoming: options.heartbeatIncoming, heartbeatIncoming: HeartbeatIncoming,
heartbeatOutgoing: options.heartbeatOutgoing, heartbeatOutgoing: HeartbeatOutgoing,
}); });
this.cli.onConnect = () => { this.cli.onConnect = () => {
@ -29,6 +33,7 @@ export class StompMessagingClient extends MessageClient {
const errMsg = frame.headers['message']; const errMsg = frame.headers['message'];
if (errMsg === '401') { if (errMsg === '401') {
console.warn('认证失败,断开WebSocket连接'); console.warn('认证失败,断开WebSocket连接');
this.cli.deactivate();
} else { } else {
console.error('收到Stomp错误消息', frame); console.error('收到Stomp错误消息', frame);
} }

View File

@ -195,7 +195,7 @@
"@pixi/graphics-extras@^7.2.4": "@pixi/graphics-extras@^7.2.4":
version "7.2.4" version "7.2.4"
resolved "https://registry.yarnpkg.com/@pixi/graphics-extras/-/graphics-extras-7.2.4.tgz#72ac967992f239d3671d6e680ac891471619fe07" resolved "https://registry.npmjs.org/@pixi/graphics-extras/-/graphics-extras-7.2.4.tgz"
integrity sha512-0yT91yqF3KLiZI/iLRcfcYlTVpkVyWsfGtWEIorZs0eX+/zYx7um7EJ2h7tFORI/1FxA2maR4td5vpgCwOLJAQ== integrity sha512-0yT91yqF3KLiZI/iLRcfcYlTVpkVyWsfGtWEIorZs0eX+/zYx7um7EJ2h7tFORI/1FxA2maR4td5vpgCwOLJAQ==
"@pixi/graphics@7.2.4": "@pixi/graphics@7.2.4":
@ -316,27 +316,27 @@
"@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2": "@protobufjs/aspromise@^1.1.1", "@protobufjs/aspromise@^1.1.2":
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz#9b8b0cc663d669a7d8f6f5d0893a14d348f30fbf" resolved "https://registry.npmmirror.com/@protobufjs/aspromise/-/aspromise-1.1.2.tgz"
integrity sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ== integrity sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==
"@protobufjs/base64@^1.1.2": "@protobufjs/base64@^1.1.2":
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/@protobufjs/base64/-/base64-1.1.2.tgz#4c85730e59b9a1f1f349047dbf24296034bb2735" resolved "https://registry.npmmirror.com/@protobufjs/base64/-/base64-1.1.2.tgz"
integrity sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg== integrity sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==
"@protobufjs/codegen@^2.0.4": "@protobufjs/codegen@^2.0.4":
version "2.0.4" version "2.0.4"
resolved "https://registry.yarnpkg.com/@protobufjs/codegen/-/codegen-2.0.4.tgz#7ef37f0d010fb028ad1ad59722e506d9262815cb" resolved "https://registry.npmmirror.com/@protobufjs/codegen/-/codegen-2.0.4.tgz"
integrity sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg== integrity sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==
"@protobufjs/eventemitter@^1.1.0": "@protobufjs/eventemitter@^1.1.0":
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz#355cbc98bafad5978f9ed095f397621f1d066b70" resolved "https://registry.npmmirror.com/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz"
integrity sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q== integrity sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==
"@protobufjs/fetch@^1.1.0": "@protobufjs/fetch@^1.1.0":
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/fetch/-/fetch-1.1.0.tgz#ba99fb598614af65700c1619ff06d454b0d84c45" resolved "https://registry.npmmirror.com/@protobufjs/fetch/-/fetch-1.1.0.tgz"
integrity sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ== integrity sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==
dependencies: dependencies:
"@protobufjs/aspromise" "^1.1.1" "@protobufjs/aspromise" "^1.1.1"
@ -344,27 +344,27 @@
"@protobufjs/float@^1.0.2": "@protobufjs/float@^1.0.2":
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/@protobufjs/float/-/float-1.0.2.tgz#5e9e1abdcb73fc0a7cb8b291df78c8cbd97b87d1" resolved "https://registry.npmmirror.com/@protobufjs/float/-/float-1.0.2.tgz"
integrity sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ== integrity sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==
"@protobufjs/inquire@^1.1.0": "@protobufjs/inquire@^1.1.0":
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/inquire/-/inquire-1.1.0.tgz#ff200e3e7cf2429e2dcafc1140828e8cc638f089" resolved "https://registry.npmmirror.com/@protobufjs/inquire/-/inquire-1.1.0.tgz"
integrity sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q== integrity sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==
"@protobufjs/path@^1.1.2": "@protobufjs/path@^1.1.2":
version "1.1.2" version "1.1.2"
resolved "https://registry.yarnpkg.com/@protobufjs/path/-/path-1.1.2.tgz#6cc2b20c5c9ad6ad0dccfd21ca7673d8d7fbf68d" resolved "https://registry.npmmirror.com/@protobufjs/path/-/path-1.1.2.tgz"
integrity sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA== integrity sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==
"@protobufjs/pool@^1.1.0": "@protobufjs/pool@^1.1.0":
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/pool/-/pool-1.1.0.tgz#09fd15f2d6d3abfa9b65bc366506d6ad7846ff54" resolved "https://registry.npmmirror.com/@protobufjs/pool/-/pool-1.1.0.tgz"
integrity sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw== integrity sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==
"@protobufjs/utf8@^1.1.0": "@protobufjs/utf8@^1.1.0":
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570" resolved "https://registry.npmmirror.com/@protobufjs/utf8/-/utf8-1.1.0.tgz"
integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw== integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==
"@quasar/app-vite@^1.0.0": "@quasar/app-vite@^1.0.0":
@ -546,7 +546,7 @@
"@types/node@>=13.7.0": "@types/node@>=13.7.0":
version "20.4.5" version "20.4.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.4.5.tgz#9dc0a5cb1ccce4f7a731660935ab70b9c00a5d69" resolved "https://registry.npmmirror.com/@types/node/-/node-20.4.5.tgz"
integrity sha512-rt40Nk13II9JwQBdeYqmbn2Q6IVTA5uPhvSO+JVqdXw/6/4glI6oR9ezty/A9Hg5u7JH4OmYmuQ+XvjKm0Datg== integrity sha512-rt40Nk13II9JwQBdeYqmbn2Q6IVTA5uPhvSO+JVqdXw/6/4glI6oR9ezty/A9Hg5u7JH4OmYmuQ+XvjKm0Datg==
"@types/node@^12.20.21": "@types/node@^12.20.21":
@ -1049,7 +1049,7 @@ caniuse-lite@^1.0.30001464, caniuse-lite@^1.0.30001489:
centrifuge@^4.0.1: centrifuge@^4.0.1:
version "4.0.1" version "4.0.1"
resolved "https://registry.yarnpkg.com/centrifuge/-/centrifuge-4.0.1.tgz#2607756d4b7da6201ca12666bfc6564e4e8ef6a2" resolved "https://registry.npmmirror.com/centrifuge/-/centrifuge-4.0.1.tgz"
integrity sha512-akAyUfvMnyoCa6X2tdU5WPEccVqjkb9R/xxfm3iJ7ha7EIawjKu1dQmoyMkoLDpgl0jFxhorjmVgRcbojE17DA== integrity sha512-akAyUfvMnyoCa6X2tdU5WPEccVqjkb9R/xxfm3iJ7ha7EIawjKu1dQmoyMkoLDpgl0jFxhorjmVgRcbojE17DA==
dependencies: dependencies:
events "^3.3.0" events "^3.3.0"
@ -1776,7 +1776,7 @@ eventemitter3@^4.0.0:
events@^3.3.0: events@^3.3.0:
version "3.3.0" version "3.3.0"
resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400" resolved "https://registry.npmmirror.com/events/-/events-3.3.0.tgz"
integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q== integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==
express@^4.17.3: express@^4.17.3:
@ -2389,7 +2389,7 @@ log-symbols@^4.1.0:
long@^5.0.0: long@^5.0.0:
version "5.2.3" version "5.2.3"
resolved "https://registry.yarnpkg.com/long/-/long-5.2.3.tgz#a3ba97f3877cf1d778eccbcb048525ebb77499e1" resolved "https://registry.npmmirror.com/long/-/long-5.2.3.tgz"
integrity sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q== integrity sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==
lower-case@^1.1.1: lower-case@^1.1.1:
@ -2782,7 +2782,7 @@ process-nextick-args@~2.0.0:
protobufjs@^7.2.4: protobufjs@^7.2.4:
version "7.2.4" version "7.2.4"
resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-7.2.4.tgz#3fc1ec0cdc89dd91aef9ba6037ba07408485c3ae" resolved "https://registry.npmmirror.com/protobufjs/-/protobufjs-7.2.4.tgz"
integrity sha512-AT+RJgD2sH8phPmCf7OUZR8xGdcJRga4+1cOaXJ64hvcSkVhNcRHOwIxUatPH15+nj59WAGTDv3LSGZPEQbJaQ== integrity sha512-AT+RJgD2sH8phPmCf7OUZR8xGdcJRga4+1cOaXJ64hvcSkVhNcRHOwIxUatPH15+nj59WAGTDv3LSGZPEQbJaQ==
dependencies: dependencies:
"@protobufjs/aspromise" "^1.1.2" "@protobufjs/aspromise" "^1.1.2"