mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-30 06:31:02 +00:00
feat(packages): add shared package
This commit is contained in:
27
packages/shared/src/constants/DisconnectReason.ts
Executable file
27
packages/shared/src/constants/DisconnectReason.ts
Executable file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Disconnect reasons for clients
|
||||
*/
|
||||
enum DisconnectReason {
|
||||
/**
|
||||
* Unknown reason
|
||||
*/
|
||||
Generic = 1,
|
||||
/**
|
||||
* The client did not respond in time
|
||||
*/
|
||||
TimedOut,
|
||||
/**
|
||||
* The client sent an invalid packet (unserializable or invalid JSON)
|
||||
*/
|
||||
InvalidPacket,
|
||||
/**
|
||||
* The server has encountered an internal error
|
||||
*/
|
||||
ServerError,
|
||||
/**
|
||||
* The client had never connected to the server (**CLIENT-ONLY**)
|
||||
*/
|
||||
NeverConnected
|
||||
}
|
||||
|
||||
export default DisconnectReason
|
||||
11
packages/shared/src/constants/HumanizedDisconnectReason.ts
Executable file
11
packages/shared/src/constants/HumanizedDisconnectReason.ts
Executable file
@@ -0,0 +1,11 @@
|
||||
import DisconnectReason from './DisconnectReason.js'
|
||||
|
||||
const HumanizedDisconnectReason = {
|
||||
[DisconnectReason.InvalidPacket]: 'has sent invalid packet',
|
||||
[DisconnectReason.Generic]: 'has been disconnected for unknown reasons',
|
||||
[DisconnectReason.TimedOut]: 'has timed out',
|
||||
[DisconnectReason.ServerError]: 'has been disconnected due to an internal server error',
|
||||
[DisconnectReason.NeverConnected]: 'had never connected to the server'
|
||||
} as const satisfies Record<DisconnectReason, string>
|
||||
|
||||
export default HumanizedDisconnectReason
|
||||
57
packages/shared/src/constants/Operation.ts
Executable file
57
packages/shared/src/constants/Operation.ts
Executable file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Client operation codes for the gateway
|
||||
*/
|
||||
export enum ClientOperation {
|
||||
/**
|
||||
* Client's heartbeat (to check if the connection is dead or not)
|
||||
*/
|
||||
Heartbeat = 100,
|
||||
|
||||
/**
|
||||
* Client's request to parse text
|
||||
*/
|
||||
ParseText = 110,
|
||||
/**
|
||||
* Client's request to parse image
|
||||
*/
|
||||
ParseImage,
|
||||
}
|
||||
|
||||
/**
|
||||
* Server operation codes for the gateway
|
||||
*/
|
||||
export enum ServerOperation {
|
||||
/**
|
||||
* Server's acknowledgement of a client's heartbeat
|
||||
*/
|
||||
HeartbeatAck = 1,
|
||||
/**
|
||||
* Server's initial response to a client's connection
|
||||
*/
|
||||
Hello,
|
||||
|
||||
/**
|
||||
* Server's response to client's request to parse text
|
||||
*/
|
||||
ParsedText = 10,
|
||||
/**
|
||||
* Server's response to client's request to parse image
|
||||
*/
|
||||
ParsedImage,
|
||||
/**
|
||||
* Server's failure response to client's request to parse text
|
||||
*/
|
||||
ParseTextFailed,
|
||||
/**
|
||||
* Server's failure response to client's request to parse image
|
||||
*/
|
||||
ParseImageFailed,
|
||||
|
||||
/**
|
||||
* Server's disconnect message
|
||||
*/
|
||||
Disconnect = 20
|
||||
}
|
||||
|
||||
export const Operation = { ...ClientOperation, ...ServerOperation } as const
|
||||
export type Operation = (ClientOperation | ServerOperation)
|
||||
3
packages/shared/src/constants/index.ts
Executable file
3
packages/shared/src/constants/index.ts
Executable file
@@ -0,0 +1,3 @@
|
||||
export { default as DisconnectReason } from './DisconnectReason.js'
|
||||
export { default as HumanizedDisconnectReason } from './HumanizedDisconnectReason.js'
|
||||
export * from './Operation.js'
|
||||
Reference in New Issue
Block a user