### Start Development Server Source: https://github.com/socketodev/socketo/blob/main/README.md Run the development server for all applications or a specific application using Bun filters. This command starts the local development environment. ```bash bun run dev # all apps bun run --filter=@apps/server dev # server only ``` -------------------------------- ### Install Dependencies Source: https://github.com/socketodev/socketo/blob/main/README.md Install project dependencies using Bun. This command should be run in the project's root directory. ```bash bun install ``` -------------------------------- ### Get Single Channel Info Source: https://github.com/socketodev/socketo/blob/main/README.md Retrieves detailed information about a specific channel within an application. ```APIDOC ## GET /apps/:key/channels/:channel_name ### Description Fetches detailed information for a specific channel, including its occupancy status and user counts. ### Method GET ### Endpoint /apps/:key/channels/:channel_name ### Parameters #### Path Parameters - **key** (string) - Required - The unique identifier for the application. - **channel_name** (string) - Required - The name of the channel to retrieve information for. ### Response #### Success Response (200 OK) - **occupied** (boolean) - True if the channel has active subscribers, false otherwise. - **user_count** (integer) - The number of unique users currently subscribed to the channel. - **subscription_count** (integer) - The total number of subscriptions to the channel. ``` -------------------------------- ### Get Channel List Source: https://github.com/socketodev/socketo/blob/main/README.md Retrieves a list of all channels within an application, along with their current subscription counts. Supports filtering by channel name prefix. ```APIDOC ## GET /apps/:key/channels ### Description Lists all channels in an application and provides the number of subscribers for each channel. Can be filtered by a channel name prefix. ### Method GET ### Endpoint /apps/:key/channels ### Parameters #### Path Parameters - **key** (string) - Required - The unique identifier for the application. #### Query Parameters - **filter_by_prefix** (string) - Optional - Filters channels to include only those starting with the specified prefix (e.g., `presence-`). ### Response #### Success Response (200 OK) - **channels** (object) - An object where keys are channel names and values are objects containing channel information. - **occupied** (boolean) - Indicates if the channel has any subscribers. - **user_count** (integer) - The number of users currently subscribed to the channel. - **subscription_count** (integer) - The total number of subscriptions to the channel. ``` -------------------------------- ### Get Users in Presence Channel Source: https://github.com/socketodev/socketo/blob/main/README.md Retrieves a list of user IDs subscribed to a specific presence channel. ```APIDOC ## GET /apps/:key/channels/:channel_name/users ### Description Returns a list of user identifiers who are currently subscribed to a given presence channel. ### Method GET ### Endpoint /apps/:key/channels/:channel_name/users ### Parameters #### Path Parameters - **key** (string) - Required - The unique identifier for the application. - **channel_name** (string) - Required - The name of the presence channel. ### Response #### Success Response (200 OK) - **users** (object) - An object containing user information. - **ids** (array) - An array of user IDs subscribed to the channel. - **hash** (object) - A hash map of user IDs to their associated channel data. - **count** (integer) - The total number of users subscribed to the channel. ``` -------------------------------- ### Get Active Socket Count Source: https://github.com/socketodev/socketo/blob/main/README.md Retrieves the number of currently active WebSocket connections for a given application. ```APIDOC ## GET /apps/:key/sockets ### Description Returns the total count of active WebSocket connections for the specified application. ### Method GET ### Endpoint /apps/:key/sockets ### Parameters #### Path Parameters - **key** (string) - Required - The unique identifier for the application. ### Response #### Success Response (200 OK) - **sockets** (integer) - The number of active sockets. ``` -------------------------------- ### Deploy Server Application Source: https://github.com/socketodev/socketo/blob/main/README.md Deploy the server application using Bun. This command is used for manual deployment of the server component. ```bash bun run --filter=@apps/server deploy ``` -------------------------------- ### Run Database Migrations Source: https://github.com/socketodev/socketo/blob/main/README.md Execute database migrations by sending a POST request to the migrate endpoint. This ensures your database schema is up-to-date. ```bash curl -X POST http://localhost:8787/migrate ``` -------------------------------- ### WebSocket Upgrade Source: https://github.com/socketodev/socketo/blob/main/README.md Initiates a WebSocket connection for real-time communication. Requires specific headers and query parameters. ```APIDOC ## GET /app/:key ### Description Establishes a WebSocket connection. This endpoint is used to upgrade an HTTP connection to a WebSocket connection. ### Method GET ### Endpoint /app/:key ### Parameters #### Query Parameters - **protocol** (string) - Required - Must be `7` to indicate the Pusher protocol version. ### Headers - **Upgrade** (string) - Required - Must be `websocket`. ### Response #### Success Response (101 Switching Protocols) - The server responds with a 101 status code, indicating that the connection is being switched to WebSocket. ``` -------------------------------- ### Presence Channel Subscription and Signin Source: https://github.com/socketodev/socketo/blob/main/README.md For presence channels, first sign in with an authentication signature and user data, then subscribe to the channel. Member lifecycle events are automatically broadcast. ```javascript // 1. Sign in pusher.signin({ auth: "", user_data: JSON.stringify({ id: "123", user_info: { name: "Alice" } }) }) // 2. Subscribe pusher.subscribe("presence-chat") ``` -------------------------------- ### Initialize Pusher JS SDK for Socketo Source: https://github.com/socketodev/socketo/blob/main/README.md Connect to Socketo using the Pusher JS SDK. Ensure your APP_KEY and worker host are correctly configured. This snippet is for client-side integration. ```javascript import Pusher from "pusher-js" const pusher = new Pusher("APP_KEY", { wsHost: "your-worker.workers.dev", wssPort: 443, forceTLS: true, enabledTransports: ["ws"], cluster: "socketo", }); const channel = pusher.subscribe("my-channel").bind("my-event", (message) => { console.log(message); }) ``` -------------------------------- ### Initialize Pusher Server SDK for Socketo Broadcast Source: https://github.com/socketodev/socketo/blob/main/README.md Broadcast messages from your backend to clients using the Pusher server SDK. Configure your APP_ID, APP_KEY, APP_SECRET, and worker host. This snippet is for server-side integration. ```javascript import Pusher from "pusher" const pusher = new Pusher({ appId: "APP_ID", key: "APP_KEY", secret: "APP_SECRET", host: "your-worker.workers.dev", useTLS: true, }); // Trigger an event named 'my-event' on a channel called 'my-channel' await pusher.trigger("my-channel", "my-event", { message: "Hello from server", }); ``` -------------------------------- ### Trigger Batch Events Source: https://github.com/socketodev/socketo/blob/main/README.md Triggers multiple events to be broadcast efficiently in a single request. ```APIDOC ## POST /apps/:key/batch_events ### Description Allows triggering multiple events in a single API call, which can be more efficient than making individual requests for each event. ### Method POST ### Endpoint /apps/:key/batch_events ### Parameters #### Path Parameters - **key** (string) - Required - The unique identifier for the application. #### Request Body - **batch** (array) - Required - An array of event objects. Each object should have `name`, `channels`, and `data` properties similar to the single event trigger. - **name** (string) - Required - The name of the event. - **channels** (array) - Required - An array of channel names. - **data** (string) - Required - The event payload. - **socket_id** (string) - Optional - Excludes the sender's socket. ### Request Example ```json { "batch": [ { "name": "event1", "channels": ["channel1"], "data": "{\"message\": \"Data for event 1\"}" }, { "name": "event2", "channels": ["channel2"], "data": "{\"message\": \"Data for event 2\"}" } ] } ``` ### Response #### Success Response (200 OK) - An empty response body indicates the batch of events was successfully queued. ``` -------------------------------- ### Trigger Client-Side Event Source: https://github.com/socketodev/socketo/blob/main/README.md Send a custom event from the client to the server or other clients using the subscribed channel. This requires a channel object obtained from pusher.subscribe(). ```js channel.trigger("client-my-event", { message: "Hello from client" }); ``` -------------------------------- ### Trigger Single Event Source: https://github.com/socketodev/socketo/blob/main/README.md Triggers a single event to be broadcast to clients subscribed to specified channels. ```APIDOC ## POST /apps/:key/events ### Description Sends a single event to one or more channels. This is used for broadcasting messages to connected clients. ### Method POST ### Endpoint /apps/:key/events ### Parameters #### Path Parameters - **key** (string) - Required - The unique identifier for the application. #### Request Body - **name** (string) - Required - The name of the event to trigger. - **channels** (array) - Required - An array of channel names to send the event to. - **data** (string) - Required - The payload of the event, typically a JSON string. - **socket_id** (string) - Optional - If provided, the event will not be sent to the sender's socket. ### Request Example ```json { "name": "new-message", "channels": ["private-orders", "public-chat"], "data": "{\"message\": \"Hello world!\"}" } ``` ### Response #### Success Response (200 OK) - An empty response body indicates the event was successfully queued for broadcasting. ``` -------------------------------- ### Private Channel Subscription Source: https://github.com/socketodev/socketo/blob/main/README.md To subscribe to a private channel, generate an auth signature server-side using your app secret and include it in the subscription payload. ```text pusher:subscribe → { "channel": "private-orders", "auth": ":" } ``` -------------------------------- ### Terminate User Connections Source: https://github.com/socketodev/socketo/blob/main/README.md Terminates all active WebSocket connections associated with a specific user ID. ```APIDOC ## POST /apps/:key/users/:user_id/terminate_connections ### Description Forces disconnection of all WebSocket connections belonging to a specified user. ### Method POST ### Endpoint /apps/:key/users/:user_id/terminate_connections ### Parameters #### Path Parameters - **key** (string) - Required - The unique identifier for the application. - **user_id** (string) - Required - The ID of the user whose connections should be terminated. ### Response #### Success Response (200 OK) - An empty response body indicates the connections were successfully terminated. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.