mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add WebRTC send function.
This commit is contained in:
parent
f22922191a
commit
c8200e3bb7
@ -7,6 +7,7 @@ type WebRTCPeer interface {
|
||||
SignalCandidate(candidate webrtc.ICECandidateInit) error
|
||||
SetVideoID(videoID string) error
|
||||
|
||||
Send(data []byte) error
|
||||
Destroy() error
|
||||
}
|
||||
|
||||
|
@ -213,9 +213,11 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
||||
}
|
||||
}
|
||||
|
||||
connection.OnNegotiationNeeded(func() {
|
||||
logger.Warn().Msg("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!negotiation needed!")
|
||||
})
|
||||
peer := &WebRTCPeerCtx{
|
||||
api: api,
|
||||
connection: connection,
|
||||
changeVideo: changeVideo,
|
||||
}
|
||||
|
||||
connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
|
||||
switch state {
|
||||
@ -237,6 +239,8 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
||||
})
|
||||
|
||||
connection.OnDataChannel(func(channel *webrtc.DataChannel) {
|
||||
peer.dataChannel = channel
|
||||
|
||||
channel.OnMessage(func(message webrtc.DataChannelMessage) {
|
||||
if !session.IsHost() {
|
||||
return
|
||||
@ -248,15 +252,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
|
||||
})
|
||||
})
|
||||
|
||||
session.SetWebRTCPeer(&WebRTCPeerCtx{
|
||||
api: api,
|
||||
engine: engine,
|
||||
settings: settings,
|
||||
connection: connection,
|
||||
configuration: configuration,
|
||||
changeVideo: changeVideo,
|
||||
})
|
||||
|
||||
session.SetWebRTCPeer(peer)
|
||||
return connection.LocalDescription(), nil
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,8 @@ import "github.com/pion/webrtc/v3"
|
||||
|
||||
type WebRTCPeerCtx struct {
|
||||
api *webrtc.API
|
||||
engine *webrtc.MediaEngine
|
||||
settings *webrtc.SettingEngine
|
||||
connection *webrtc.PeerConnection
|
||||
configuration *webrtc.Configuration
|
||||
dataChannel *webrtc.DataChannel
|
||||
changeVideo func(videoID string) error
|
||||
}
|
||||
|
||||
@ -26,6 +24,14 @@ func (webrtc_peer *WebRTCPeerCtx) SetVideoID(videoID string) error {
|
||||
return webrtc_peer.changeVideo(videoID)
|
||||
}
|
||||
|
||||
func (webrtc_peer *WebRTCPeerCtx) Send(data []byte) error {
|
||||
if webrtc_peer.dataChannel == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return webrtc_peer.dataChannel.Send(data)
|
||||
}
|
||||
|
||||
func (webrtc_peer *WebRTCPeerCtx) Destroy() error {
|
||||
if webrtc_peer.connection == nil || webrtc_peer.connection.ConnectionState() != webrtc.PeerConnectionStateConnected {
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user