specs-websocket

Implements real-time WebSocket connections in Lens Studio using the InternetModule.

16|2|Updated Apr 13, 2026
One-click install
npx skills add https://github.com/lens-studio-devs/ls-extensions --skill specs-websocket-lens-studio-devs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: specs-websocket
Source: https://github.com/lens-studio-devs/ls-extensions/tree/main/plugins/ls-clad/skills/specs-websocket
Command: npx skills add https://github.com/lens-studio-devs/ls-extensions --skill specs-websocket-lens-studio-devs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Building persistent, bidirectional socket connections on Snap Spectacles requires handling Lens Studio's specific WebSocket lifecycle, binary Blob frames, and platform constraints that differ from standard browser APIs. ## Core Features & Use Cases - Complete WebSocket Component Pattern: Provides a runnable connect/onopen/onmessage/onclose/onerror skeleton with readyState-guarded send calls and reconnect logic. - Text and Binary Frame Handling: Demonstrates branching on Blob frames with bytes()/text() conversion and a JSON message protocol pattern. - Use Case: Stream IMU sensor data over a socket and parse CSV angle frames to drive real-time 3D rotation of a cube in a Lens. ## Quick Start Ask the agent to create a WebSocket component in Lens Studio that connects to a server and handles incoming text and binary messages.

Frequently Asked Questions about specs-websocket

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a WebSocket connection in Lens Studio?

Add the InternetModule to your project, declare it as an @input, then call internetModule.createWebSocket(url) and wire the onopen, onmessage, onclose, and onerror handlers. Bind connect() to OnStartEvent and close the socket in OnDestroyEvent.

How do I handle binary WebSocket messages on Spectacles?

Set socket.binaryType to 'blob' and check event.data instanceof Blob in onmessage. For binary frames, call await data.bytes() for a Uint8Array or await data.text() for a string; otherwise treat the data as a text frame.

Can I publish a Lens that uses insecure ws:// WebSocket connections?

No. Insecure ws:// connections require Experimental APIs and are only suitable for testing. Lenses using secure wss:// connections are eligible for publication.

Why does WebSocket arraybuffer binaryType not work in Lens Studio?

The platform's WebSocket implementation does not support binaryType 'arraybuffer'; only 'blob' is supported. The Blob type also lacks ArrayBuffer and Stream support, and the extensions, protocol, and bufferedAmount properties are unavailable.

How do I reconnect a WebSocket after it closes in Lens Studio?

In the onclose handler, create a DelayedCallbackEvent, bind it to your connect() method, and call reset with a delay in seconds. Always guard send() calls with socket.readyState === WebSocket.OPEN.