mirror of
https://github.com/flavioribeiro/donut.git
synced 2025-10-23 23:14:07 +08:00
main: add datachannel for metadata transmission
This commit is contained in:
13
main.go
13
main.go
@@ -8,7 +8,6 @@ import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
@@ -32,7 +31,7 @@ var (
|
||||
enableICEMux = false
|
||||
)
|
||||
|
||||
func srtToWebRTC(srtConnection *astisrt.Connection, videoTrack *webrtc.TrackLocalStaticSample) {
|
||||
func srtToWebRTC(srtConnection *astisrt.Connection, videoTrack *webrtc.TrackLocalStaticSample, metadataTrack *webrtc.DataChannel) {
|
||||
r, w := io.Pipe()
|
||||
defer r.Close()
|
||||
defer w.Close()
|
||||
@@ -80,7 +79,7 @@ func srtToWebRTC(srtConnection *astisrt.Connection, videoTrack *webrtc.TrackLoca
|
||||
break
|
||||
}
|
||||
if captions != "" {
|
||||
fmt.Println("Captions: ", captions)
|
||||
metadataTrack.SendText(captions)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,6 +132,12 @@ func doSignaling(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Create data channel for metadata transmission
|
||||
metadataSender, err := peerConnection.CreateDataChannel("metadata", nil)
|
||||
if err != nil {
|
||||
errorToHTTP(w, err)
|
||||
}
|
||||
|
||||
// Set the handler for ICE connection state
|
||||
// This will notify you when the peer has connected/disconnected
|
||||
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||
@@ -187,7 +192,7 @@ func doSignaling(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
log.Println("Connected to SRT")
|
||||
|
||||
go srtToWebRTC(srtConnection, videoTrack)
|
||||
go srtToWebRTC(srtConnection, videoTrack, metadataSender)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if _, err := w.Write(response); err != nil {
|
||||
|
Reference in New Issue
Block a user