Send initial user flags to internal sessions asynchronously.

This commit is contained in:
Joachim Bauch 2022-07-12 14:16:33 +02:00
parent 532587eb9f
commit 706a876fc3
No known key found for this signature in database
GPG Key ID: 77C1D22D53E15F02
2 changed files with 12 additions and 7 deletions

View File

@ -44,7 +44,8 @@ type AsyncMessage struct {
type AsyncRoomMessage struct {
Type string `json:"type"`
SessionId string `json:"sessionid,omitempty"`
SessionId string `json:"sessionid,omitempty"`
ClientType string `json:"clienttype,omitempty"`
}
type SendOfferMessage struct {

16
room.go
View File

@ -247,6 +247,9 @@ func (r *Room) processBackendRoomRequestAsyncRoom(message *AsyncRoomMessage) {
switch message.Type {
case "sessionjoined":
r.notifySessionJoined(message.SessionId)
if message.ClientType == HelloClientTypeInternal {
r.publishUsersChangedWithInternal()
}
default:
log.Printf("Unsupported async room request with type %s in %s: %+v", message.Type, r.Id(), message)
}
@ -305,8 +308,9 @@ func (r *Room) AddSession(session Session, sessionData *json.RawMessage) {
if err := r.events.PublishBackendRoomMessage(r.id, r.backend, &AsyncMessage{
Type: "asyncroom",
AsyncRoom: &AsyncRoomMessage{
Type: "sessionjoined",
SessionId: sid,
Type: "sessionjoined",
SessionId: sid,
ClientType: session.ClientType(),
},
}); err != nil {
log.Printf("Error publishing joined event for session %s: %s", sid, err)
@ -530,10 +534,6 @@ func (r *Room) PublishSessionJoined(session Session, sessionData *RoomSessionDat
if err := r.publish(message); err != nil {
log.Printf("Could not publish session joined message in room %s: %s", r.Id(), err)
}
if session.ClientType() == HelloClientTypeInternal {
r.publishUsersChangedWithInternal()
}
}
func (r *Room) PublishSessionLeft(session Session) {
@ -840,6 +840,10 @@ func (r *Room) NotifySessionChanged(session Session) {
func (r *Room) publishUsersChangedWithInternal() {
message := r.getParticipantsUpdateMessage(r.users)
if len(message.Event.Update.Users) == 0 {
return
}
if err := r.publish(message); err != nil {
log.Printf("Could not publish users changed message in room %s: %s", r.Id(), err)
}