mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 23:26:58 +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
|
||||
// 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())
|
||||
|
||||
// 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.OnMessage = func(payload datachannel.Payload) {
|
||||
dataChannel.Onmessage = func(payload datachannel.Payload) {
|
||||
switch p := payload.(type) {
|
||||
case *datachannel.PayloadString:
|
||||
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
|
||||
// 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())
|
||||
}
|
||||
|
||||
datachannels := make([]*webrtc.RTCDataChannel, 0)
|
||||
var dataChannelsLock sync.RWMutex
|
||||
|
||||
peerConnection.OnDataChannel = func(d *webrtc.RTCDataChannel) {
|
||||
peerConnection.Ondatachannel = func(d *webrtc.RTCDataChannel) {
|
||||
dataChannelsLock.Lock()
|
||||
datachannels = append(datachannels, d)
|
||||
dataChannelsLock.Unlock()
|
||||
@@ -70,7 +70,7 @@ func main() {
|
||||
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
d.OnMessage = func(payload datachannel.Payload) {
|
||||
d.Onmessage = func(payload datachannel.Payload) {
|
||||
switch p := payload.(type) {
|
||||
case *datachannel.PayloadString:
|
||||
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
|
||||
// for the given codec
|
||||
peerConnection.OnTrack = func(track *webrtc.RTCTrack) {
|
||||
peerConnection.Ontrack = func(track *webrtc.RTCTrack) {
|
||||
codec := track.Codec
|
||||
fmt.Printf("Track has started, of type %d: %s \n", track.PayloadType, codec.Name)
|
||||
pipeline := gst.CreatePipeline(codec.Name)
|
||||
@@ -59,7 +59,7 @@ func main() {
|
||||
|
||||
// Set the handler for ICE connection state
|
||||
// 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())
|
||||
}
|
||||
|
||||
|
@@ -46,7 +46,7 @@ func main() {
|
||||
|
||||
// Set the handler for ICE connection state
|
||||
// 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())
|
||||
}
|
||||
|
||||
|
@@ -31,7 +31,7 @@ func buildPeerConnection() *webrtc.RTCPeerConnection {
|
||||
}
|
||||
|
||||
d.Lock()
|
||||
d.OnMessage = func(payload datachannel.Payload) {
|
||||
d.Onmessage = func(payload datachannel.Payload) {
|
||||
switch p := payload.(type) {
|
||||
case *datachannel.PayloadString:
|
||||
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()
|
||||
|
||||
peerConnection.OnIceConnectionStateChange = func(connectionState ice.ConnectionState) {
|
||||
peerConnection.OnICEConnectionStateChange = func(connectionState ice.ConnectionState) {
|
||||
fmt.Printf("Connection State has changed %s \n", connectionState.String())
|
||||
if connectionState == ice.ConnectionStateConnected {
|
||||
fmt.Println("sending openchannel")
|
||||
|
@@ -22,16 +22,16 @@ func buildPeerConnection() *webrtc.RTCPeerConnection {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
peerConnection.OnIceConnectionStateChange = func(connectionState ice.ConnectionState) {
|
||||
peerConnection.OnICEConnectionStateChange = func(connectionState ice.ConnectionState) {
|
||||
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)
|
||||
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
d.OnMessage = func(payload datachannel.Payload) {
|
||||
d.Onmessage = func(payload datachannel.Payload) {
|
||||
switch p := payload.(type) {
|
||||
case *datachannel.PayloadString:
|
||||
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
|
||||
// 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
|
||||
peerConnection.OnTrack = func(track *webrtc.RTCTrack) {
|
||||
peerConnection.Ontrack = func(track *webrtc.RTCTrack) {
|
||||
if track.Codec.Name == webrtc.VP8 {
|
||||
fmt.Println("Got VP8 track, saving to disk as output.ivf")
|
||||
i, err := newIVFWriter("output.ivf")
|
||||
@@ -61,7 +61,7 @@ func main() {
|
||||
|
||||
// Set the handler for ICE connection state
|
||||
// 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())
|
||||
}
|
||||
|
||||
|
@@ -84,7 +84,12 @@ type RTCDataChannel struct {
|
||||
// OnBufferedAmountLow func()
|
||||
// OnError 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
|
||||
}
|
||||
|
@@ -99,11 +99,27 @@ type RTCPeerConnection struct {
|
||||
// OnIceCandidate func()
|
||||
// OnIceCandidateError 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()
|
||||
// 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
|
||||
@@ -740,7 +756,7 @@ func (pc *RTCPeerConnection) Close() error {
|
||||
|
||||
/* Everything below is private */
|
||||
func (pc *RTCPeerConnection) generateChannel(ssrc uint32, payloadType uint8) (buffers chan<- *rtp.Packet) {
|
||||
if pc.OnTrack == nil {
|
||||
if pc.Ontrack == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -769,7 +785,7 @@ func (pc *RTCPeerConnection) generateChannel(ssrc uint32, payloadType uint8) (bu
|
||||
|
||||
// TODO: Register the receiving Track
|
||||
|
||||
go pc.OnTrack(track)
|
||||
go pc.Ontrack(track)
|
||||
return bufferTransport
|
||||
}
|
||||
|
||||
@@ -777,8 +793,8 @@ func (pc *RTCPeerConnection) iceStateChange(newState ice.ConnectionState) {
|
||||
pc.Lock()
|
||||
defer pc.Unlock()
|
||||
|
||||
if pc.OnIceConnectionStateChange != nil && pc.IceConnectionState != newState {
|
||||
pc.OnIceConnectionStateChange(newState)
|
||||
if pc.OnICEConnectionStateChange != nil && pc.IceConnectionState != newState {
|
||||
pc.OnICEConnectionStateChange(newState)
|
||||
}
|
||||
pc.IceConnectionState = newState
|
||||
}
|
||||
@@ -792,20 +808,20 @@ func (pc *RTCPeerConnection) dataChannelEventHandler(e network.DataChannelEvent)
|
||||
id := event.StreamIdentifier()
|
||||
newDataChannel := &RTCDataChannel{ID: &id, Label: event.Label, rtcPeerConnection: pc}
|
||||
pc.dataChannels[e.StreamIdentifier()] = newDataChannel
|
||||
if pc.OnDataChannel != nil {
|
||||
go pc.OnDataChannel(newDataChannel)
|
||||
if pc.Ondatachannel != nil {
|
||||
go pc.Ondatachannel(newDataChannel)
|
||||
} else {
|
||||
fmt.Println("OnDataChannel is unset, discarding message")
|
||||
fmt.Println("Ondatachannel is unset, discarding message")
|
||||
}
|
||||
case *network.DataChannelMessage:
|
||||
if datachannel, ok := pc.dataChannels[e.StreamIdentifier()]; ok {
|
||||
datachannel.RLock()
|
||||
defer datachannel.RUnlock()
|
||||
|
||||
if datachannel.OnMessage != nil {
|
||||
go datachannel.OnMessage(event.Payload)
|
||||
if datachannel.Onmessage != nil {
|
||||
go datachannel.Onmessage(event.Payload)
|
||||
} 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 {
|
||||
fmt.Printf("No datachannel found for streamIdentifier %d \n", e.StreamIdentifier())
|
||||
|
Reference in New Issue
Block a user