![Galactic Logo](https://s3.galaxybot.app/media/galactic/bridgeBanner.png?v=2) # Getting Started: Bridge A **Bridge** serves as the head for a set of Galatic [Managed Instances](https://github.com/GalaxyBotTeam/galactic.ts/wiki/Managed-Instance). It distributes the clusters across the instances and restarts them as needed or redistributes them across the instances. It starts an IPC server, through which the instances connect. *** ## 1. Start the Bridge Server ```ts filename="bridge.ts" import {Bridge} from "galactic.ts"; const bridge = new Bridge( 3000, // Port to run the bridge on "MTM1ODUzMTk2MTQ3MT...", // Your bot token ["Guilds"], // Intents to use 2, // Shards per cluster 2 // Total of clusters 300000 // Recluster timeout in ms ); bridge.start(); // Start the bridge ``` ## 2. Listen to Events (optional) The bridge outputs various events, which could be used for log outputs, for example. ```ts filename="bridge.ts" this.bridge.on("EVENT_NAME", (...) => { console.log(...) }) ``` *** # Events | Name | Signature | Occurance | |--------------------------|------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------| | CLUSTER_READY | `(cluster: BridgeClusterConnection, guilds: number, members: number) => void` | When a cluster reports ready, with the number of guilds and members it is in. | | CLUSTER_STOPPED | `(cluster: BridgeClusterConnection) => void` | When a cluster stops. | | CLUSTER_SPAWNED | `(cluster: BridgeClusterConnection, connection: BridgeHostConnection) => void` | When a cluster is spawned. | | CLUSTER_RECLUSTER | `(cluster: BridgeClusterConnection, newConnection: BridgeHostConnection, oldConnection: BridgeHostConnection) => void` | When a cluster is moved to a new instance. | | CLUSTER_HEARTBEAT_FAILED | `(cluster: BridgeClusterConnection, error: unknown) => void` | On failed heartbeat response from a cluster. | | HOST_CONNECTED | `(client: BridgeHostConnection) => void` | On new instance connection to the bridge. | | HOST_DISCONNECTED | `(client: BridgeHostConnection, reason: string) => void` |When an instance disconnects.| | ERROR | `(error: string) => void` |Internal errors during operations (e.g. reclustering without available target).| | HOST_STOP | `(instance: BridgeHostConnection) => void` |Before an instance is stopped.|