Skip to content

Commit 3a71f4e

Browse files
committed
Fix #11: Add RTMP example.
1 parent 1f6af13 commit 3a71f4e

12 files changed

+70
-199
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ _testmain.go
2929
# Coverage files
3030
*.txt
3131

32+
.DS_Store

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/ossrs/go-oryx-lib
2+
3+
go 1.4.0

go.sum

Whitespace-only changes.

main.go

-31
This file was deleted.

main_test.go

-34
This file was deleted.

rtmp/example_test.go

+66
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,69 @@
2020
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
package rtmp_test
23+
24+
import (
25+
"fmt"
26+
"math/rand"
27+
"net"
28+
"time"
29+
30+
"github.com/ossrs/go-oryx-lib/rtmp"
31+
)
32+
33+
func ExampleRtmpClientHandshake() {
34+
// Connect to RTMP server via TCP client.
35+
c, err := net.DialTCP("tcp", nil, &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1935})
36+
if err != nil {
37+
panic(err)
38+
}
39+
defer c.Close()
40+
41+
rd := rand.New(rand.NewSource(time.Now().UnixNano()))
42+
hs := rtmp.NewHandshake(rd)
43+
44+
// Client send C0,C1
45+
if err := hs.WriteC0S0(c); err != nil {
46+
panic(err)
47+
}
48+
if err := hs.WriteC1S1(c); err != nil {
49+
panic(err)
50+
}
51+
52+
// Receive S0,S1,S2 from RTMP server.
53+
if _, err = hs.ReadC0S0(c); err != nil {
54+
panic(err)
55+
}
56+
s1, err := hs.ReadC1S1(c)
57+
if err != nil {
58+
panic(err)
59+
}
60+
if _, err = hs.ReadC2S2(c); err != nil {
61+
panic(err)
62+
}
63+
64+
// Client send C2
65+
if err := hs.WriteC2S2(c, s1); err != nil {
66+
panic(err)
67+
}
68+
}
69+
70+
func ExampleRtmpClientConnect() {
71+
// Connect to RTMP server via TCP, then finish the RTMP handshake see ExampleRtmpClientHandshake.
72+
var c *net.TCPConn
73+
74+
// Create a RTMP client.
75+
client := rtmp.NewProtocol(c)
76+
77+
// Send RTMP connect tcURL packet.
78+
connectApp := rtmp.NewConnectAppPacket()
79+
connectApp.CommandObject.Set("tcUrl", amf0.NewString(fmt.Sprintf("rtmp://%v%v", u.Hostname(), app)))
80+
if err = client.WritePacket(connectApp, 1); err != nil {
81+
panic(err)
82+
}
83+
84+
var connectAppRes *rtmp.ConnectAppResPacket
85+
if _, err = client.ExpectPacket(&connectAppRes); err != nil {
86+
panic(err)
87+
}
88+
}

sip/example_test.go

-22
This file was deleted.

sip/sip.go

-23
This file was deleted.

sip/sip_test.go

-22
This file was deleted.

turn/example_test.go

-22
This file was deleted.

turn/turn.go

-23
This file was deleted.

turn/turn_test.go

-22
This file was deleted.

0 commit comments

Comments
 (0)