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

[Access] Implement web socket handler for new web socket connection under /ws endpoint #6593

Closed
Tracked by #6163
Guitarheroua opened this issue Oct 24, 2024 · 0 comments · Fixed by #6630
Closed
Tracked by #6163
Assignees
Labels

Comments

@Guitarheroua
Copy link
Contributor

Guitarheroua commented Oct 24, 2024

Based on the Draft design of new WebSockets, a new WSBrokerHandler should be implemented as part of the new WebSocket subscription system, building upon the current WSHandler.

The new WSBrokerHandler should be created in router.go, similar to how the WSHandler is implemented. It can use a similar WSHandler approach:

func NewWSHandler(
logger zerolog.Logger,
api state_stream.API,
subscribeFunc SubscribeHandlerFunc,
chain flow.Chain,
stateStreamConfig backend.Config,
) *WSHandler {
handler := &WSHandler{
subscribeFunc: subscribeFunc,
api: api,
eventFilterConfig: stateStreamConfig.EventFilterConfig,
maxStreams: int32(stateStreamConfig.MaxGlobalStreams),
defaultHeartbeatInterval: stateStreamConfig.HeartbeatInterval,
activeStreamCount: atomic.NewInt32(0),
HttpHandler: NewHttpHandler(logger, chain),
}
return handler
}

A new AddPubSubRoute function should be added to router.go to separate the new WebSocket implementation from other REST API functionalities:

func (b *RouterBuilder) AddWsRoutes(
stateStreamApi state_stream.API,
chain flow.Chain,
stateStreamConfig backend.Config,
) *RouterBuilder {
for _, r := range WSRoutes {
h := NewWSHandler(b.logger, stateStreamApi, r.Handler, chain, stateStreamConfig)
b.v1SubRouter.
Methods(r.Method).
Path(r.Pattern).
Name(r.Name).
Handler(h)
}
return b
}

The main difference in the creation of this handler is that it will use a single route with the Name "ws" and Pattern "/ws", but without a handler function, as specific subscriptions will be managed internally by the new WebSocketBroker.

@Guitarheroua Guitarheroua changed the title [Access] Implement WSBrokerHandler component [Access] Implement web socket handler for new web socket connection under /ws endpoint Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants