5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

スマホのライトを遠隔制御するアプリつくーる(React / Express)

Posted at

はじめに

Xですげぇと話題になっていたので、作ってみました。

開発環境

  • MacBook Air M1, 2020
  • Cursor 2.0.60
  • nvm 0.39.7
  • Node.js 22.4.0
  • ngrok 3.34.0
  • iPhone 12 Pro
  • iPhone 13
  • iPhone 16
  • iPhone 17

フォルダ構成

frontend: Vite + React + TypeScript のフロントエンド
backend: Express + TypeScript のバックエンド

my-mobile-light/
├── backend/                 # バックエンドサーバー
│   ├── src/
│   │   └── server.ts        # Express + WebSocketサーバー
│   ├── package.json
│   ├── tsconfig.json
│   └── node_modules/
│
├── frontend/                 # フロントエンドアプリケーション
│   ├── src/
│   │   ├── components/
│   │   │   ├── AdminPage.tsx        # 管理画面コンポーネント
│   │   │   ├── AdminPage.css
│   │   │   ├── FlashlightClient.tsx # クライアント画面コンポーネント
│   │   │   ├── FlashlightToggle.css
│   │   │   └── FlashlightToggle.tsx
│   │   ├── App.tsx          # ルーティング設定
│   │   ├── App.css
│   │   ├── main.tsx         # エントリーポイント
│   │   └── index.css
│   ├── public/              # 静的ファイル
│   ├── dist/                # ビルド成果物(本番用)
│   ├── package.json
│   ├── vite.config.ts       # Vite設定
│   ├── tsconfig.json
│   └── node_modules/
│
└── README.md

起動方法

こちらのリポジトリをクローンして下さい

git clone https://github.com/SatoshiRobatoFujimoto/my-mobile-light.git
cd my-mobile-light

ngrokを起動

ngrok http 3000
Forwarding    https://xxxx.ngrok-free.dev -> http://localhost:3000 

frontend/.envを編集

VITE_API_URL=https://xxxx.ngrok-free.dev

frontendをビルド

cd frontend
npm install
npm run build

backendを起動

cd backend
npm install
npm run dev

PCで https://xxxx.ngrok-free.dev を開く

20251215-033036-2f4987dc.png

スマホでhttps://xxxx.ngrok-free.dev/1 を開く(※カメラのアクセスを許可して下さい)

20251215-033236-d6148bd0.png

PCの方にデバイスが登録される

20251215-033255-0efa5a58.png

PCの方でオン/オフするとスマホのライトがオン/オフされます!

4台繋いでみると、こんな感じです!
それぞれのスマホで

に繋いでください

お疲れ様でした。

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?