Websockets和Firebase簡介-如何構建實時應用



剛開始進行網路開發時,您不會經常考慮狀態。因為HTTP是無狀態協議。但是,有許多應用程序需要客戶端和伺服器之間存在持久的雙向通信通道,以便它們可以不斷地相互之間來回發送數據,並且伺服器還可以一次將數據廣播到所有連接的客戶端。

輸入Websockets。 Websocket是所有現代瀏覽器的本機功能,但是它們有點難以處理。它們的級別很低,每個瀏覽器以略有不同的方式實現它們。因此,如果您想構建一個實時應用程序,那麼您將面臨一些挑戰。

幸運的是,通過使用一種稱為Firebase的令人難以置信的服務,有一種非常簡單的方法來開始使用Websocket。 Firebase是一家於2012年成立的初創公司,然後於2014年被Google收購。Firebase作為一項服務可以做很多事情,但是如果您需要了解一件事,那就是Firebase是最簡單的方法構建一個實時應用,該應用在多個設備之間具有共享狀態。 。

20 comments
  1. pls tell me that how to update OR send player vectors (movements) to my real time database in firebase asa i'm trying to make a simple multiplayer game using firebase RTDB and also how top get that movement value back to show other players in realtime? pls help there i no such tutorial for this IN UNITY 2D

  2. Sorry this is not a WebSocket connection, this is just Firebase's RealTimeDataBase.

    RealTimeDataBase itself is already a socket connection,

    but the RealTimeDataBase socket has its own rules.

    To really make a WebSocket connection with FireBase using your own rules, you have to follow this more or less, also using Firebase Functions, Hosting etc …

    take a look

    https://codereview.stackexchange.com/questions/193305/firebase-server-side-auth-with-persistent-websocket-connection?rq=1

  3. Great intro to what websockets are used for. Do you know of any resources that I could use to learn alternatives to Firebase? E.g. how to run websocket servers on instances of Google Compute Engine. My goal is to build a mobile app with an IM feature. If you don't know of any guides, would you please consider making one? I'd be more than happy to pay for it.

  4. started off promising with a great intorduction, but the example seemed to skip over a heap of details for people unfamiliar with server side javascript. was also hoping to see example code that i could run and experiment with so i could fill in the gaps.

  5. Hey buddy! Awesome video again. Keep em' coming. I have a question for you: I built an app using Firebase for the real-time connection stuff. I started considering moving to PouchDB or something like that, because I was worried that the free Firebase plan wouldn't hold up minimal traffic. How true is that?

  6. How do you subscribe to the deltas (changes) of a reference when it is updated? I don't want to reprocess a whole nested structure every time a leaf node is changed. Can probably be optimized with shouldcomponentupdate and immutable data structure if the delta is known. I can't find an elegant solution anywhere. Perhaps you have some ideas?

    Also firebase is probably only sending the deltas over the wire and not the entire object for every little change right?

  7. gerat episode as usual, and very educational. keep em coming. i don't understand how this channel didn't blow up yet

  8. Great intro to firebase and integration with React! Thanks for taking the time to teach these interesting topics, I really enjoy the quality of these videos!

Comments are closed.