> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getmelody.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Web-based Playback

> Control device playback from a web browser — connect over WebSocket, subscribe to scripts or live streams, and receive signals on the device.

This page walks through controlling device playback from a web browser. Devices and browsers use different protocols and endpoints to reach our system, so we provide a mechanism to remotely control the device. The WebSocket example below shows how to connect, subscribe to scripts or live streams, and start receiving signals on the device.

***

## 1. Connect a device to the Haptics server

<Tabs>
  <Tab title="Real device">
    Follow the [First Activation](/melody/first_activation) instructions to set up a real device.
  </Tab>

  <Tab title="Virtual device">
    Use the Python example ([client-example-py](https://github.com/infomediji/haptic-docs/tree/master/client-example-py)):

    ```shell theme={null}
    cd client-example-py

    export DEVICE_ID=<your device id>
    export PAIRING_TOKEN=<pairing token assigned to your device id>

    python -u subscriber.py
    ```

    If everything is correct, you will connect to the server and begin receiving system events.
  </Tab>
</Tabs>

***

## 2. Subscribe to the Haptics stream

**2.1** Start a local web server with the device control example:

```shell theme={null}
cd client-example-js

npm install -g http-server

http-server
```

**2.2** Open a browser and go to `localhost:8080`.

**2.3** Because you are testing the connection locally, you may lack the required authentication cookies. Log in to your account, copy the `auth_jwt` cookie value from the session, and paste it into the **Auth JWT** input field. This value is passed to the Haptics server during WebSocket initialization.

**2.4** Enter your device name and the desired script or live stream.

Available development live stream IDs:

```text theme={null}
00000000-0000-0000-0000-000000000000
00000000-0000-0000-0000-000000000001
```

**2.5** Click **Connect**. If everything is correct, you will start receiving signals on your device.

<Check>
  You have connected from your web browser to your device and sent the first command.
</Check>
