mirror of
https://github.com/Monibuca/plugin-webrtc.git
synced 2025-10-07 15:50:52 +08:00
修改API路由
This commit is contained in:
12
README.md
12
README.md
@@ -6,10 +6,8 @@
|
|||||||
|
|
||||||
通过浏览器和monibuca交换sdp信息,然后读取rtp包或者发送rtp的方式进行
|
通过浏览器和monibuca交换sdp信息,然后读取rtp包或者发送rtp的方式进行
|
||||||
|
|
||||||
# 界面操作
|
# API
|
||||||
|
- /api/webrtc/play?streamPath=live/rtc
|
||||||
## publish
|
用于播放live/rtc的流,需要在请求的body中放入sdp的json数据,这个接口会返回服务端的sdp数据
|
||||||
在后台管理界面,会自动获取摄像头,在streamPath中填入需要发布流的名称,点击publish开始发布
|
- /api/webrtc/publish?streamPath=live/rtc
|
||||||
|
同上
|
||||||
## play
|
|
||||||
在后台管理界面,点击上方play tab页此时会显示当前monibuca中所有正在发布的流,点击其中需要播放的流,会出现按钮,点击Play按钮即可弹出播放器界面并进行播放。
|
|
19
main.go
19
main.go
@@ -156,12 +156,25 @@ func (rtc *WebRTC) Publish(streamPath string) bool {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
var etrack engine.Track
|
var etrack engine.Track
|
||||||
|
codec := track.Codec()
|
||||||
if track.Kind() == RTPCodecTypeAudio {
|
if track.Kind() == RTPCodecTypeAudio {
|
||||||
//TODO: 判断音频格式
|
switch codec.MimeType {
|
||||||
|
case MimeTypePCMA:
|
||||||
at := engine.NewAudioTrack()
|
at := engine.NewAudioTrack()
|
||||||
at.SoundFormat = 7
|
at.SoundFormat = 7
|
||||||
|
at.SoundType = byte(codec.Channels) - 1
|
||||||
rtc.SetOriginAT(at)
|
rtc.SetOriginAT(at)
|
||||||
etrack = at
|
etrack = at
|
||||||
|
case MimeTypePCMU:
|
||||||
|
at := engine.NewAudioTrack()
|
||||||
|
at.SoundFormat = 8
|
||||||
|
at.SoundType = byte(codec.Channels) - 1
|
||||||
|
rtc.SetOriginAT(at)
|
||||||
|
etrack = at
|
||||||
|
default:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
vt := engine.NewVideoTrack()
|
vt := engine.NewVideoTrack()
|
||||||
vt.CodecID = 7
|
vt.CodecID = 7
|
||||||
@@ -214,7 +227,7 @@ func run() {
|
|||||||
}
|
}
|
||||||
m.RegisterDefaultCodecs()
|
m.RegisterDefaultCodecs()
|
||||||
api = NewAPI(WithMediaEngine(&m), WithSettingEngine(s))
|
api = NewAPI(WithMediaEngine(&m), WithSettingEngine(s))
|
||||||
http.HandleFunc("/webrtc/play", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/api/webrtc/play", func(w http.ResponseWriter, r *http.Request) {
|
||||||
utils.CORS(w, r)
|
utils.CORS(w, r)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
streamPath := r.URL.Query().Get("streamPath")
|
streamPath := r.URL.Query().Get("streamPath")
|
||||||
@@ -337,7 +350,7 @@ func run() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
http.HandleFunc("/webrtc/publish", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/api/webrtc/publish", func(w http.ResponseWriter, r *http.Request) {
|
||||||
streamPath := r.URL.Query().Get("streamPath")
|
streamPath := r.URL.Query().Get("streamPath")
|
||||||
offer := SessionDescription{}
|
offer := SessionDescription{}
|
||||||
bytes, err := ioutil.ReadAll(r.Body)
|
bytes, err := ioutil.ReadAll(r.Body)
|
||||||
|
Reference in New Issue
Block a user