Skip to content

Commit 22b67ed

Browse files
authored
Support extra attributes in Join. (#684)
1 parent fa733aa commit 22b67ed

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

room.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ type SignalClientConnectParams struct {
9898

9999
RetransmitBufferSize uint16
100100

101+
Attributes map[string]string // See WithExtraAttributes
102+
101103
Pacer pacer.Factory
102104

103105
Interceptors []interceptor.Factory
@@ -147,6 +149,20 @@ func WithDisableRegionDiscovery() ConnectOption {
147149
}
148150
}
149151

152+
func WithExtraAttributes(attrs map[string]string) ConnectOption {
153+
return func(p *SignalClientConnectParams) {
154+
if len(attrs) != 0 && p.Attributes == nil {
155+
p.Attributes = make(map[string]string, len(attrs))
156+
}
157+
for k, v := range attrs {
158+
if v == "" {
159+
continue
160+
}
161+
p.Attributes[k] = v
162+
}
163+
}
164+
}
165+
150166
type PLIWriter func(webrtc.SSRC)
151167

152168
type Room struct {

signalclient.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ package lksdk
1616

1717
import (
1818
"context"
19+
"encoding/base64"
20+
"encoding/json"
1921
"errors"
2022
"fmt"
2123
"io"
@@ -153,6 +155,14 @@ func (c *SignalClient) connectContext(ctx context.Context, urlPrefix string, tok
153155
urlSuffix += fmt.Sprintf("&sid=%s", participantSID)
154156
}
155157
}
158+
if len(params.Attributes) != 0 {
159+
data, err := json.Marshal(params.Attributes)
160+
if err != nil {
161+
return nil, ErrInvalidParameter
162+
}
163+
str := base64.URLEncoding.EncodeToString(data)
164+
urlSuffix += "&attributes=" + str
165+
}
156166
urlSuffix += getStatsParamString()
157167

158168
u, err := url.Parse(urlPrefix + urlSuffix)

0 commit comments

Comments
 (0)