npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@casual-simulation/aux-websocket-aws

v4.2.0

Published

AWS API Gateway Websocket integration with AUX services

Downloads

2,599

Readme

@casual-simulation/aux-websocket-aws

AWS API Gateway WebSocket integration layer for CasualOS (AUX) services, providing specialized handling for AWS API Gateway's WebSocket message size limitations.

Overview

This package provides a WebSocket client specifically designed for connecting to CasualOS (AUX) services hosted on AWS API Gateway. It extends the standard WebSocket protocol with automatic large message handling through S3 upload/download mechanisms, working around AWS API Gateway's 32KB message size limit.

Main Export

ApiGatewayWebsocketConnectionClient

A specialized WebSocket client that implements the ConnectionClient interface with AWS API Gateway-specific features, particularly automatic handling of large messages through S3 presigned URLs.

Features:

  • Automatic Large Message Handling: Messages exceeding 32KB are automatically uploaded to S3 via presigned URLs
  • Message Size Detection: Automatically detects when messages exceed AWS API Gateway limits
  • Upload/Download Protocol: Implements a custom protocol for transferring large messages via HTTP
  • Transparent to Application: Large message handling is completely transparent to the application layer
  • Connection State Management: Full connection state tracking via RxJS observables
  • Error Handling: Dedicated error stream for connection and protocol errors
  • Type-Safe: Built with TypeScript for full type safety

Key Methods:

  • connect() - Establish WebSocket connection to AWS API Gateway
  • disconnect() - Close WebSocket connection
  • send(message) - Send a message (automatically handles large messages)
  • event<T>(name) - Subscribe to specific event types
  • connectionState - Observable of connection state changes
  • onError - Observable of error events

Usage:

import { ApiGatewayWebsocketConnectionClient } from '@casual-simulation/aux-websocket-aws';
import { ReconnectableSocket } from '@casual-simulation/websocket';

// Create underlying WebSocket connection to AWS API Gateway
const socket = new ReconnectableSocket(
    'wss://your-api-gateway-id.execute-api.region.amazonaws.com/stage'
);

// Create AWS API Gateway-aware client
const client = new ApiGatewayWebsocketConnectionClient(socket);

// Listen for connection state changes
client.connectionState.subscribe((state) => {
    console.log('Connected:', state.connected);
});

// Listen for specific event types
client.event('device').subscribe((event) => {
    console.log('Device event:', event);
});

// Handle errors
client.onError.subscribe((error) => {
    console.error('WebSocket error:', error);
});

// Connect and send messages
client.connect();

// Small messages sent directly through WebSocket
client.send({
    type: 'login',
    data: { userId: '123' },
});

// Large messages automatically handled via S3
client.send({
    type: 'largeData',
    payload: veryLargeDataObject, // Automatically uploaded to S3
});

Large Message Handling

When a message exceeds the MAX_MESSAGE_SIZE (32KB), the client automatically:

  1. Requests Upload URL: Sends an upload request to the server
  2. Receives Presigned URL: Server responds with S3 presigned URL
  3. Uploads to S3: Client uploads message data to S3 via HTTP
  4. Requests Download: Client notifies server of S3 location
  5. Server Downloads: Server downloads from S3 and processes message

This entire process is transparent to the application - just call send() with any size message.

Message Size Limit

MAX_MESSAGE_SIZE = 32_000 bytes (32KB)

Messages larger than this threshold trigger the automatic upload/download protocol.

WebSocket Event Protocol

The client implements an extended WebSocket event protocol:

  • WebsocketEventTypes.Message - Standard message event
  • WebsocketEventTypes.UploadRequest - Request S3 upload URL
  • WebsocketEventTypes.UploadResponse - Receive S3 upload URL
  • WebsocketEventTypes.DownloadRequest - Request download from S3
  • WebsocketEventTypes.Error - Error event

Dependencies

  • @casual-simulation/websocket: Low-level WebSocket management
  • @casual-simulation/aux-common: AUX common types and interfaces
  • axios: HTTP client for S3 uploads/downloads
  • rxjs: Observable-based event handling

Installation

npm install @casual-simulation/aux-websocket-aws

When to Use This Package

Use this package when:

  • Connecting to CasualOS services hosted on AWS API Gateway
  • You need to send messages that may exceed 32KB
  • You want transparent large message handling

Use @casual-simulation/aux-websocket instead when:

  • Connecting to non-AWS WebSocket endpoints
  • All messages are guaranteed to be under 32KB
  • You don't need AWS-specific features