You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.9 KiB
75 lines
2.9 KiB
import {
|
|
ClientGoodbyeAction,
|
|
ClientHelloCommand,
|
|
ClientRefreshCommand,
|
|
SendableAction,
|
|
SentAction
|
|
} from "../../../common/src/actions/ClientAction";
|
|
import {SyncedState} from "../../../common/src/state/SyncedState";
|
|
|
|
export enum ServerConnectionState {
|
|
/** Used when the client is going through the WebSockets connection process and sending a Hello. */
|
|
CONNECTING = "CONNECTING",
|
|
/** Used when the client has sent a hello, and is waiting for the server to respond. */
|
|
AWAITING_HELLO = "AWAITING_HELLO",
|
|
/** Used when the client has sent a refresh request, and is waiting for the server to respond. */
|
|
AWAITING_REFRESH = "AWAITING_REFRESH",
|
|
/** Used when the client is connected and everything is normal. */
|
|
CONNECTED = "CONNECTED",
|
|
/**
|
|
* Used when the client has requested that the connection be closed,
|
|
* and is waiting for it to actually be closed.
|
|
*/
|
|
AWAITING_GOODBYE = "AWAITING_GOODBYE",
|
|
/**
|
|
* Used when the client is disconnected and not currently connecting,
|
|
* such as when waiting for the automatic reconnect, or if the browser is currently in offline mode,
|
|
* or if the client was disconnected due to a protocol error.
|
|
*/
|
|
OFFLINE = "OFFLINE"
|
|
}
|
|
|
|
export interface NetworkState {
|
|
/**
|
|
* The current state of the server, as this client knows it.
|
|
* Used to keep a clean state for applying pending actions to if, for any reason, the current state needs to be
|
|
* recalculated from the server and pending states (e.g., if a server action comes in, or a pending action
|
|
* is applied).
|
|
*
|
|
* Null iff the connection has never been established.
|
|
*/
|
|
readonly serverState: SyncedState|null
|
|
/**
|
|
* The current state of the connection.
|
|
*/
|
|
readonly connectionState: ServerConnectionState
|
|
/**
|
|
* A special action that should take precedence over sending more actions.
|
|
*/
|
|
readonly specialMessage: ClientHelloCommand|ClientRefreshCommand|ClientGoodbyeAction|null
|
|
/**
|
|
* The ID of the next ClientSentAction to be created.
|
|
*/
|
|
readonly nextID: number
|
|
/**
|
|
* Messages that were sent to the server but have not yet received a response.
|
|
* These come before pendingActions.
|
|
*/
|
|
readonly sentActions: readonly SentAction[]
|
|
/** Yet-unsent actions that originated here. These come after sentActions. */
|
|
readonly pendingActions: readonly SendableAction[]
|
|
/**
|
|
* The error code of the close message.
|
|
* Non-null if and only if the current state is OFFLINE or REJECTED.
|
|
*/
|
|
readonly goodbyeCode: number | null
|
|
/**
|
|
* The error reason of the close message.
|
|
* Non-null if and only if the current state is OFFLINE or REJECTED.
|
|
*/
|
|
readonly goodbyeReason: string | null
|
|
/** The time the client will attempt to reconnect, if at all. */
|
|
readonly autoReconnectAt: Date | null
|
|
/** The number of attempts at reconnecting. */
|
|
readonly reconnectAttempts: number | null
|
|
} |