From e7e8a9b555a70d37a77c6f6bf8897ae31e513d11 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Tue, 30 Apr 2024 18:17:00 +0200 Subject: [PATCH] Add method Addr to client. --- diskwriter/diskwriter.go | 5 +++++ group/client.go | 2 ++ rtpconn/webclient.go | 9 ++++++++- rtpconn/whipclient.go | 10 ++++++++-- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/diskwriter/diskwriter.go b/diskwriter/diskwriter.go index 8e0a240..63edfcf 100644 --- a/diskwriter/diskwriter.go +++ b/diskwriter/diskwriter.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "log" + "net" "os" "path/filepath" "runtime" @@ -107,6 +108,10 @@ func (client *Client) Kick(id string, user *string, message string) error { return err } +func (client *Client) Addr() net.Addr { + return nil +} + func (client *Client) Joined(group, kind string) error { return nil } diff --git a/group/client.go b/group/client.go index 43dfe10..b972df6 100644 --- a/group/client.go +++ b/group/client.go @@ -7,6 +7,7 @@ import ( "encoding/json" "errors" "hash" + "net" "golang.org/x/crypto/bcrypt" "golang.org/x/crypto/pbkdf2" @@ -111,6 +112,7 @@ type ClientCredentials struct { type Client interface { Group() *Group + Addr() net.Addr Id() string Username() string SetUsername(string) diff --git a/rtpconn/webclient.go b/rtpconn/webclient.go index 891f5f6..cf46ea8 100644 --- a/rtpconn/webclient.go +++ b/rtpconn/webclient.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "net" "os" "sync" "time" @@ -58,6 +59,7 @@ func isWSNormalError(err error) bool { type webClient struct { group *group.Group + addr net.Addr id string username string permissions []string @@ -77,6 +79,10 @@ func (c *webClient) Group() *group.Group { return c.group } +func (c *webClient) Addr() net.Addr { + return c.addr +} + func (c *webClient) Id() string { return c.id } @@ -818,7 +824,7 @@ func readMessage(conn *websocket.Conn, m *clientMessage) error { const protocolVersion = "2" -func StartClient(conn *websocket.Conn) (err error) { +func StartClient(conn *websocket.Conn, addr net.Addr) (err error) { var m clientMessage err = readMessage(conn, &m) @@ -849,6 +855,7 @@ func StartClient(conn *websocket.Conn) (err error) { } c := &webClient{ + addr: addr, id: m.Id, actions: unbounded.New[any](), done: make(chan struct{}), diff --git a/rtpconn/whipclient.go b/rtpconn/whipclient.go index da08260..9f3e981 100644 --- a/rtpconn/whipclient.go +++ b/rtpconn/whipclient.go @@ -3,6 +3,7 @@ package rtpconn import ( "context" "errors" + "net" "sync" "github.com/jech/galene/conn" @@ -12,6 +13,7 @@ import ( type WhipClient struct { group *group.Group + addr net.Addr id string token string username string @@ -21,14 +23,18 @@ type WhipClient struct { connection *rtpUpConnection } -func NewWhipClient(g *group.Group, id string, token string) *WhipClient { - return &WhipClient{group: g, id: id, token: token} +func NewWhipClient(g *group.Group, id string, token string, addr net.Addr) *WhipClient { + return &WhipClient{group: g, id: id, token: token, addr: addr} } func (c *WhipClient) Group() *group.Group { return c.group } +func (c *WhipClient) Addr() net.Addr { + return c.addr +} + func (c *WhipClient) Id() string { return c.id }