ID412 Web

W2

Week 2. Cross-Device Interaction (WebSocket)

1. Mobile Modality & Parametric Interfaces For Web

Mobile Modality: The Phone as an Instrument

Two Types of Interaction

Parametric Web Interface

Input Materials (The "Keys" of Your Instrument)

Single Device vs. Multi-Device

Creating Your 'Visual Instrument'

2. Multi-Device Interaction & Parametric Interface

3. Socket.io

How it is structured in this repo

Overall workflow

  1. Screen page mounts → useSocket connects to the relay → join("name")
  2. Mobile page mounts → same
  3. Mobile: send("action", { x, y })
  4. Relay: forwards { type: "action", data: { x, y } } to the rest of the room
  5. Screen: onMessage("action", { x, y }) → update your state → render

Socket.io examples

  1. Simple: Tap on mobile, respond on screen
  2. Continuous: Touch move / tilt on mobile, parameter on screen
  3. Multiple mobiles, one screen

Deployment

4. Debugging & QA

A. Mobile Debugging

A1. Local Network Connection (Using ifconfig)

Your mobile device cannot access localhost:3000 because "localhost" refers to the device itself. You must connect your mobile to your computer's local network IP address.

A2. Remote Debugging (iOS vs. Android)

This is how you "Google it" to see console.log() messages, inspect the DOM, and check network requests from your phone on your computer's screen.

Android (Chrome Debugging)

  1. On Your Android Device: Enable "Developer Options" (this is usually hidden; search how to enable it for your specific phone). Inside Developer Options, toggle on "USB Debugging".
  2. On Your Computer: Connect your phone to your computer with a USB cable.
  3. Open desktop Chrome and type chrome://inspect#devices into the address bar.
  4. You should see your device and any open tabs. Click "Inspect" on the tab you want to debug.
  5. A full DevTools window will open, allowing you to inspect your mobile browser session.

iOS (Safari Web Inspector)

Note: This process requires a Mac.

  1. On Your iPhone: Go to Settings > Safari > Advanced and toggle on "Web Inspector".
  2. On Your Mac: Open Safari. Go to Safari > Preferences > Advanced and tick the box at the bottom: "Show Develop menu in menu bar".
  3. Connect: Connect your iPhone to your Mac with a USB cable.
  4. On your Mac's Safari, click the new "Develop" menu. You should see your iPhone's name.
  5. Hover over your iPhone's name to see a list of open tabs. Click the tab you wish to debug to open a Web Inspector window.

A3. HTTPS for Local Dev: pnpm dev:mobile

Modern browsers block sensitive APIs (like the camera, microphone, or accelerometer) on insecure http:// connections for security reasons. localhost is an exception (it counts as a secure context), which is why pnpm dev was enough in W1. The moment your phone connects via 192.168.x.x, it is not localhost anymore, so you must serve your local site over https://.

What pnpm dev:mobile does

CRITICAL: Bypassing the Security Warning (twice)

This uses a self-signed certificate, which your phone does not trust by default. You will see a large security warning page (e.g., "Your connection is not private" or NET::ERR_CERT_AUTHORITY_INVALID).

You only need to do this once per device (until the certificate changes). Your phone will then load the https:// version of your site, and your sensitive APIs (camera, accelerometer, etc.) will now work for testing.

B. Other Debugging Strategies