mirror of
https://github.com/flavioribeiro/donut.git
synced 2025-10-28 09:31:27 +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"
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
@@ -32,7 +31,7 @@ var (
|
|||||||
enableICEMux = false
|
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()
|
r, w := io.Pipe()
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
@@ -80,7 +79,7 @@ func srtToWebRTC(srtConnection *astisrt.Connection, videoTrack *webrtc.TrackLoca
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if captions != "" {
|
if captions != "" {
|
||||||
fmt.Println("Captions: ", captions)
|
metadataTrack.SendText(captions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,6 +132,12 @@ func doSignaling(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
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
|
// Set the handler for ICE connection state
|
||||||
// This will notify you when the peer has connected/disconnected
|
// This will notify you when the peer has connected/disconnected
|
||||||
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
|
||||||
@@ -187,7 +192,7 @@ func doSignaling(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
log.Println("Connected to SRT")
|
log.Println("Connected to SRT")
|
||||||
|
|
||||||
go srtToWebRTC(srtConnection, videoTrack)
|
go srtToWebRTC(srtConnection, videoTrack, metadataSender)
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
if _, err := w.Write(response); err != nil {
|
if _, err := w.Write(response); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user