From b98b1cd0e5d07fd37be54592edd362f443a145ad Mon Sep 17 00:00:00 2001 From: Melonai Date: Mon, 14 Jun 2021 11:55:03 +0200 Subject: Make connection independent of type --- assets/src/network/channel/connection.ts | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'assets/src/network/channel/connection.ts') diff --git a/assets/src/network/channel/connection.ts b/assets/src/network/channel/connection.ts index e1ed2d1..c7e9012 100644 --- a/assets/src/network/channel/connection.ts +++ b/assets/src/network/channel/connection.ts @@ -6,17 +6,9 @@ import { UnregisterHandler, } from "./messages/handler"; import type { AnyMessage } from "./messages/messages"; -import { startRequest } from "./request"; -import { startShare } from "./share"; import { connectSocket, fetchToken } from "./socket"; -export enum Type { - NONE, - REQUEST, - SHARE, -} - -enum ConnectionState { +export enum ConnectionState { CONNECTING_SOCKET, FETCHING_TOKEN, CONNECTING_CHANNEL, @@ -30,7 +22,6 @@ export type Connection = { token: string | null; state: ConnectionState; handlers: Handlers; - type: Type; }; const connection: Connection = { @@ -39,23 +30,15 @@ const connection: Connection = { token: null, state: ConnectionState.CONNECTING_SOCKET, handlers: {}, - type: Type.NONE, }; -export async function start(type: Type.REQUEST | Type.SHARE) { - connection.type = type; - +export async function start() { await connectSocket(connection.socket); updateState(ConnectionState.FETCHING_TOKEN); connection.token = await fetchToken(connection.socket); - updateState(ConnectionState.CONNECTING_CHANNEL); - type === Type.SHARE - ? await startShare(connection) - : await startRequest(connection); - - updateState(ConnectionState.CONNECTED) + return connection; } export function send(event: string, data: any): Push { @@ -95,7 +78,7 @@ export function getOwnToken(): string { return connection.token; } -function updateState(state: ConnectionState) { +export function updateState(state: ConnectionState) { // TODO: Notify state listeners connection.state = state; } -- cgit 1.4.1