zhangyuang / ssr

A most advanced ssr framework support React17/React18/Vue2/Vue3 on Earth that implemented serverless-side render specification.
http://doc.ssr-fc.com/
MIT License
2.61k stars 284 forks source link

Websocket #116

Closed geomen888 closed 3 years ago

geomen888 commented 3 years ago

Hi, what about websockets (ws\socket.io) support? As for server: nest-js it's socket implementation is oblivious. But If U put some example regarding client part it's will be great. Thank U

zhangyuang commented 3 years ago

there is no relation between websocket and ssr。you can write websocket like traditional spa+nodejs program。i will provide an example at a later time

geomen888 commented 3 years ago

In addition, websocket like traditional manner I think that primitive. The logic that already realized provides in brief: if trigger something at client It requests server-side, than some data fetched throw api and it re-renders client-side UI. My expectations that U provide some example where server-side (nest-js) listen some ws events, when it updates by data messaging, then it will hydrate & re-render client-side UI. Or do the same by emit ws event action from client-side. Besides implementation ws at server-side is more advanced in authentication (headers, protocols, tokens)

zhangyuang commented 3 years ago

I can't understand well about what's your mean, hydrate behavior has been only happened at the first render in client side. websocket should be established after hydrate for example in mounted/componentDidMount lifecycle. when client side receive server side message lead to rerender which behavior is the same as csr application.

i5ting commented 3 years ago

you can use ssr-nest plugin, the scafold will be init a nest project, then you can add ws\socket.io, maybe it is better