Closed morya closed 2 months ago
yes, a workaround method,
just split subscribe to another API command ( I think)
I think, the related code lines are:
subscriptions := make(map[string]centrifuge.SubscribeOptions, len(result.Channels))
// ...
// should be changed to these
joinLeave := chOpts.JoinLeave
if result.Subs != nil {
opt := result.Subs[ch]
if opt != nil && opt.Override != nil && opt.Override.ForcePushJoinLeave != nil {
joinLeave = opt.GetOverride().GetForcePushJoinLeave().GetValue()
}
}
subscriptions[ch] = centrifuge.SubscribeOptions{
EmitPresence: chOpts.Presence,
EmitJoinLeave: chOpts.JoinLeave,
PushJoinLeave: joinLeave, // chOpts.ForcePushJoinLeave, // read directly from chOpts.ForcePushJoinLeave , subs from ConnectResponse cmd is ignored.
EnableRecovery: chOpts.ForceRecovery,
EnablePositioning: chOpts.ForcePositioning,
RecoveryMode: chOpts.GetRecoveryMode(),
Source: subsource.ConnectProxy,
HistoryMetaTTL: time.Duration(chOpts.HistoryMetaTTL),
}
Hello @morya ,
Thanks for the detailed report, you are right – subs
field is not used now by Centrifugo when processing the response from the connect proxy.
I see the following things to be fixed here:
ConnectResult.subs
field in the same way we do in other places now. I just opened PR - https://github.com/centrifugal/centrifugo/pull/874override
object - it still uses format from Centrifugo v3, while some fields were renamed in Centrifugo v4, so this should be updated to reflect correct field names (which correspond to current channel namespace options). PR with doc fix - https://github.com/centrifugal/centrifugal.dev/pull/52One note btw, I see you are using both channels
and subs
in your connect result:
return {
"result": {
...
"channels": ["room"],
"subs": {
"room": {
...
},
}
}
}
You can stick to sth single here - whether only channels
, or only to subs
. After the fix they should be processed one after another, just subs
allow setting some extra channel options while channels
is just an array of server-side channels without any customization.
Alright, I use channels for this kind of response from our project, which works perfectly, until I want to customize sub options.
I thought, it's should be the subs
to customize sub options, and channels
to describe server sub
option, when I was digging through code of centrifugo.
I will stick to subs
option and drop channels
when new version is released.
I was planning open a PR, but afraid of send miss leading codes, which may lead to extra pointless review efforts.
Best regards.
just confirmed that, github.com/centrifugal/gocent/v3 v3.3.0
is not working when using with these codes:
func doServerSubscribe(client string) {
cc := gocent.New(gocent.Config{
Addr: "http://127.0.0.1:8000/api",
Key: "fake-key",
})
err := cc.Subscribe(context.TODO(), "foo", client, gocent.WithPresence(true), gocent.WithJoinLeave(true))
if err != nil {
log.Fatalf("Server Subscribe failed %v", err)
}
}
params from gocent.WithPresence(true), gocent.WithJoinLeave(true)
will be ignored from centrifugo v3 to v5
encoded json result is:
{"method":"subscribe","params":{"channel":"foo","user":"3e3fc43b-bef9-4ab5-a3da-4c96c688351e","presence":true,"join_leave":true}}
and, this will be ignored when decode from centrifugo server with SubscribeRequest
from internal/apiproto/api.pb.go
SubscribeRequest require all fields inside override
sub field.
just confirmed that, github.com/centrifugal/gocent/v3 v3.3.0 is not working when using with these codes:
Could you please open a separate issue in gocent
about it?
ok
Describe the bug.
SubscribeOptions field from connect proxy response, is not working.
version: v5.4.4
Centrifugo version is
v5.4.4
Client library used isgithub.com/centrifugal/centrifuge v0.33.1-0.20240801054640-96afa7258679
Operating system ismacos
Steps to Reproduce How can the bug be triggered?
with
config.yaml
for centrifugo like this:Expected behavior What output or behaviour were you expecting instead?
Code Snippets A minimum viable code snippet can be useful.
I use fastapi to be centrifugo proxy-handler.