@@ -2,15 +2,11 @@ package webrtc
22
33import (
44 "errors"
5- "io"
6- "net/http"
75 "strings"
86
97 . "github.com/pion/webrtc/v4"
108 "m7s.live/v5"
11- "m7s.live/v5/pkg"
129 "m7s.live/v5/pkg/config"
13- "m7s.live/v5/pkg/util"
1410)
1511
1612const (
@@ -43,92 +39,6 @@ func (c *Client) Start() (err error) {
4339 return c .MultipleConnection .Start ()
4440}
4541
46- // WHIPClient is a client that pushes media to the server
47- type WHIPClient struct {
48- Client
49- pushCtx m7s.PushJob
50- }
51-
52- func (c * WHIPClient ) GetPushJob () * m7s.PushJob {
53- return & c .pushCtx
54- }
55-
56- // WHEPClient is a client that pulls media from the server
57- type WHEPClient struct {
58- Client
59- pullCtx m7s.PullJob
60- }
61-
62- func (c * WHEPClient ) GetPullJob () * m7s.PullJob {
63- return & c .pullCtx
64- }
65-
66- func (c * WHEPClient ) Start () (err error ) {
67- err = c .pullCtx .Publish ()
68- if err != nil {
69- return
70- }
71- c .Publisher = c .pullCtx .Publisher
72- c .pullCtx .GoToStepConst (StepWebRTCInit )
73- err = c .Client .Start ()
74- if err != nil {
75- return
76- }
77- // u, _ := url.Parse(c.pullCtx.RemoteURL)
78- // c.ApiBase, _, _ = strings.Cut(c.pullCtx.RemoteURL, "?")
79- c .Receive ()
80- if c .pullCtx .PublishConfig .PubVideo {
81- var transeiver * RTPTransceiver
82- transeiver , err = c .AddTransceiverFromKind (RTPCodecTypeVideo , RTPTransceiverInit {
83- Direction : RTPTransceiverDirectionRecvonly ,
84- })
85- if err != nil {
86- return
87- }
88- c .Info ("webrtc add video transceiver" , "transceiver" , transeiver .Mid ())
89- }
90-
91- if c .pullCtx .PublishConfig .PubAudio {
92- var transeiver * RTPTransceiver
93- transeiver , err = c .AddTransceiverFromKind (RTPCodecTypeAudio , RTPTransceiverInit {
94- Direction : RTPTransceiverDirectionRecvonly ,
95- })
96- if err != nil {
97- return
98- }
99- c .Info ("webrtc add audio transceiver" , "transceiver" , transeiver .Mid ())
100- }
101-
102- c .pullCtx .GoToStepConst (StepOfferCreate )
103- var sdpBody SDPBody
104- sdpBody .SessionDescription , err = c .GetOffer ()
105- if err != nil {
106- return
107- }
108-
109- c .pullCtx .GoToStepConst (StepSessionCreate )
110- var res * http.Response
111- res , err = http .DefaultClient .Post (c .pullCtx .RemoteURL , "application/sdp" , strings .NewReader (sdpBody .SessionDescription .SDP ))
112- if err != nil {
113- return
114- }
115- c .pullCtx .GoToStepConst (StepNegotiation )
116- if res .StatusCode != http .StatusCreated && res .StatusCode != http .StatusOK {
117- err = errors .New (res .Status )
118- return
119- }
120- var sd SessionDescription
121- sd .Type = SDPTypeAnswer
122- var body util.Buffer
123- io .Copy (& body , res .Body )
124- sd .SDP = string (body )
125- if err = c .SetRemoteDescription (sd ); err != nil {
126- return
127- }
128- c .pullCtx .GoToStepConst (pkg .StepStreaming )
129- return
130- }
131-
13242func NewPuller (conf config.Pull ) m7s.IPuller {
13343 if strings .HasPrefix (conf .URL , "https://rtc.live.cloudflare.com" ) {
13444 return NewCFClient (DIRECTION_PULL )
0 commit comments