mirror of
https://github.com/Monibuca/plugin-jessica.git
synced 2025-10-04 15:42:46 +08:00
feat: remove ps
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -91,28 +92,10 @@ func (j *JessicaFLV) OnEvent(event any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type JessicaPS struct {
|
|
||||||
Subscriber
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *JessicaPS) OnEvent(event any) {
|
|
||||||
switch v := event.(type) {
|
|
||||||
case *track.Data:
|
|
||||||
if v.Name == "ps" {
|
|
||||||
j.AddTrack(v)
|
|
||||||
go v.Play(j.IO, func(data any) error {
|
|
||||||
return wsutil.WriteServerBinary(j, data.(*util.ListItem[util.Buffer]).Value)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
j.Subscriber.OnEvent(event)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *JessicaConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (j *JessicaConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
isFlv := strings.HasSuffix(r.URL.Path, ".flv")
|
ext := path.Ext(r.URL.Path)
|
||||||
isPS := strings.HasSuffix(r.URL.Path, ".ps")
|
streamPath := strings.TrimPrefix(r.URL.Path, "/")
|
||||||
streamPath := strings.TrimSuffix(strings.TrimPrefix(r.URL.Path, "/"), ".flv")
|
streamPath = strings.TrimSuffix(streamPath, ext)
|
||||||
if r.URL.RawQuery != "" {
|
if r.URL.RawQuery != "" {
|
||||||
streamPath += "?" + r.URL.RawQuery
|
streamPath += "?" + r.URL.RawQuery
|
||||||
}
|
}
|
||||||
@@ -125,9 +108,7 @@ func (j *JessicaConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
baseStream.SetParentCtx(r.Context()) //注入context
|
baseStream.SetParentCtx(r.Context()) //注入context
|
||||||
baseStream.ID = r.RemoteAddr
|
baseStream.ID = r.RemoteAddr
|
||||||
var specific ISubscriber
|
var specific ISubscriber
|
||||||
if isPS {
|
if ext == ".flv" {
|
||||||
specific = &JessicaPS{baseStream}
|
|
||||||
} else if isFlv {
|
|
||||||
specific = &JessicaFLV{baseStream}
|
specific = &JessicaFLV{baseStream}
|
||||||
} else {
|
} else {
|
||||||
specific = &JessicaSubscriber{baseStream, make([]byte, 5)}
|
specific = &JessicaSubscriber{baseStream, make([]byte, 5)}
|
||||||
@@ -136,7 +117,7 @@ func (j *JessicaConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if isFlv {
|
if ext == ".flv" {
|
||||||
go specific.PlayFLV()
|
go specific.PlayFLV()
|
||||||
} else {
|
} else {
|
||||||
go specific.PlayRaw()
|
go specific.PlayRaw()
|
||||||
@@ -145,8 +126,8 @@ func (j *JessicaConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
b, err := wsutil.ReadClientBinary(conn)
|
b, err := wsutil.ReadClientBinary(conn)
|
||||||
var rtpPacket rtp.Packet
|
var rtpPacket rtp.Packet
|
||||||
if err == nil {
|
if err == nil {
|
||||||
dc := specific.GetSubscriber().Stream.NewDataTrack("voice", nil)
|
dc := track.NewDataTrack[[]byte]("voice")
|
||||||
dc.Attach()
|
dc.Attach(specific.GetSubscriber().Stream)
|
||||||
for err == nil {
|
for err == nil {
|
||||||
err = rtpPacket.Unmarshal(b)
|
err = rtpPacket.Unmarshal(b)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Reference in New Issue
Block a user