whepclient

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2025 License: Apache-2.0 Imports: 8 Imported by: 1

README

WHEP Client

A simple WHEP client.

Example

package main

import (
	"encoding/json"
	"fmt"
	"net/http"
	"os"

	whepclient "github.com/elixir-webrtc/whep-client"
	"github.com/pion/webrtc/v4"
)

func main() {
package main

import (
	"fmt"
	"os"

	whepclient "github.com/elixir-webrtc/whep-client"
	"github.com/pion/webrtc/v4"
)

func main() {
	url := os.Args[1]

	client, err := whepclient.New(url, webrtc.Configuration{})
	if err != nil {
		panic(err)
	}

	client.Pc.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) {
		fmt.Printf("Connection State has changed %s \n", connectionState.String())
	})

	client.Pc.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
		fmt.Printf("New track: %s\n", track.Codec().MimeType)
		for {
			_, _, err := track.ReadRTP()
			if err != nil {
				panic(err)
			}
		}
	})

	err = client.Connect()
	if err != nil {
		panic(err)
	}

	// block forever
	select {}
}

Then call:

go run main.go https://yourWhepEndpointURL

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidURL         = errors.New("Invalid server URL")
	ErrFailedToConnect    = errors.New("Failed to connect")
	ErrNoLocationHeader   = errors.New("No location header in the response")
	ErrFailedToDisconnect = errors.New("Failed to remove server resource")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Pc *webrtc.PeerConnection
	// contains filtered or unexported fields
}

func New

func New(urlString string, pcConfig webrtc.Configuration) (*Client, error)

func (*Client) Connect

func (client *Client) Connect() error

func (*Client) Disconnect

func (client *Client) Disconnect() error

Jump to

Keyboard shortcuts

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