From 67846e2683f9f3194513683b4825915b968ac486 Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Fri, 18 Jul 2025 10:53:40 +0800 Subject: rename messages.ts --- packages/airmx/src/airmx.ts | 4 +-- packages/airmx/src/message.ts | 59 ------------------------------------------ packages/airmx/src/messages.ts | 59 ++++++++++++++++++++++++++++++++++++++++++ packages/airmx/src/util.ts | 2 +- 4 files changed, 62 insertions(+), 62 deletions(-) delete mode 100644 packages/airmx/src/message.ts create mode 100644 packages/airmx/src/messages.ts (limited to 'packages') diff --git a/packages/airmx/src/airmx.ts b/packages/airmx/src/airmx.ts index cd7aeaf..be67a58 100644 --- a/packages/airmx/src/airmx.ts +++ b/packages/airmx/src/airmx.ts @@ -1,12 +1,12 @@ import crypto from 'crypto' import { MqttClient } from 'mqtt' import { EagleStatus } from './eagle.js' -import { EagleControlMesasge } from './message.js' +import { EagleControlMesasge } from './messages.js' import { SnowStatus } from './snow.js' import type { Config, SnowListener, EagleListener, EagleControlData } from './types.js' import { Command } from './types.js' import { Signer } from './util.js' -import type { CommandMessage } from './message.js' +import type { CommandMessage } from './messages.js' export class Topic { constructor( diff --git a/packages/airmx/src/message.ts b/packages/airmx/src/message.ts deleted file mode 100644 index 6bac4f5..0000000 --- a/packages/airmx/src/message.ts +++ /dev/null @@ -1,59 +0,0 @@ -import type { EagleControlData, InstantPushData } from './types.js' -import { MessageSource } from './types.js' - -export class CommandMessage { - constructor( - readonly commandId: number, - readonly commandName: string, - readonly data: T, - readonly time: number, - readonly from: number - ) {} - - payload() { - return { - cmdId: this.commandId, - name: this.commandName, - time: this.time, - from: this.from, - data: this.data, - } - } -} - -const current = () => { - return Math.floor(new Date().getTime() / 1000) -} - -export class InstantPushMessage extends CommandMessage { - static commandId() { - return 40 - } - - /** - * @param frequency - Report frequency in seconds. - * @param duration - Report duration in seconds. - */ - static make(frequency: number, duration: number) { - const data = { - frequencyTime: frequency, - durationTime: duration - } - return new InstantPushMessage( - this.commandId(), 'instantPush', data, current(), MessageSource.App_Android - ) - } -} - -export class EagleControlMesasge extends CommandMessage { - static commandId() { - return 100 - } - - static make(data: EagleControlData) { - const timestamp = Math.floor(new Date().getTime() / 1000) - return new EagleControlMesasge( - this.commandId(), 'control', data, timestamp, MessageSource.App_Android - ) - } -} diff --git a/packages/airmx/src/messages.ts b/packages/airmx/src/messages.ts new file mode 100644 index 0000000..6bac4f5 --- /dev/null +++ b/packages/airmx/src/messages.ts @@ -0,0 +1,59 @@ +import type { EagleControlData, InstantPushData } from './types.js' +import { MessageSource } from './types.js' + +export class CommandMessage { + constructor( + readonly commandId: number, + readonly commandName: string, + readonly data: T, + readonly time: number, + readonly from: number + ) {} + + payload() { + return { + cmdId: this.commandId, + name: this.commandName, + time: this.time, + from: this.from, + data: this.data, + } + } +} + +const current = () => { + return Math.floor(new Date().getTime() / 1000) +} + +export class InstantPushMessage extends CommandMessage { + static commandId() { + return 40 + } + + /** + * @param frequency - Report frequency in seconds. + * @param duration - Report duration in seconds. + */ + static make(frequency: number, duration: number) { + const data = { + frequencyTime: frequency, + durationTime: duration + } + return new InstantPushMessage( + this.commandId(), 'instantPush', data, current(), MessageSource.App_Android + ) + } +} + +export class EagleControlMesasge extends CommandMessage { + static commandId() { + return 100 + } + + static make(data: EagleControlData) { + const timestamp = Math.floor(new Date().getTime() / 1000) + return new EagleControlMesasge( + this.commandId(), 'control', data, timestamp, MessageSource.App_Android + ) + } +} diff --git a/packages/airmx/src/util.ts b/packages/airmx/src/util.ts index 08400a7..0b21b0d 100644 --- a/packages/airmx/src/util.ts +++ b/packages/airmx/src/util.ts @@ -1,5 +1,5 @@ import crypto from 'crypto' -import type { CommandMessage } from './message.js' +import type { CommandMessage } from './messages.js' export class Signer { sign(message: CommandMessage, key: string) { -- cgit v1.2.3