添加一些注释,清理暂时不用的配置项
This commit is contained in:
parent
e521b07d86
commit
0562fb08b2
@ -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);
|
||||||
|
@ -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 = () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user