Unlabeled (pass through) data channels. (#3567)
* Unlabeled (pass through) data channels. Support data channels than can pass through raw data without any LK protocol marshaling/unmarshaling. * statischeck * test * error -> warn * reset data message callback
This commit is contained in:
+35
-6
@@ -81,10 +81,11 @@ type RTCClient struct {
|
||||
// tracks waiting to be acked, cid => trackInfo
|
||||
pendingPublishedTracks map[string]*livekit.TrackInfo
|
||||
|
||||
pendingTrackWriters []*TrackWriter
|
||||
OnConnected func()
|
||||
OnDataReceived func(data []byte, sid string)
|
||||
refreshToken string
|
||||
pendingTrackWriters []*TrackWriter
|
||||
OnConnected func()
|
||||
OnDataReceived func(data []byte, sid string)
|
||||
OnDataUnlabeledReceived func(data []byte)
|
||||
refreshToken string
|
||||
|
||||
// map of livekit.ParticipantID and last packet
|
||||
lastPackets map[livekit.ParticipantID]*rtp.Packet
|
||||
@@ -262,6 +263,18 @@ func NewRTCClient(conn *websocket.Conn, opts *Options) (*RTCClient, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := c.publisher.CreateDataChannel("pubraw", &webrtc.DataChannelInit{
|
||||
Ordered: &ordered,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := c.subscriber.CreateReadableDataChannel("subraw", &webrtc.DataChannelInit{
|
||||
Ordered: &ordered,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
subscriberHandler.OnICECandidateCalls(func(ic *webrtc.ICECandidate, t livekit.SignalTarget) error {
|
||||
if ic == nil {
|
||||
return nil
|
||||
@@ -271,7 +284,8 @@ func NewRTCClient(conn *websocket.Conn, opts *Options) (*RTCClient, error) {
|
||||
subscriberHandler.OnTrackCalls(func(track *webrtc.TrackRemote, rtpReceiver *webrtc.RTPReceiver) {
|
||||
go c.processTrack(track)
|
||||
})
|
||||
subscriberHandler.OnDataPacketCalls(c.handleDataMessage)
|
||||
subscriberHandler.OnDataMessageCalls(c.handleDataMessage)
|
||||
subscriberHandler.OnDataMessageUnlabeledCalls(c.handleDataMessageUnlabeled)
|
||||
subscriberHandler.OnInitialConnectedCalls(func() {
|
||||
logger.Debugw("subscriber initial connected", "participant", c.localParticipant.Identity)
|
||||
|
||||
@@ -732,7 +746,16 @@ func (c *RTCClient) PublishData(data []byte, kind livekit.DataPacket_Kind) error
|
||||
return err
|
||||
}
|
||||
|
||||
return c.publisher.SendDataPacket(kind, dpData)
|
||||
return c.publisher.SendDataMessage(kind, dpData)
|
||||
}
|
||||
|
||||
func (c *RTCClient) PublishDataUnlabeled(data []byte) error {
|
||||
if err := c.ensurePublisherConnected(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("RAJA sending unlabeled data: %s\n", string(data)) // REMOVE
|
||||
return c.publisher.SendDataMessageUnlabeled(data)
|
||||
}
|
||||
|
||||
func (c *RTCClient) GetPublishedTrackIDs() []string {
|
||||
@@ -787,6 +810,12 @@ func (c *RTCClient) handleDataMessage(kind livekit.DataPacket_Kind, data []byte)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *RTCClient) handleDataMessageUnlabeled(data []byte) {
|
||||
if c.OnDataUnlabeledReceived != nil {
|
||||
c.OnDataUnlabeledReceived(data)
|
||||
}
|
||||
}
|
||||
|
||||
// handles a server initiated offer, handle on subscriber PC
|
||||
func (c *RTCClient) handleOffer(desc webrtc.SessionDescription) {
|
||||
c.subscriber.HandleRemoteDescription(desc)
|
||||
|
||||
Reference in New Issue
Block a user