|
1 | 1 | package lksdk
|
2 | 2 |
|
3 |
| -type dataPublishOptions struct { |
4 |
| - Reliable *bool |
5 |
| - DestinationIdentities []string |
6 |
| - Topic string |
| 3 | +import ( |
| 4 | + "github.com/livekit/protocol/livekit" |
| 5 | + "google.golang.org/protobuf/proto" |
| 6 | +) |
| 7 | + |
| 8 | +// Data types |
| 9 | + |
| 10 | +type DataPacket interface { |
| 11 | + ToProto() *livekit.DataPacket |
| 12 | +} |
| 13 | + |
| 14 | +// Compile-time assertion for all supported data packet types. |
| 15 | +var ( |
| 16 | + _ DataPacket = (*UserDataPacket)(nil) |
| 17 | + _ DataPacket = (*livekit.SipDTMF)(nil) // implemented in the protocol package |
| 18 | +) |
| 19 | + |
| 20 | +// UserData is a custom user data that can be sent via WebRTC. |
| 21 | +func UserData(data []byte) *UserDataPacket { |
| 22 | + return &UserDataPacket{Payload: data} |
| 23 | +} |
| 24 | + |
| 25 | +// UserDataPacket is a custom user data that can be sent via WebRTC on a custom topic. |
| 26 | +type UserDataPacket struct { |
| 27 | + Payload []byte |
| 28 | + Topic string // optional |
7 | 29 | }
|
8 | 30 |
|
| 31 | +// ToProto implements DataPacket. |
| 32 | +func (p *UserDataPacket) ToProto() *livekit.DataPacket { |
| 33 | + var topic *string |
| 34 | + if p.Topic != "" { |
| 35 | + topic = proto.String(p.Topic) |
| 36 | + } |
| 37 | + return &livekit.DataPacket{Value: &livekit.DataPacket_User{ |
| 38 | + User: &livekit.UserPacket{ |
| 39 | + Payload: p.Payload, |
| 40 | + Topic: topic, |
| 41 | + }, |
| 42 | + }} |
| 43 | +} |
| 44 | + |
| 45 | +// receiving |
| 46 | + |
9 | 47 | type DataReceiveParams struct {
|
10 | 48 | Sender *RemoteParticipant
|
11 | 49 | SenderIdentity string
|
12 | 50 | Topic string // Deprecated: Use UserDataPacket.Topic
|
13 | 51 | }
|
14 | 52 |
|
| 53 | +// publishing |
| 54 | + |
| 55 | +type dataPublishOptions struct { |
| 56 | + Reliable *bool |
| 57 | + DestinationIdentities []string |
| 58 | + Topic string |
| 59 | +} |
| 60 | + |
15 | 61 | type DataPublishOption func(*dataPublishOptions)
|
16 | 62 |
|
17 | 63 | func WithDataPublishTopic(topic string) DataPublishOption {
|
|
0 commit comments