Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support standard streamid syntax #39

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion srt/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (s *ServerImpl) registerForStats(ctx context.Context, conn *srtConn) {
func (s *ServerImpl) GetStatistics() []*relay.StreamStatistics {
streams := s.relay.GetStatistics()
for _, stream := range streams {
stream.URL = fmt.Sprintf("srt://%s?streamid=play/%s", s.config.PublicAddress, stream.Name)
stream.URL = fmt.Sprintf("srt://%s?streamid=#!::m=request,r=%s", s.config.PublicAddress, stream.Name)
}
return streams
}
Expand Down
82 changes: 60 additions & 22 deletions stream/streamid.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,73 @@ func NewStreamID(name string, password string, mode Mode) (*StreamID, error) {
// The second slash and password is optional and defaults to empty.
// If error is not nil then StreamID will remain unchanged.
func (s *StreamID) FromString(src string) error {
split := strings.Split(src, "/")

password := ""
if len(split) == 3 {
password = split[2]
} else if len(split) != 2 {
return InvalidSlashes
}
modeStr := split[0]
name := split[1]
if strings.HasPrefix(src, "#!::") {
for _, kv := range strings.Split(src[len("#!::"):], ",") {
kv2 := strings.SplitN(kv, "=", 2)
if len(kv2) != 2 {
return fmt.Errorf("invalid value")
}

if len(name) == 0 {
return MissingName
key, value := kv2[0], kv2[1]

switch key {
case "u":
// s.user = value

case "r":
s.name = value

case "h":

case "s":
s.password = value

case "t":

case "m":
switch value {
case "request":
s.mode = ModePlay

case "publish":
s.mode = ModePublish

default:
return InvalidMode
}

default:
return fmt.Errorf("unsupported key '%s'", key)
}
}
} else {
split := strings.Split(src, "/")

s.password = ""
if len(split) == 3 {
s.password = split[2]
} else if len(split) != 2 {
return InvalidSlashes
}
modeStr := split[0]
s.name = split[1]

switch modeStr {
case "play":
s.mode = ModePlay
case "publish":
s.mode = ModePublish
default:
return InvalidMode
}
}

var mode Mode
switch modeStr {
case "play":
mode = ModePlay
case "publish":
mode = ModePublish
default:
return InvalidMode
if len(s.name) == 0 {
return MissingName
}

s.str = src
s.mode = mode
s.name = name
s.password = password
return nil
}

Expand Down