Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ReactでWebsocket通信してみた.pdf
Search
riku0202
October 31, 2022
Programming
130
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ReactでWebsocket通信してみた.pdf
riku0202
October 31, 2022
More Decks by riku0202
See All by riku0202
jestのspyOnでmockする際に詰まった話
riku0202
0
1.9k
Other Decks in Programming
See All in Programming
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
400
Agents on Rails - Rails at Scale 2026
irinanazarova
0
310
TiDB Cloudのカスタムコントローラーによるオートスケール対応
takaidohigasi
0
140
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
120
FreeBSDでZabbixを動かす
kenkino
0
350
AWSに止められる覚悟してますか?
morizo_1984
2
500
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
420
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
290
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
140
速習iPhone Duo対応
yuukiw00w
2
930
wkhtmltopdfの次どうするか問題2026
willnet
2
1.8k
Featured
See All Featured
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
380
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
600
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
340
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Unsuck your backbone
ammeep
672
58k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
730
Paper Plane (Part 1)
katiecoart
PRO
2
11k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
Testing 201, or: Great Expectations
jmmastey
46
8.3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
560
Transcript
ReactでWebSocket通信してみた
まずは簡単な挨拶 下島 陸 静岡県のweb系企業(2021年10月〜3月) 株式会社HRBrain (2022年4月〜現在) フロントエンド(React,TS) バックエンド(Go)
犬が大好き
アジェンダ 1. webSocketを触ろうと思った理由 2. webSocketとは? 3. 実際に作ってみた! 4. 使用したライブラリ 5.
Reactでどのように実装したか 6. 学び・得たもの
webSocketに興味を持ったきっかけ
webSocketに興味を持ったきっかけ
webSocketに興味を持ったきっかけ
webSocketに興味を持ったきっかけ
webSocketとは? • サーバーと双方向通信が可能なプロトコル • URIが ws://〜 またはwss://〜 ◦ 例:ws://localhost:3000 •
HTTPと比べて一回の通信量が比較的少ない WebSocket / WebRTCの技術紹介 https://www.slideshare.net/mawarimichi/websocketwebrtc
実際に作ってみた!
使用したライブラリ Socket.io 選んだ理由 • Microsoftなどの様々な大企業で使用されている • ドキュメントがわかりやすかった • starが多かった •
TSサポート
socketインスタンスが作られる webSocketが確立するまでロングポーリングしてくれる Reactでどのように実装したか 準備
State管理 Reactでどのように実装したか 描画部分
マウント時に`socket.on`というメソッドを実行することでハンドラーを登録 上の例ではサーバーから `new message` というEventNameを受け取り、 渡したコールバック関数が実行される Reactでどのように実装したか メッセージを受信
メッセージを送信 サーバーに`new message` というEventNameとともにメッセージを送信している Reactでどのように実装したか
学び・得たこと • socket.ioのおかげで簡単に実装できた 神! • webSocketについて知ることができた ◦ 自分の中でできることが広がった
フロントエンドエンジニアを積極採用募集中です
ありがとうございました!! @Riku_0202_