添加一些注释,清理暂时不用的配置项

This commit is contained in:
walker 2023-07-28 16:22:35 +08:00
parent e521b07d86
commit 0562fb08b2
2 changed files with 40 additions and 24 deletions

View File

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

View File

@ -6,6 +6,10 @@ import {
MessageHandler,
} from './BasicMessageClient';
const ReconnectDelay = 3000;
const HeartbeatIncoming = 30000;
const HeartbeatOutgoing = 30000;
export class StompMessagingClient extends MessageClient {
options: MessageCliOption;
cli: StompClient;
@ -17,9 +21,9 @@ export class StompMessagingClient extends MessageClient {
connectHeaders: {
Authorization: options.token ? options.token : '',
},
reconnectDelay: options.reconnectDelay,
heartbeatIncoming: options.heartbeatIncoming,
heartbeatOutgoing: options.heartbeatOutgoing,
reconnectDelay: ReconnectDelay,
heartbeatIncoming: HeartbeatIncoming,
heartbeatOutgoing: HeartbeatOutgoing,
});
this.cli.onConnect = () => {