From 8898ee3addb71fa99b624224e20ef1778fd384fa Mon Sep 17 00:00:00 2001 From: scruzin Date: Sun, 13 Jan 2019 09:18:52 +1030 Subject: [PATCH] setupURL() now a method on Session and renamed init(). --- rtmp/rtmp.go | 2 +- rtmp/rtmp_test.go | 17 ++++++++++------- rtmp/session.go | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index ac74a3ec..1693a7f1 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -163,7 +163,7 @@ var ( ) // init initialises the Session link -func setupURL(s *Session) (err error) { +func (s *Session) init() (err error) { s.link.protocol, s.link.host, s.link.port, s.link.app, s.link.playpath, err = parseURL(s.url) if err != nil { return err diff --git a/rtmp/rtmp_test.go b/rtmp/rtmp_test.go index 01dad10f..4e8daf5f 100644 --- a/rtmp/rtmp_test.go +++ b/rtmp/rtmp_test.go @@ -116,7 +116,7 @@ func TestKey(t *testing.T) { testLog(0, "Testing against URL "+testBaseURL+testKey) } -// TestSetupURL tests URL parsing. +// TestSetupURL tests URL parsing and link initialization. func TestSetupURL(t *testing.T) { testLog(0, "TestSetupURL") // test with just the base URL @@ -124,19 +124,22 @@ func TestSetupURL(t *testing.T) { if s.url != testBaseURL && s.link.timeout != testTimeout { t.Errorf("NewSession failed") } - err := setupURL(s) + err := s.init() if err != nil { - t.Errorf("setupURL(testBaseURL) failed with error: %v", err) + t.Errorf("setupURL: failed with error: %v", err) } // test the parts are as expected - if rtmpProtocolStrings[s.link.protocol] != rtmpProtocol { - t.Errorf("setupURL returned wrong protocol: %v", s.link.protocol) + if s.link.protocol&featureWrite == 0 { + t.Errorf("setupURL: link not writable") + } + if rtmpProtocolStrings[s.link.protocol&^featureWrite] != rtmpProtocol { + t.Errorf("setupURL: wrong protocol: %v", s.link.protocol) } if s.link.host != testHost { - t.Errorf("setupURL returned wrong host: %v", s.link.host) + t.Errorf("setupURL: wrong host: %v", s.link.host) } if s.link.app != testApp { - t.Errorf("setupURL returned wrong app: %v", s.link.app) + t.Errorf("setupURL: wrong app: %v", s.link.app) } } diff --git a/rtmp/session.go b/rtmp/session.go index ca66a6ef..7452b9db 100644 --- a/rtmp/session.go +++ b/rtmp/session.go @@ -129,7 +129,7 @@ func (s *Session) Open() error { if s.isConnected() { return errConnected } - err := setupURL(s) + err := s.init() if err != nil { return err }