go
go copied to clipboard
On sample code, PresenceEvent with Changes=true shows empty Who[], Occupancy 0
Starting from the sample code and adding:
r.Status = false
r.Changes = true
The received PresenceEvent for "changes" shows Who as being empty[] and occupancy 0. Output:
$ go run main2.go
Received message: hello
Occupancy: 0
Who: []
Occupancy: 0
Who: []
Full code:
package main
import (
"fmt"
"time"
emitter "github.com/emitter-io/go"
)
func main() {
// Create the options with default values
o := emitter.NewClientOptions()
// Set the message handler
o.SetOnMessageHandler(func(client emitter.Emitter, msg emitter.Message) {
fmt.Printf("Received message: %s\n", msg.Payload())
})
// Set the presence notification handler
o.SetOnPresenceHandler(func(_ emitter.Emitter, p emitter.PresenceEvent) {
fmt.Printf("Occupancy: %v\n", p.Occupancy)
fmt.Println("Who:", p.Who)
})
// Create a new emitter client and connect to the broker
c := emitter.NewClient(o)
sToken := c.Connect()
if sToken.Wait() && sToken.Error() != nil {
panic("Error on Client.Connect(): " + sToken.Error().Error())
}
// Subscribe to the presence demo channel
c.Subscribe("X4-nUeHjiAygHMdN8wst82S3c2KcCMn7", "presence-demo/1")
// Publish to the channel
c.Publish("X4-nUeHjiAygHMdN8wst82S3c2KcCMn7", "presence-demo/1", "hello")
// Ask for presence
r := emitter.NewPresenceRequest()
r.Key = "X4-nUeHjiAygHMdN8wst82S3c2KcCMn7"
r.Channel = "presence-demo/1"
r.Status = false
r.Changes = true
c.Presence(r)
// stop after 10 seconds
time.Sleep(10 * time.Second)
}
The Presence event follows an eventual consistency pattern. This means that each presence event may not be correct, but the last should be. :)
I don't understand. It never shows anyone present. Ever.
Interesting... Could you provide a small sample project of what you're seeing? That would probably help the emitter team figure out the problem, and then maybe I could help, too.
the emitter server will never response the "occupancy"
when the event is "subscribe" or "unsubscribe", the "who" is a json object, but when the event is "status" the "who" is a json array.
Indeed, the broker doesn't actually send occupancy anymore (since we've migrated from C# broker) and it just sends a list of IDs.