go icon indicating copy to clipboard operation
go copied to clipboard

On sample code, PresenceEvent with Changes=true shows empty Who[], Occupancy 0

Open MichaelHipp opened this issue 6 years ago • 6 comments

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)
}

MichaelHipp avatar Sep 16 '18 21:09 MichaelHipp

The Presence event follows an eventual consistency pattern. This means that each presence event may not be correct, but the last should be. :)

richterk avatar Nov 12 '18 21:11 richterk

I don't understand. It never shows anyone present. Ever.

MichaelHipp avatar Nov 12 '18 23:11 MichaelHipp

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.

richterk avatar Nov 13 '18 03:11 richterk

default the emitter server will never response the "occupancy"

richardchey avatar Dec 17 '18 09:12 richardchey

default

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.

richardchey avatar Dec 17 '18 09:12 richardchey

Indeed, the broker doesn't actually send occupancy anymore (since we've migrated from C# broker) and it just sends a list of IDs.

kelindar avatar Jan 15 '19 13:01 kelindar