Skip to content

Commit

Permalink
Remove unused Close function on Peer (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdubbelboer authored Jun 18, 2024
1 parent ffa75e2 commit ef02e44
Showing 1 changed file with 0 additions and 31 deletions.
31 changes: 0 additions & 31 deletions internal/signaling/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,6 @@ type Peer struct {
Lobby string
}

func (p *Peer) Close(ctx context.Context) {
logger := logging.GetLogger(ctx)
logger.Info("closing peer", zap.String("peer", p.ID))
if p.ID != "" && p.Game != "" && p.Lobby != "" {
packet := DisconnectPacket{
Type: "disconnect",
ID: p.ID,
}
data, err := json.Marshal(packet)
if err == nil {
ctx, cancel := context.WithTimeout(ctx, 1*time.Minute)
defer cancel()

others, err := p.store.LeaveLobby(ctx, p.Game, p.Lobby, p.ID)
if err != nil {
logger.Warn("failed to leave lobby", zap.Error(err))
} else {
for _, id := range others {
if id != p.ID {
err := p.store.Publish(ctx, p.Game+p.Lobby+id, data)
if err != nil {
logger.Error("failed to publish disconnect packet", zap.Error(err))
}
}
}
}
}
}
p.conn.Close(websocket.StatusInternalError, "error")
}

func (p *Peer) Send(ctx context.Context, packet interface{}) error {
return wsjson.Write(ctx, p.conn, packet)
}
Expand Down

0 comments on commit ef02e44

Please sign in to comment.