Open jbenguira opened 3 years ago
r.engine.rooms
data.peerTrackReadTimeout
engineStateLoopPeriod
at engine/engine.go.Thanks for trying kraken. It's still too simple, but we have used it in production.
@cedricfung Thanks so much for making this library!
@jbenguira It is absolutely possible to get all the rooms (that have been connected to) and connected users.
In router.go: above: https://github.com/MixinNetwork/kraken/blob/master/engine/router.go#L32
func (r *Router) listAll() (map[string][]string, error) {
r.engine.rooms.RLock()
rooms := make(map[string][]string)
for _, pm := range r.engine.rooms.m {
pm.RLock()
for _, p := range pm.m {
_, ok := rooms[p.rid]
if !ok {
rooms[p.rid] = make([]string, 0)
}
if p.pc.ConnectionState().String() == "connected" {
rooms[p.rid] = append(rooms[p.rid], p.uid)
}
}
pm.RUnlock()
}
r.engine.rooms.RUnlock()
return rooms, nil
}
In rpc.go, above: https://github.com/MixinNetwork/kraken/blob/master/engine/rpc.go#L89
case "listAll":
rooms, err := impl.listAll()
if err != nil {
renderer.RenderError(err)
} else {
renderer.RenderData(map[string]interface{}{"rooms": rooms})
}
In rpc.go, above: https://github.com/MixinNetwork/kraken/blob/master/engine/rpc.go#L164
func (r *R) listAll() (map[string][]string, error) {
return r.router.listAll()
}
How I use this. I already have a data layer of all the existing rooms. What I don't have, is whether any users exist in the rooms when a user first initialises the chat application. So requesting this endpoint gives me a snapshot at that time!
Is it possible to get the list of rooms with the REST API? It would be great to have a JSON with the list of rooms + participants in each room
Something like this:
Also I noticed there is a quite long delay before a disconnected user is removed from the room, is this configurable?
Last point, the method "info" seems to be computed only once every 30 sec, is that also something that can be configured? if not could you give me a pointer about what part of the source code is responsible for this? :)
Thanks a lot for this great piece of OSS :)