{"id":16466194,"url":"https://github.com/isystk/nextjs-webrtc-firebase","last_synced_at":"2025-03-23T11:32:37.601Z","repository":{"id":37008693,"uuid":"446273740","full_name":"isystk/nextjs-webrtc-firebase","owner":"isystk","description":"Next.js \u0026 Web-RTC の学習用アプリケーションです。Firebaseを利用してビデオ通話、画面共有、チャット機能、録画機能、デバイス選択 などの機能を作成しました。","archived":false,"fork":false,"pushed_at":"2022-06-19T13:27:26.000Z","size":2819,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T19:55:07.112Z","etag":null,"topics":["firebase","nextjs","typescript","webrtc"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/isystk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-10T03:55:20.000Z","updated_at":"2024-12-16T00:19:56.000Z","dependencies_parsed_at":"2022-08-18T00:21:28.878Z","dependency_job_id":null,"html_url":"https://github.com/isystk/nextjs-webrtc-firebase","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isystk%2Fnextjs-webrtc-firebase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isystk%2Fnextjs-webrtc-firebase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isystk%2Fnextjs-webrtc-firebase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/isystk%2Fnextjs-webrtc-firebase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/isystk","download_url":"https://codeload.github.com/isystk/nextjs-webrtc-firebase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245097158,"owners_count":20560311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["firebase","nextjs","typescript","webrtc"],"created_at":"2024-10-11T11:36:43.185Z","updated_at":"2025-03-23T11:32:36.928Z","avatar_url":"https://github.com/isystk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"🌙 nextjs-webrtc-firebase\n====\n\n![GitHub issues](https://img.shields.io/github/issues/isystk/nextjs-webrtc-firebase)\n![GitHub forks](https://img.shields.io/github/forks/isystk/nextjs-webrtc-firebase)\n![GitHub stars](https://img.shields.io/github/stars/isystk/nextjs-webrtc-firebase)\n![GitHub license](https://img.shields.io/github/license/isystk/nextjs-webrtc-firebase)\n\n## 📗 プロジェクトの概要\n\nNext.js \u0026 Web-RTC の学習用アプリケーションです。Firebaseを利用してビデオ通話、画面共有、チャット機能、録画機能、デバイス選択 などの機能を作成しました。\n\n## P2P 通信 が確立するまでの処理の流れ\n\n```\n1. Aさんがルームに入ったらブロードキャストですべてのメンバーにjoinを送信する\n2. BさんがAさんからjoinを受信したらBさんはAさんにacceptを送信する\n    2-1. joinを受信して新メンバーの情報をローカルに登録する\n    2-2. acceptを送信する\n3. AさんがBさんからacceptを受信したらAさんはBさんにofferを送信する\n    3-1. acceptを受信して既存メンバーの情報をローカルに登録する\n    3-2. 通信経路をシグナリングサーバーに送信できるようにイベントハンドラを登録する\n    3-3. P2P確立後、通信相手のメディアストリーム情報の受信後、表示先のDOMを登録しておく\n    3-4. SDP(offer)を作成する\n    3-5. 作成したSDP(offer)を保存する\n    3-6. SDP(offer)を送信する\n4. AさんがBさんからofferを受信したらAさんはBさんにanswerを送信する\n    4-1. 新メンバーからofferを受信する\n    4-2. 通信経路をシグナリングサーバーに送信できるようにイベントハンドラを登録する\n    4-3. P2P確立後、通信相手のメディアストリーム情報の受信後、表示先のDOMを登録しておく\n    4-4. 受信した相手のSDP(offer)を保存する\n    4-5. SDP(answer)を作成する\n    4-6. 作成したSDP(answer)を保存する\n    4-7. SDP(answer)を送信する\n5. BさんがAさんからanswerを受信したらBさんはAさんのSDP(answer)を保存する\n    5-1. 既存メンバーからanswerを受信する\n    5-2. 受信した相手のSDP(answer)を保存する\n6. シグナリングサーバー経由でcandidateを受信し、相手の通信経路(candidate)を追加する\n    6-1. Aさん、Bさんはシグナリングサーバーからcandidateを受信する\n    6-2. 受信した相手の通信経路(candidate)を保存する\n```\n\n## MediaDevices\n\n##### getUserMedia()\n\n要求された種類のメディアを含むトラックを持つ `MediaStream` を生成するメディア入力を使用する許可をユーザーに求めます。\n```\nカメラ\nnavigator.mediaDevices.getUserMedia({ audio: true, video: true })\n\n画面共有\nnavigator.mediaDevices.getDisplayMedia({ audio: false, video: true })\n```\n\nメディアストリームをVideoタグに書き出す\n```\nconst videoRef = document.querySelector(`#video-xxxx`)\nvideoRef.srcObject = mediaStream\n```\n\n## 🌐 Demo\n\nhttps://nextjs-webrtc-firebase.web.app\n\n![投稿画面](./app.png \"投稿画面\")\n\n\n## 📦 ディレクトリ構造\n\n```\n.\n├── docker/\n│   ├── apache/ (Webサーバー)\n│   │   └── Dockerfile\n│   ├── app/ (Node.js をDockerで動作させたい場合に利用する)\n│   │   └── Dockerfile\n│   └── firebase/ (Firebase のエミュレータ)\n│       ├── Dockerfile\n│       └── src\n│           └── functions (Cloud functions のソースコード)\n├── src/ (Next.js のソースコード)\n│   ├── @types/\n│   ├── common/\n│   ├── components/\n│   ├── pages/\n│   ├── store/\n│   ├── styles/\n│   └── utilities/\n├── test/\n└── dc.sh （Dockerの起動用スクリプト）\n```\n\n## 🖊️ Docker 操作用シェルスクリプトの使い方\n\n```\nUsage:\n  dc.sh [command] [\u003coptions\u003e]\n\nOptions:\n  stats|st                 Dockerコンテナの状態を表示します。\n  init                     Dockerコンテナ・イメージ・生成ファイルの状態を初期化します。\n  start                    すべてのDaemonを起動します。\n  stop                     すべてのDaemonを停止します。\n  firebase login           Firebase にログインします。\n  firebase start           Firebase のエミュレータを起動します。\n  firebase build           Cloud Functions をビルドします。\n  firebase deploy          Firebase にデプロイします。\n  --version, -v     バージョンを表示します。\n  --help, -h        ヘルプを表示します。\n```\n\n\n## 💬 使い方\n\n```\n$ node -v\nv17.9.0\n\n# 下準備\n$ ./dc.sh init\n$ cp .env.example .env\n\n# Dockerを起動する\n$ ./dc.sh start\n\n# 初回のみFirebaseのセットアップ\n./dc.sh firebase login\n./dc.sh firebase init\n\n# Firebaseエミュレータを起動します。\n$ ./dc.sh firebase start\n$ open http://localhost:4000\n\n# Cloud Functions をビルドします。\ndocker-compose -f docker/docker-compose.yml exec firebase sh\ncd ./functions\nyarn\nyarn build\n\n# 投稿データをPOST\ncurl -X POST -H \"Content-Type: application/json\" -d @post.json http://localhost:5001/nextjs-typescript-firestore/us-central1/api/posts\n# 投稿データの一覧を取得する\ncurl http://localhost:5001/nextjs-typescript-firestore/us-central1/api/posts\n\n# Next.jsアプリを起動します。\n./dc.sh app install\n./dc.sh app dev\n$ open http://localhost:3000\n\n# Dockerを停止する場合\n$ ./dc.sh stop\n```\n\n## 🎨 参考\n\n| プロジェクト| 概要|\n| :---------------------------------------| :-------------------------------|\n| [RTCPeerConnection](https://developer.mozilla.org/ja/docs/Web/API/RTCPeerConnection)| RTCPeerConnection |\n| [STUNTMAN](http://www.stunprotocol.org/)| Public STUN server |\n| [Material Icons](https://v4.mui.com/components/material-icons/)| Material Icons |\n\n\n\n## 🎫 Licence\n\n[MIT](https://github.com/isystk/nextjs-webrtc-firebase/blob/master/LICENSE)\n\n## 👀 Author\n\n[isystk](https://github.com/isystk)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisystk%2Fnextjs-webrtc-firebase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fisystk%2Fnextjs-webrtc-firebase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fisystk%2Fnextjs-webrtc-firebase/lists"}