We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Q: 前端 甚麼時候 需要用 websocket 送資料 給後端?? A: 聊天室
AC:
The text was updated successfully, but these errors were encountered:
試了一個晚上沒有找到什麼比較好的解法跟 Spring Security 整合再一起 嘗試在連線時把 Authentication 放進 Securitycontextholder 但在接收 event 從 Securitycontextholder 拿不到 Authentication
後來就決定用比較 Hacky 的方式 在 Socket.IO 連線時去解 Token 然後查 UserId 然後把連線加入房間, 房間名稱是他的 UserId 之後想要知道連線的 UserId 就把他所有有加入的房間拿出來 找到有 USER_ prefix 的就是他的 UserId
Sorry, something went wrong.
另外我還有順便把聊天室的 Event 也接上了
在 Socket.IO 連線時 會從 url parameter 的 token 取出 jwt token 再來會解析 jwt token 取出 subject ex. google-oauth2|102527320242660434908 從資料庫查出他對應的 userId ex. 173921799328193 然後把這個 SocketIOClient join room ex. USER_173921799328193
之後接收到 event 我們可以從 client 獲得其所在的房間 ex. ROOM_1972919392, USER_173921799328193 從中找到 USER_ 開頭的房間 然後就知道這個連線的 userId 為 173921799328193
kuoche1712003
No branches or pull requests
Q: 前端 甚麼時候 需要用 websocket 送資料 給後端??
A: 聊天室
AC:
The text was updated successfully, but these errors were encountered: