mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
01. Support GB config as StreamCaster. 02. Support disable GB by --gb28181=off. 03. Add utests for SIP examples. 04. Wireshark plugin to decode TCP/9000 as rtp.rfc4571 05. Support MPEGPS program stream codec. 06. Add utest for PS stream codec. 07. Decode MPEGPS packet stream. 08. Carry RTP and PS packet as helper in PS message. 09. Support recover from error mode. 10. Support process by a pack of PS/TS messages. 11. Add statistic for recovered and msgs dropped. 12. Recover from err position fastly. 13. Define state machine for GB session. 14. Bind context to GB session. 15. Re-invite when media disconnected. 16. Update GitHub actions with GB28181. 17. Support parse CANDIDATE by env or pip. 18. Support mux GB28181 to RTMP. 19. Support regression test by srs-bench.
81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
/*
|
|
Package ws implements a client and server for the WebSocket protocol as
|
|
specified in RFC 6455.
|
|
|
|
The main purpose of this package is to provide simple low-level API for
|
|
efficient work with protocol.
|
|
|
|
Overview.
|
|
|
|
Upgrade to WebSocket (or WebSocket handshake) can be done in two ways.
|
|
|
|
The first way is to use `net/http` server:
|
|
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
conn, _, _, err := ws.UpgradeHTTP(r, w)
|
|
})
|
|
|
|
The second and much more efficient way is so-called "zero-copy upgrade". It
|
|
avoids redundant allocations and copying of not used headers or other request
|
|
data. User decides by himself which data should be copied.
|
|
|
|
ln, err := net.Listen("tcp", ":8080")
|
|
if err != nil {
|
|
// handle error
|
|
}
|
|
|
|
conn, err := ln.Accept()
|
|
if err != nil {
|
|
// handle error
|
|
}
|
|
|
|
handshake, err := ws.Upgrade(conn)
|
|
if err != nil {
|
|
// handle error
|
|
}
|
|
|
|
For customization details see `ws.Upgrader` documentation.
|
|
|
|
After WebSocket handshake you can work with connection in multiple ways.
|
|
That is, `ws` does not force the only one way of how to work with WebSocket:
|
|
|
|
header, err := ws.ReadHeader(conn)
|
|
if err != nil {
|
|
// handle err
|
|
}
|
|
|
|
buf := make([]byte, header.Length)
|
|
_, err := io.ReadFull(conn, buf)
|
|
if err != nil {
|
|
// handle err
|
|
}
|
|
|
|
resp := ws.NewBinaryFrame([]byte("hello, world!"))
|
|
if err := ws.WriteFrame(conn, frame); err != nil {
|
|
// handle err
|
|
}
|
|
|
|
As you can see, it stream friendly:
|
|
|
|
const N = 42
|
|
|
|
ws.WriteHeader(ws.Header{
|
|
Fin: true,
|
|
Length: N,
|
|
OpCode: ws.OpBinary,
|
|
})
|
|
|
|
io.CopyN(conn, rand.Reader, N)
|
|
|
|
Or:
|
|
|
|
header, err := ws.ReadHeader(conn)
|
|
if err != nil {
|
|
// handle err
|
|
}
|
|
|
|
io.CopyN(ioutil.Discard, conn, header.Length)
|
|
|
|
For more info see the documentation.
|
|
*/
|
|
package ws
|