(rooms *Rooms, current ClientInfo)
| 16 | } |
| 17 | |
| 18 | func (e *Join) Execute(rooms *Rooms, current ClientInfo) error { |
| 19 | if rooms.connected[current.ID] != "" { |
| 20 | return fmt.Errorf("cannot join room, you are already in one") |
| 21 | } |
| 22 | |
| 23 | room, ok := rooms.Rooms[e.ID] |
| 24 | if !ok { |
| 25 | return fmt.Errorf("room with id %s does not exist", e.ID) |
| 26 | } |
| 27 | name := e.UserName |
| 28 | if current.Authenticated { |
| 29 | name = current.AuthenticatedUser |
| 30 | } |
| 31 | if name == "" { |
| 32 | name = rooms.RandUserName() |
| 33 | } |
| 34 | |
| 35 | room.Users[current.ID] = &User{ |
| 36 | ID: current.ID, |
| 37 | Name: name, |
| 38 | Streaming: false, |
| 39 | Owner: false, |
| 40 | Addr: current.Addr, |
| 41 | _write: current.Write, |
| 42 | } |
| 43 | rooms.connected[current.ID] = room.ID |
| 44 | room.notifyInfoChanged() |
| 45 | usersJoinedTotal.Inc() |
| 46 | |
| 47 | v4, v6, err := rooms.config.TurnIPProvider.Get() |
| 48 | if err != nil { |
| 49 | return err |
| 50 | } |
| 51 | |
| 52 | for _, user := range room.Users { |
| 53 | if current.ID == user.ID || !user.Streaming { |
| 54 | continue |
| 55 | } |
| 56 | room.newSession(user.ID, current.ID, rooms, v4, v6) |
| 57 | } |
| 58 | |
| 59 | return nil |
| 60 | } |
no test coverage detected