mirror of
https://github.com/pion/webrtc.git
synced 2025-10-06 15:46:54 +08:00
Revert public API name changes for on event handlers
This commit is contained in:
@@ -33,7 +33,7 @@ func main() {
|
|||||||
|
|
||||||
// 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 ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange = func(connectionState ice.ConnectionState) {
|
||||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||||
|
|
||||||
// TODO: find the correct place for this
|
// TODO: find the correct place for this
|
||||||
@@ -46,9 +46,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register the OnMessage to handle incoming messages
|
// Register the Onmessage to handle incoming messages
|
||||||
dataChannel.Lock()
|
dataChannel.Lock()
|
||||||
dataChannel.OnMessage = func(payload datachannel.Payload) {
|
dataChannel.Onmessage = func(payload datachannel.Payload) {
|
||||||
switch p := payload.(type) {
|
switch p := payload.(type) {
|
||||||
case *datachannel.PayloadString:
|
case *datachannel.PayloadString:
|
||||||
fmt.Printf("Message '%s' from DataChannel '%s' payload '%s'\n", p.PayloadType().String(), dataChannel.Label, string(p.Data))
|
fmt.Printf("Message '%s' from DataChannel '%s' payload '%s'\n", p.PayloadType().String(), dataChannel.Label, string(p.Data))
|
||||||
|
@@ -54,14 +54,14 @@ func main() {
|
|||||||
|
|
||||||
// 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 ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange = func(connectionState ice.ConnectionState) {
|
||||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
datachannels := make([]*webrtc.RTCDataChannel, 0)
|
datachannels := make([]*webrtc.RTCDataChannel, 0)
|
||||||
var dataChannelsLock sync.RWMutex
|
var dataChannelsLock sync.RWMutex
|
||||||
|
|
||||||
peerConnection.OnDataChannel = func(d *webrtc.RTCDataChannel) {
|
peerConnection.Ondatachannel = func(d *webrtc.RTCDataChannel) {
|
||||||
dataChannelsLock.Lock()
|
dataChannelsLock.Lock()
|
||||||
datachannels = append(datachannels, d)
|
datachannels = append(datachannels, d)
|
||||||
dataChannelsLock.Unlock()
|
dataChannelsLock.Unlock()
|
||||||
@@ -70,7 +70,7 @@ func main() {
|
|||||||
|
|
||||||
d.Lock()
|
d.Lock()
|
||||||
defer d.Unlock()
|
defer d.Unlock()
|
||||||
d.OnMessage = func(payload datachannel.Payload) {
|
d.Onmessage = func(payload datachannel.Payload) {
|
||||||
switch p := payload.(type) {
|
switch p := payload.(type) {
|
||||||
case *datachannel.PayloadString:
|
case *datachannel.PayloadString:
|
||||||
fmt.Printf("Message '%s' from DataChannel '%s' payload '%s'\n", p.PayloadType().String(), d.Label, string(p.Data))
|
fmt.Printf("Message '%s' from DataChannel '%s' payload '%s'\n", p.PayloadType().String(), d.Label, string(p.Data))
|
||||||
|
@@ -46,7 +46,7 @@ func main() {
|
|||||||
|
|
||||||
// Set a handler for when a new remote track starts, this handler creates a gstreamer pipeline
|
// Set a handler for when a new remote track starts, this handler creates a gstreamer pipeline
|
||||||
// for the given codec
|
// for the given codec
|
||||||
peerConnection.OnTrack = func(track *webrtc.RTCTrack) {
|
peerConnection.Ontrack = func(track *webrtc.RTCTrack) {
|
||||||
codec := track.Codec
|
codec := track.Codec
|
||||||
fmt.Printf("Track has started, of type %d: %s \n", track.PayloadType, codec.Name)
|
fmt.Printf("Track has started, of type %d: %s \n", track.PayloadType, codec.Name)
|
||||||
pipeline := gst.CreatePipeline(codec.Name)
|
pipeline := gst.CreatePipeline(codec.Name)
|
||||||
@@ -59,7 +59,7 @@ func main() {
|
|||||||
|
|
||||||
// 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 ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange = func(connectionState ice.ConnectionState) {
|
||||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -46,7 +46,7 @@ func main() {
|
|||||||
|
|
||||||
// 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 ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange = func(connectionState ice.ConnectionState) {
|
||||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,7 +31,7 @@ func buildPeerConnection() *webrtc.RTCPeerConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
d.Lock()
|
d.Lock()
|
||||||
d.OnMessage = func(payload datachannel.Payload) {
|
d.Onmessage = func(payload datachannel.Payload) {
|
||||||
switch p := payload.(type) {
|
switch p := payload.(type) {
|
||||||
case *datachannel.PayloadString:
|
case *datachannel.PayloadString:
|
||||||
fmt.Printf("Message '%s' from DataChannel '%s' payload '%s'\n", p.PayloadType().String(), d.Label, string(p.Data))
|
fmt.Printf("Message '%s' from DataChannel '%s' payload '%s'\n", p.PayloadType().String(), d.Label, string(p.Data))
|
||||||
@@ -43,7 +43,7 @@ func buildPeerConnection() *webrtc.RTCPeerConnection {
|
|||||||
}
|
}
|
||||||
d.Unlock()
|
d.Unlock()
|
||||||
|
|
||||||
peerConnection.OnIceConnectionStateChange = func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange = func(connectionState ice.ConnectionState) {
|
||||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||||
if connectionState == ice.ConnectionStateConnected {
|
if connectionState == ice.ConnectionStateConnected {
|
||||||
fmt.Println("sending openchannel")
|
fmt.Println("sending openchannel")
|
||||||
|
@@ -22,16 +22,16 @@ func buildPeerConnection() *webrtc.RTCPeerConnection {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
peerConnection.OnIceConnectionStateChange = func(connectionState ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange = func(connectionState ice.ConnectionState) {
|
||||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
peerConnection.OnDataChannel = func(d *webrtc.RTCDataChannel) {
|
peerConnection.Ondatachannel = func(d *webrtc.RTCDataChannel) {
|
||||||
fmt.Printf("New DataChannel %s %d\n", d.Label, d.ID)
|
fmt.Printf("New DataChannel %s %d\n", d.Label, d.ID)
|
||||||
|
|
||||||
d.Lock()
|
d.Lock()
|
||||||
defer d.Unlock()
|
defer d.Unlock()
|
||||||
d.OnMessage = func(payload datachannel.Payload) {
|
d.Onmessage = func(payload datachannel.Payload) {
|
||||||
switch p := payload.(type) {
|
switch p := payload.(type) {
|
||||||
case *datachannel.PayloadString:
|
case *datachannel.PayloadString:
|
||||||
fmt.Printf("Message '%s' from DataChannel '%s' payload '%s'\n", p.PayloadType().String(), d.Label, string(p.Data))
|
fmt.Printf("Message '%s' from DataChannel '%s' payload '%s'\n", p.PayloadType().String(), d.Label, string(p.Data))
|
||||||
|
@@ -46,7 +46,7 @@ func main() {
|
|||||||
// Set a handler for when a new remote track starts, this handler saves buffers to disk as
|
// Set a handler for when a new remote track starts, this handler saves buffers to disk as
|
||||||
// an ivf file, since we could have multiple video tracks we provide a counter.
|
// an ivf file, since we could have multiple video tracks we provide a counter.
|
||||||
// In your application this is where you would handle/process video
|
// In your application this is where you would handle/process video
|
||||||
peerConnection.OnTrack = func(track *webrtc.RTCTrack) {
|
peerConnection.Ontrack = func(track *webrtc.RTCTrack) {
|
||||||
if track.Codec.Name == webrtc.VP8 {
|
if track.Codec.Name == webrtc.VP8 {
|
||||||
fmt.Println("Got VP8 track, saving to disk as output.ivf")
|
fmt.Println("Got VP8 track, saving to disk as output.ivf")
|
||||||
i, err := newIVFWriter("output.ivf")
|
i, err := newIVFWriter("output.ivf")
|
||||||
@@ -61,7 +61,7 @@ func main() {
|
|||||||
|
|
||||||
// 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 ice.ConnectionState) {
|
peerConnection.OnICEConnectionStateChange = func(connectionState ice.ConnectionState) {
|
||||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -84,7 +84,12 @@ type RTCDataChannel struct {
|
|||||||
// OnBufferedAmountLow func()
|
// OnBufferedAmountLow func()
|
||||||
// OnError func()
|
// OnError func()
|
||||||
// OnClose func()
|
// OnClose func()
|
||||||
OnMessage func(datachannel.Payload)
|
|
||||||
|
// Onmessage designates an event handler which is invoked on a message
|
||||||
|
// arrival over the sctp transport from a remote peer.
|
||||||
|
//
|
||||||
|
// Deprecated: Variable name is changing from Onmessage to OnMessage.
|
||||||
|
Onmessage func(datachannel.Payload)
|
||||||
|
|
||||||
rtcPeerConnection *RTCPeerConnection
|
rtcPeerConnection *RTCPeerConnection
|
||||||
}
|
}
|
||||||
|
@@ -99,11 +99,27 @@ type RTCPeerConnection struct {
|
|||||||
// OnIceCandidate func()
|
// OnIceCandidate func()
|
||||||
// OnIceCandidateError func()
|
// OnIceCandidateError func()
|
||||||
// OnSignalingStateChange func()
|
// OnSignalingStateChange func()
|
||||||
OnIceConnectionStateChange func(ice.ConnectionState)
|
|
||||||
|
// OnICEConnectionStateChange designates an event handler which is called
|
||||||
|
// when an ice connection state is changed.
|
||||||
|
//
|
||||||
|
// Deprecated: Variable name is changing from OnICEConnectionStateChange to
|
||||||
|
// OnIceConnectionStateChange.
|
||||||
|
OnICEConnectionStateChange func(ice.ConnectionState)
|
||||||
// OnIceGatheringStateChange func()
|
// OnIceGatheringStateChange func()
|
||||||
// OnConnectionStateChange func()
|
// OnConnectionStateChange func()
|
||||||
OnTrack func(*RTCTrack)
|
|
||||||
OnDataChannel func(*RTCDataChannel)
|
// Ontrack designates an event handler which is called when remote track
|
||||||
|
// arrives from a remote peer.
|
||||||
|
//
|
||||||
|
// Deprecated: Variable name is changing from Ontrack to OnTrack.
|
||||||
|
Ontrack func(*RTCTrack)
|
||||||
|
|
||||||
|
// Ondatachannel designates an event handler which is invoked when a data
|
||||||
|
// channel message arrives from a remote peer.
|
||||||
|
//
|
||||||
|
// Deprecated: Variable name is changing from Ondatachannel to OnDataChannel.
|
||||||
|
Ondatachannel func(*RTCDataChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public
|
// Public
|
||||||
@@ -740,7 +756,7 @@ func (pc *RTCPeerConnection) Close() error {
|
|||||||
|
|
||||||
/* Everything below is private */
|
/* Everything below is private */
|
||||||
func (pc *RTCPeerConnection) generateChannel(ssrc uint32, payloadType uint8) (buffers chan<- *rtp.Packet) {
|
func (pc *RTCPeerConnection) generateChannel(ssrc uint32, payloadType uint8) (buffers chan<- *rtp.Packet) {
|
||||||
if pc.OnTrack == nil {
|
if pc.Ontrack == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -769,7 +785,7 @@ func (pc *RTCPeerConnection) generateChannel(ssrc uint32, payloadType uint8) (bu
|
|||||||
|
|
||||||
// TODO: Register the receiving Track
|
// TODO: Register the receiving Track
|
||||||
|
|
||||||
go pc.OnTrack(track)
|
go pc.Ontrack(track)
|
||||||
return bufferTransport
|
return bufferTransport
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -777,8 +793,8 @@ func (pc *RTCPeerConnection) iceStateChange(newState ice.ConnectionState) {
|
|||||||
pc.Lock()
|
pc.Lock()
|
||||||
defer pc.Unlock()
|
defer pc.Unlock()
|
||||||
|
|
||||||
if pc.OnIceConnectionStateChange != nil && pc.IceConnectionState != newState {
|
if pc.OnICEConnectionStateChange != nil && pc.IceConnectionState != newState {
|
||||||
pc.OnIceConnectionStateChange(newState)
|
pc.OnICEConnectionStateChange(newState)
|
||||||
}
|
}
|
||||||
pc.IceConnectionState = newState
|
pc.IceConnectionState = newState
|
||||||
}
|
}
|
||||||
@@ -792,20 +808,20 @@ func (pc *RTCPeerConnection) dataChannelEventHandler(e network.DataChannelEvent)
|
|||||||
id := event.StreamIdentifier()
|
id := event.StreamIdentifier()
|
||||||
newDataChannel := &RTCDataChannel{ID: &id, Label: event.Label, rtcPeerConnection: pc}
|
newDataChannel := &RTCDataChannel{ID: &id, Label: event.Label, rtcPeerConnection: pc}
|
||||||
pc.dataChannels[e.StreamIdentifier()] = newDataChannel
|
pc.dataChannels[e.StreamIdentifier()] = newDataChannel
|
||||||
if pc.OnDataChannel != nil {
|
if pc.Ondatachannel != nil {
|
||||||
go pc.OnDataChannel(newDataChannel)
|
go pc.Ondatachannel(newDataChannel)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("OnDataChannel is unset, discarding message")
|
fmt.Println("Ondatachannel is unset, discarding message")
|
||||||
}
|
}
|
||||||
case *network.DataChannelMessage:
|
case *network.DataChannelMessage:
|
||||||
if datachannel, ok := pc.dataChannels[e.StreamIdentifier()]; ok {
|
if datachannel, ok := pc.dataChannels[e.StreamIdentifier()]; ok {
|
||||||
datachannel.RLock()
|
datachannel.RLock()
|
||||||
defer datachannel.RUnlock()
|
defer datachannel.RUnlock()
|
||||||
|
|
||||||
if datachannel.OnMessage != nil {
|
if datachannel.Onmessage != nil {
|
||||||
go datachannel.OnMessage(event.Payload)
|
go datachannel.Onmessage(event.Payload)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("OnMessage has not been set for Datachannel %s %d \n", datachannel.Label, e.StreamIdentifier())
|
fmt.Printf("Onmessage has not been set for Datachannel %s %d \n", datachannel.Label, e.StreamIdentifier())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("No datachannel found for streamIdentifier %d \n", e.StreamIdentifier())
|
fmt.Printf("No datachannel found for streamIdentifier %d \n", e.StreamIdentifier())
|
||||||
|
Reference in New Issue
Block a user