ws

package
v1.9.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 12 Imported by: 0

README

WebSocket

Endpoint: /api/ws

Query parameters:

  • src (required) - Stream name
WebRTC

Request SDP:

{"type":"webrtc/offer","value":"v=0\r\n..."}

Response SDP:

{"type":"webrtc/answer","value":"v=0\r\n..."}

Request/response candidate:

  • empty value also allowed and optional
{"type":"webrtc/candidate","value":"candidate:3277516026 1 udp 2130706431 192.168.1.123 54321 typ host"}
MSE

Request:

  • codecs list optional
{"type":"mse","value":"avc1.640029,avc1.64002A,avc1.640033,hvc1.1.6.L153.B0,mp4a.40.2,mp4a.40.5,flac,opus"}

Response:

{"type":"mse","value":"video/mp4; codecs=\"avc1.64001F,mp4a.40.2\""}
HLS

Request:

{"type":"hls","value":"avc1.640029,avc1.64002A,avc1.640033,hvc1.1.6.L153.B0,mp4a.40.2,mp4a.40.5,flac"}

Response:

  • you MUST rewrite full HTTP path to http://192.168.1.123:1984/api/hls/playlist.m3u8
{"type":"hls","value":"#EXTM3U\n#EXT-X-STREAM-INF:BANDWIDTH=1000000,CODECS=\"avc1.64001F,mp4a.40.2\"\nhls/playlist.m3u8?id=DvmHdd9w"}
MJPEG

Request/response:

{"type":"mjpeg"}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleFunc

func HandleFunc(msgType string, handler WSHandler)

func Init

func Init()

Types

type Message

type Message struct {
	Type  string `json:"type"`
	Value any    `json:"value,omitempty"`
}

Message - struct for data exchange in Web API

func (*Message) String

func (m *Message) String() (value string)

func (*Message) Unmarshal added in v1.9.5

func (m *Message) Unmarshal(v any) error

type Transport

type Transport struct {
	Request *http.Request
	// contains filtered or unexported fields
}

func (*Transport) Close

func (t *Transport) Close()

func (*Transport) OnChange

func (t *Transport) OnChange(f func())

func (*Transport) OnClose

func (t *Transport) OnClose(f func())

func (*Transport) OnWrite

func (t *Transport) OnWrite(f func(msg any) error)

func (*Transport) WithContext

func (t *Transport) WithContext(f func(ctx map[any]any))

WithContext - run function with Context variable

func (*Transport) Write

func (t *Transport) Write(msg any)

func (*Transport) Writer

func (t *Transport) Writer() io.Writer

type WSHandler

type WSHandler func(tr *Transport, msg *Message) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL