forked from livekit/server-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.go
79 lines (64 loc) · 1.72 KB
/
data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package lksdk
import (
"github.com/livekit/protocol/livekit"
"google.golang.org/protobuf/proto"
)
// Data types
type DataPacket interface {
ToProto() *livekit.DataPacket
}
// Compile-time assertion for all supported data packet types.
var (
_ DataPacket = (*UserDataPacket)(nil)
_ DataPacket = (*livekit.SipDTMF)(nil) // implemented in the protocol package
)
// UserData is a custom user data that can be sent via WebRTC.
func UserData(data []byte) *UserDataPacket {
return &UserDataPacket{Payload: data}
}
// UserDataPacket is a custom user data that can be sent via WebRTC on a custom topic.
type UserDataPacket struct {
Payload []byte
Topic string // optional
}
// ToProto implements DataPacket.
func (p *UserDataPacket) ToProto() *livekit.DataPacket {
var topic *string
if p.Topic != "" {
topic = proto.String(p.Topic)
}
return &livekit.DataPacket{Value: &livekit.DataPacket_User{
User: &livekit.UserPacket{
Payload: p.Payload,
Topic: topic,
},
}}
}
// receiving
type DataReceiveParams struct {
Sender *RemoteParticipant
SenderIdentity string
Topic string // Deprecated: Use UserDataPacket.Topic
}
// publishing
type dataPublishOptions struct {
Reliable *bool
DestinationIdentities []string
Topic string
}
type DataPublishOption func(*dataPublishOptions)
func WithDataPublishTopic(topic string) DataPublishOption {
return func(o *dataPublishOptions) {
o.Topic = topic
}
}
func WithDataPublishReliable(reliable bool) DataPublishOption {
return func(o *dataPublishOptions) {
o.Reliable = &reliable
}
}
func WithDataPublishDestination(identities []string) DataPublishOption {
return func(o *dataPublishOptions) {
o.DestinationIdentities = identities
}
}