mirror of
				https://github.com/pion/webrtc.git
				synced 2025-10-31 18:52:55 +08:00 
			
		
		
		
	 backkem
					backkem
				
			
				
					committed by
					
						 Michiel De Backker
						Michiel De Backker
					
				
			
			
				
	
			
			
			 Michiel De Backker
						Michiel De Backker
					
				
			
						parent
						
							4fe2728721
						
					
				
				
					commit
					36cf0df239
				
			
							
								
								
									
										27
									
								
								api.go
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								api.go
									
									
									
									
									
								
							| @@ -43,30 +43,3 @@ func WithSettingEngine(s SettingEngine) func(a *API) { | |||||||
| 		a.settingEngine = &s | 		a.settingEngine = &s | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| // defaultAPI is used to support the legacy global API. |  | ||||||
| // This global API should not be extended and may be phased out |  | ||||||
| // in the future. |  | ||||||
| var defaultAPI = NewAPI() |  | ||||||
|  |  | ||||||
| // Media Engine API |  | ||||||
|  |  | ||||||
| // RegisterCodec on the default API. |  | ||||||
| // See MediaEngine for details. |  | ||||||
| func RegisterCodec(codec *RTPCodec) { |  | ||||||
| 	defaultAPI.mediaEngine.RegisterCodec(codec) |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // RegisterDefaultCodecs on the default API. |  | ||||||
| // See MediaEngine for details. |  | ||||||
| func RegisterDefaultCodecs() { |  | ||||||
| 	defaultAPI.mediaEngine.RegisterDefaultCodecs() |  | ||||||
| } |  | ||||||
|  |  | ||||||
| // PeerConnection API |  | ||||||
|  |  | ||||||
| // NewPeerConnection using the default API. |  | ||||||
| // See API.NewRTCPeerConnection for details. |  | ||||||
| func NewPeerConnection(configuration Configuration) (*PeerConnection, error) { |  | ||||||
| 	return defaultAPI.NewPeerConnection(configuration) |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -17,10 +17,6 @@ import ( | |||||||
| func gstreamerReceiveMain() { | func gstreamerReceiveMain() { | ||||||
| 	// Everything below is the pion-WebRTC API! Thanks for using it ❤️. | 	// Everything below is the pion-WebRTC API! Thanks for using it ❤️. | ||||||
|  |  | ||||||
| 	// Setup the codecs you want to use. |  | ||||||
| 	// We'll use the default ones but you can also define your own |  | ||||||
| 	webrtc.RegisterDefaultCodecs() |  | ||||||
|  |  | ||||||
| 	// Prepare the configuration | 	// Prepare the configuration | ||||||
| 	config := webrtc.Configuration{ | 	config := webrtc.Configuration{ | ||||||
| 		ICEServers: []webrtc.ICEServer{ | 		ICEServers: []webrtc.ICEServer{ | ||||||
|   | |||||||
| @@ -12,10 +12,6 @@ import ( | |||||||
| func main() { | func main() { | ||||||
| 	// Everything below is the pion-WebRTC API! Thanks for using it ❤️. | 	// Everything below is the pion-WebRTC API! Thanks for using it ❤️. | ||||||
|  |  | ||||||
| 	// Setup the codecs you want to use. |  | ||||||
| 	// We'll use the default ones but you can also define your own |  | ||||||
| 	webrtc.RegisterDefaultCodecs() |  | ||||||
|  |  | ||||||
| 	// Prepare the configuration | 	// Prepare the configuration | ||||||
| 	config := webrtc.Configuration{ | 	config := webrtc.Configuration{ | ||||||
| 		ICEServers: []webrtc.ICEServer{ | 		ICEServers: []webrtc.ICEServer{ | ||||||
|   | |||||||
| @@ -17,10 +17,6 @@ func main() { | |||||||
|  |  | ||||||
| 	// Everything below is the pion-WebRTC API! Thanks for using it ❤️. | 	// Everything below is the pion-WebRTC API! Thanks for using it ❤️. | ||||||
|  |  | ||||||
| 	// Setup the codecs you want to use. |  | ||||||
| 	// We'll use the default ones but you can also define your own |  | ||||||
| 	webrtc.RegisterDefaultCodecs() |  | ||||||
|  |  | ||||||
| 	// Prepare the configuration | 	// Prepare the configuration | ||||||
| 	config := webrtc.Configuration{ | 	config := webrtc.Configuration{ | ||||||
| 		ICEServers: []webrtc.ICEServer{ | 		ICEServers: []webrtc.ICEServer{ | ||||||
|   | |||||||
| @@ -33,10 +33,6 @@ func watchHandle(handle *janus.Handle) { | |||||||
| func main() { | func main() { | ||||||
| 	// Everything below is the pion-WebRTC API! Thanks for using it ❤️. | 	// Everything below is the pion-WebRTC API! Thanks for using it ❤️. | ||||||
|  |  | ||||||
| 	// Setup the codecs you want to use. |  | ||||||
| 	// We'll use the default ones but you can also define your own |  | ||||||
| 	webrtc.RegisterDefaultCodecs() |  | ||||||
|  |  | ||||||
| 	// Prepare the configuration | 	// Prepare the configuration | ||||||
| 	config := webrtc.Configuration{ | 	config := webrtc.Configuration{ | ||||||
| 		ICEServers: []webrtc.ICEServer{ | 		ICEServers: []webrtc.ICEServer{ | ||||||
|   | |||||||
| @@ -34,10 +34,6 @@ func watchHandle(handle *janus.Handle) { | |||||||
| func main() { | func main() { | ||||||
| 	// Everything below is the pion-WebRTC API! Thanks for using it ❤️. | 	// Everything below is the pion-WebRTC API! Thanks for using it ❤️. | ||||||
|  |  | ||||||
| 	// Setup the codecs you want to use. |  | ||||||
| 	// We'll use the default ones but you can also define your own |  | ||||||
| 	webrtc.RegisterDefaultCodecs() |  | ||||||
|  |  | ||||||
| 	// Prepare the configuration | 	// Prepare the configuration | ||||||
| 	config := webrtc.Configuration{ | 	config := webrtc.Configuration{ | ||||||
| 		ICEServers: []webrtc.ICEServer{ | 		ICEServers: []webrtc.ICEServer{ | ||||||
|   | |||||||
| @@ -12,12 +12,19 @@ import ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| func main() { | func main() { | ||||||
| 	// Everything below is the pion-WebRTC API! Thanks for using it ❤️. |  | ||||||
|  | 	// Create a MediaEngine object to configure the supported codec | ||||||
|  | 	m := webrtc.MediaEngine{} | ||||||
|  |  | ||||||
| 	// Setup the codecs you want to use. | 	// Setup the codecs you want to use. | ||||||
| 	// We'll use a VP8 codec but you can also define your own | 	// We'll use a VP8 codec but you can also define your own | ||||||
| 	webrtc.RegisterCodec(webrtc.NewRTPOpusCodec(webrtc.DefaultPayloadTypeOpus, 48000, 2)) | 	m.RegisterCodec(webrtc.NewRTPOpusCodec(webrtc.DefaultPayloadTypeOpus, 48000, 2)) | ||||||
| 	webrtc.RegisterCodec(webrtc.NewRTPVP8Codec(webrtc.DefaultPayloadTypeVP8, 90000)) | 	m.RegisterCodec(webrtc.NewRTPVP8Codec(webrtc.DefaultPayloadTypeVP8, 90000)) | ||||||
|  |  | ||||||
|  | 	// Create the API object with the MediaEngine | ||||||
|  | 	api := webrtc.NewAPI(webrtc.WithMediaEngine(m)) | ||||||
|  |  | ||||||
|  | 	// Everything below is the pion-WebRTC API! Thanks for using it ❤️. | ||||||
|  |  | ||||||
| 	// Prepare the configuration | 	// Prepare the configuration | ||||||
| 	config := webrtc.Configuration{ | 	config := webrtc.Configuration{ | ||||||
| @@ -29,7 +36,7 @@ func main() { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Create a new RTCPeerConnection | 	// Create a new RTCPeerConnection | ||||||
| 	peerConnection, err := webrtc.NewPeerConnection(config) | 	peerConnection, err := api.NewPeerConnection(config) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		panic(err) | 		panic(err) | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -45,6 +45,16 @@ const ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| func main() { | func main() { | ||||||
|  | 	// Create a MediaEngine object to configure the supported codec | ||||||
|  | 	m := webrtc.MediaEngine{} | ||||||
|  |  | ||||||
|  | 	// Setup the codecs you want to use. | ||||||
|  | 	// Only support VP8, this makes our proxying code simpler | ||||||
|  | 	m.RegisterCodec(webrtc.NewRTPVP8Codec(webrtc.DefaultPayloadTypeVP8, 90000)) | ||||||
|  |  | ||||||
|  | 	// Create the API object with the MediaEngine | ||||||
|  | 	api := webrtc.NewAPI(webrtc.WithMediaEngine(m)) | ||||||
|  |  | ||||||
| 	port := flag.Int("port", 8080, "http server port") | 	port := flag.Int("port", 8080, "http server port") | ||||||
| 	flag.Parse() | 	flag.Parse() | ||||||
|  |  | ||||||
| @@ -66,13 +76,10 @@ func main() { | |||||||
| 	signal.Decode(mustReadHTTP(sdp), &offer) | 	signal.Decode(mustReadHTTP(sdp), &offer) | ||||||
| 	fmt.Println("") | 	fmt.Println("") | ||||||
|  |  | ||||||
| 	/* Everything below is the pion-WebRTC API, thanks for using it! */ | 	// Everything below is the pion-WebRTC API, thanks for using it ❤️. | ||||||
|  |  | ||||||
| 	// Only support VP8, this makes our proxying code simpler |  | ||||||
| 	webrtc.RegisterCodec(webrtc.NewRTPVP8Codec(webrtc.DefaultPayloadTypeVP8, 90000)) |  | ||||||
|  |  | ||||||
| 	// Create a new RTCPeerConnection | 	// Create a new RTCPeerConnection | ||||||
| 	peerConnection, err := webrtc.NewPeerConnection(peerConnectionConfig) | 	peerConnection, err := api.NewPeerConnection(peerConnectionConfig) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		panic(err) | 		panic(err) | ||||||
| 	} | 	} | ||||||
| @@ -146,7 +153,7 @@ func main() { | |||||||
| 		signal.Decode(mustReadHTTP(sdp), &recvOnlyOffer) | 		signal.Decode(mustReadHTTP(sdp), &recvOnlyOffer) | ||||||
|  |  | ||||||
| 		// Create a new PeerConnection | 		// Create a new PeerConnection | ||||||
| 		peerConnection, err := webrtc.NewPeerConnection(peerConnectionConfig) | 		peerConnection, err := api.NewPeerConnection(peerConnectionConfig) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			panic(err) | 			panic(err) | ||||||
| 		} | 		} | ||||||
|   | |||||||
| @@ -115,6 +115,15 @@ type PeerConnection struct { | |||||||
| 	api *API | 	api *API | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // NewPeerConnection creates a peerconnection with the default | ||||||
|  | // codecs. See API.NewRTCPeerConnection for details. | ||||||
|  | func NewPeerConnection(configuration Configuration) (*PeerConnection, error) { | ||||||
|  | 	m := MediaEngine{} | ||||||
|  | 	m.RegisterDefaultCodecs() | ||||||
|  | 	api := NewAPI(WithMediaEngine(m)) | ||||||
|  | 	return api.NewPeerConnection(configuration) | ||||||
|  | } | ||||||
|  |  | ||||||
| // NewPeerConnection creates a new PeerConnection with the provided configuration against the received API object | // NewPeerConnection creates a new PeerConnection with the provided configuration against the received API object | ||||||
| func (api *API) NewPeerConnection(configuration Configuration) (*PeerConnection, error) { | func (api *API) NewPeerConnection(configuration Configuration) (*PeerConnection, error) { | ||||||
| 	// https://w3c.github.io/webrtc-pc/#constructor (Step #2) | 	// https://w3c.github.io/webrtc-pc/#constructor (Step #2) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user