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

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
*/ */
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 = () => {