Skip to content
New issue

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

How to implement PubSub WebSockets using Elysia? #115

Closed
ocodista opened this issue Sep 10, 2023 · 6 comments
Closed

How to implement PubSub WebSockets using Elysia? #115

ocodista opened this issue Sep 10, 2023 · 6 comments

Comments

@ocodista
Copy link

On the Bun documentation there is a section for Pub/Sub Websockets, but Elysia doesn't.

@SaltyAom
Copy link
Member

SaltyAom commented Sep 10, 2023

You should be able to use Pub/Sub just like Bun.

const app = new Elysia()
	.ws('/', {
		open({ subscribe }) {
			subscribe('topic')
		},
		message({ publish }) {
			publish('topic', 'message')
		}
	})

@jgb-solutions
Copy link

jgb-solutions commented Feb 1, 2025

And how would you subscribe to a certain topic using Eden Treaty for example? I think we need more docs on this. @SaltyAom

@kravetsone
Copy link
Contributor

And how would you subscribe to a certain topic using Eden Treaty for example? I think we need more docs on this. @SaltyAom

topic subscribe is on server side

@jgb-solutions
Copy link

How would the client know about the available topics? Say you are building a chat app with chat rooms. They rooms will be created by the users/clients. So there should be a way to subscribe to those on the client, and the server should receive them dynamically. Using Eden Treaty for example, how would I do this?

@kravetsone
Copy link
Contributor

How would the client know about the available topics? Say you are building a chat app with chat rooms. They rooms will be created by the users/clients. So there should be a way to subscribe to those on the client, and the server should receive them dynamically. Using Eden Treaty for example, how would I do this?

It js just websockets.
U subscribe and publish to topic on server-side
Client didn't know about yours topics
Please refer to Bun websocket documentation

@jgb-solutions
Copy link

jgb-solutions commented Feb 2, 2025

That's not how I used to do it with Socket.IO or Phoenix (Elixir). But it's Bun so I get it's different. Thanks for replying @kravetsone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants