I have a Raspberry PI connected to my local network on which I've setup nodejs with WebsocketServer. Now, in my PHP/JavaScript app local instance, I connected to the RPI's local address ws://192.168... and voila, instant communication works great.
However, moving to production will not work anymore since first it has to be wss, second production does not know 192.168... ip address.
I can't poll server every few seconds to read if RPI send any message because receiving messages should be instant.
I was thinking about GCP pub/sub where I publish message from RPI, then production nodejs will catch the message and forward this to websocketserver ws://localhost:3000 so browser can get the message.
Will that work or is there any better option?
However, moving to production will not work anymore since first it has to be wss, second production does not know 192.168... ip address.
You could move the websocket server to the PHP/Javascript app. Since that's in production, the browser can connect to it there. And, your PI can then be a websocket client and connect to the PHP/Javascript app since that server is in the public location.
I cannot move websocket server to PHP/Js app because RPI must send periodically some information from local network (IoT) and that must be send to the PHP/Js app and seen immediately on the screen.
You can still do that just fine if the websocket server is on the PHP/JS app. Remember, a websocket connection is bidirectional. You can send data either way over it. All I was suggesting you change is how the connection is initially created where you have the PI establish the websocket connection by connecting TO the PHP/JS app instead of the other way around. That still gives you a bidirectional websocket connection, but takes advantage of the fact that the PI can connect to your publicly accessible PHP/JS app whereas the PI is not on a public network so the other way around doesn't work.