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

cluster_grpc example error #356

Open
CoreELEE opened this issue Oct 12, 2023 · 1 comment
Open

cluster_grpc example error #356

CoreELEE opened this issue Oct 12, 2023 · 1 comment

Comments

@CoreELEE
Copy link

room is a backend servers, Pitaya Doc

Backend sessions
Backend sessions have access to the sessions through the handler’s methods, but they have some limitations and special characteristics. Changes to session variables must be pushed to the frontend server by calling s.PushToFront (this is not needed for s.Bind operations), setting callbacks to session lifecycle operations is also not allowed. One can also not retrieve a session by user ID from a backend server.

In the examples/demo/cluster_grpc/services/room.go

// Join room
func (r *Room) Join(ctx context.Context) (*JoinResponse, error) {
s := r.app.GetSessionFromCtx(ctx)
err := r.app.GroupAddMember(ctx, "room", s.UID())
if err != nil {
return nil, err
}
members, err := r.app.GroupMembers(ctx, "room")
if err != nil {
return nil, err
}
s.Push("onMembers", &AllMembers{Members: members})
r.app.GroupBroadcast(ctx, "connector", "room", "onNewUser", &NewUser{Content: fmt.Sprintf("New user: %d", s.ID())})
err = s.OnClose(func() {
r.app.GroupRemoveMember(ctx, "room", s.UID())
})
if err != nil {
return nil, err
}
return &JoinResponse{Result: "success"}, nil
}

s.OnCloseThis will cause an error.
{"code":"PIT-000","msg":"onclose callbacks are not allowed on backend servers"}

@lyh1091106900
Copy link

This is indeed a bug in the demo, probably a case of copy-paste, which the author has not run

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

2 participants