gosepp

package module
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 12 Imported by: 1

README

GoSEPP

A go client for eyeson custom signaling protocol SEPP.

Usage Call Interface

Create a new call by providing an WebRTC SDP, ensure to handle updates within a callback provided to SetSDPUpdateHandler.

package main

import (
	"context"
	"flag"
	"log"
	"time"

	"github.com/eyeson-team/gosepp/v2"
)

// main uses the signaling details of a eyeson meeting to initiate a webrtc
// connection. Find the proper credentials in a (JSON formatted) meeting
// response within the `.signaling.options` path.
func main() {
	authTokenFlag := flag.String("auth-token", "", "JWT token")
	clientIDFlag := flag.String("client-id", "", "Client-ID to use")
	confIDFlag := flag.String("conf-id", "", "Confserver-ID to connect to")
	flag.Parse()

	ci := &gosepp.CallInfo{
		SigEndpoint: gosepp.SeppEndpoint,
		AuthToken:   *authTokenFlag,
		ClientID:    *clientIDFlag,
		ConfID:      *confIDFlag,
	}

	call, err := gosepp.NewCall(ci)
	if err != nil {
		log.Fatalf("failed: %s", err)
	}
	defer call.Close()

	call.SetSDPUpdateHandler(func(sdp gosepp.Sdp) {
		log.Printf("Sdp update with type %s sdp: %s\n", sdp.SdpType, sdp.Sdp)
	})

	call.SetTerminatedHandler(func() {
		log.Println("Call terminated")
	})

	callID, sdp, err := call.Start(context.Background(),
		gosepp.Sdp{SdpType: "offer", Sdp: "dummy-sdp"}, "[Guest] Bla")
	if err != nil {
		log.Fatalf("Call failed with: %s", err)
	}

	log.Printf("Call with id %s and sdp %s", *callID, sdp.Sdp)

	time.Sleep(3 * time.Second)

	log.Println("Terminating call")
	if err = call.Terminate(context.Background()); err != nil {
		log.Printf("Termination failed: %s\n", err)
	}
}

Usage Messaging Interface

The signaling connection provides state updates. The following snippet demonstrates proper wait blocks to handle connection setup.

package main

import (
  "log"
  "time"

	"github.com/eyeson-team/gosepp/v2"
)

func main() {
  clientID := "client-id"
  confID := "conf-id"
  sdp := "dummy-sdp"
  jwtToken := "signed-token"

  sepp, err := gosepp.NewGoSepp(gosepp.SeppEndpoint, jwtToken)
  if err != nil {
    log.Fatalf("failed: %s", err)
  }

	// wait for connected
  select {
  case connected, ok := <-sepp.ConnectStatusCh():
    if !ok || !connected {
      log.Fatalf("Failed to connect")
    }
  case <-time.After(2 * time.Second):
    log.Fatalf("Failed to connect")
  }

  if err := sepp.SendMsg(gosepp.MsgCallStart{
    MsgBase: gosepp.MsgBase{
      Type: gosepp.MsgTypeCallStart,
      From: clientID,
      To:   confID,
    },
    Data: gosepp.MsgCallStartData{
      Sdp:         gosepp.Sdp{SdpType: "offer", Sdp: sdp},
      DisplayName: clientID},
  }); err != nil {
    log.Fatalf("failed to send message:", err)
  }

  // wait for call accepted
  select {
  case msg, ok := <-sepp.RcvCh():
    if !ok {
      log.Fatalf("Failed to receive")
    }
    // dispatch messages
    switch m := msg.(type) {
    case *gosepp.MsgCallAccepted:
      log.Printf("Call Accepted: call-id: ", m.Data.CallID)
    default:
      log.Fatalf("Accept call failed")
    }
  case <-time.After(2 * time.Second):
    log.Fatalf("Waited too long for accept")
  }
}

Development

$ go test

Documentation

Index

Constants

View Source
const (
	MsgTypeCallStart        string = "call_start"
	MsgTypeCallRejected     string = "call_rejected"
	MsgTypeCallAccepted     string = "call_accepted"
	MsgTypeSdpUpdate        string = "sdp_update"
	MsgTypeCallTerminate    string = "call_terminate"
	MsgTypeCallTerminated   string = "call_terminated"
	MsgTypeCallResume       string = "call_resume"
	MsgTypeCallResumed      string = "call_resumed"
	MsgTypeChat             string = "chat"
	MsgTypeSetPresenter     string = "set_presenter"
	MsgTypeDesktopstreaming string = "desktopstreaming"
	MsgTypeMuteVideo        string = "mute_video"
	MsgTypeSourceUpdate     string = "source_update"
	MsgTypeMemberlist       string = "memberlist"
	MsgTypeRecording        string = "recording"
)

Messages types

View Source
const SeppEndpoint string = "wss://sig.eyeson.com/call"

Variables

SeppMsgTypes defines a mapping of message types and an interface function which create a messages adhering to the MsgInterface.

Functions

This section is empty.

Types

type Call

type Call struct {
	// contains filtered or unexported fields
}

Call is an abstraction of the gosepp messaging based interface.

func NewCall

func NewCall(callInfo CallInfoInterface) (*Call, error)

NewCall initializes an instant of a call.

func (*Call) Close

func (c *Call) Close()

Close this call. Shuts down connection to the signaling service, but does _not_ terminate the call.

func (*Call) SetMemberlistHandler added in v2.3.0

func (c *Call) SetMemberlistHandler(handler func(MsgMemberlistData))

SetMemberlistHandler set handler to be called on change of the memberlist.

func (*Call) SetSDPUpdateHandler

func (c *Call) SetSDPUpdateHandler(handler func(Sdp))

SetSDPUpdateHandler sets the sdp-update handler which is called if the remote end is sending an updated sdp. Must be set-up before start.

func (*Call) SetSourceUpdateHandler added in v2.3.0

func (c *Call) SetSourceUpdateHandler(handler func(MsgSourceUpdateData))

SetSourceUpdateHandler set handler to be called if the podium layout changes.

func (*Call) SetTerminatedHandler

func (c *Call) SetTerminatedHandler(handler func())

SetTerminatedHandler sets the termination handler which is called when the call is terminated. Must be set-up before start.

func (*Call) Start

func (c *Call) Start(ctx context.Context, sdp Sdp, displayname string) (*CallID, *Sdp, error)

Start the call. On success the call-id and sdp is returned, else an error.

func (*Call) Terminate

func (c *Call) Terminate(ctx context.Context) error

Terminate the active call.

func (*Call) TurnOffVideo added in v2.3.0

func (c *Call) TurnOffVideo(ctx context.Context, off bool) error

TurnOffVideo mutes or unmute video

func (*Call) UpdateSDP

func (c *Call) UpdateSDP(ctx context.Context, sdp Sdp) error

UpdateSDP sends and sdp update to the remote end.

type CallID

type CallID string

CallID custom callID type

type CallInfo

type CallInfo struct {
	SigEndpoint string
	AuthToken   string
	ClientID    string
	ConfID      string
}

CallInfo is the default implementation of the CallInfoInterface.

func (*CallInfo) GetAuthToken

func (i *CallInfo) GetAuthToken() string

GetAuthToken returns the jwt-auth token used as bearer authorization token.

func (*CallInfo) GetClientID

func (i *CallInfo) GetClientID() string

GetClientID returns the clientID which is the initiator of this call.

func (*CallInfo) GetConfID

func (i *CallInfo) GetConfID() string

GetConfID returns the confID which is the destination of this call.

func (*CallInfo) GetSigEndpoint

func (i *CallInfo) GetSigEndpoint() string

GetSigEndpoint returns the sip-sepp endpoint.

type CallInfoInterface

type CallInfoInterface interface {
	GetSigEndpoint() string
	GetAuthToken() string
	GetClientID() string
	GetConfID() string
}

CallInfoInterface defines a configuration interface, to which the init struct of NewCall must comply.

type Dimension added in v2.2.0

type Dimension struct {
	Width  int `json:"w"`
	Height int `json:"h"`
	X      int `json:"x"`
	Y      int `json:"y"`
}

type GoSepp

type GoSepp struct {
	// contains filtered or unexported fields
}

GoSepp Confserver signaling.

func NewGoSepp

func NewGoSepp(baseURL, authToken string) (*GoSepp, error)

NewGoSepp returns a new GoSepp client.

func NewGoSeppCustomCerts

func NewGoSeppCustomCerts(baseURL string, certFile, keyFile, caFile string,
	insecure bool, useSystemCAPool bool, authToken string) (*GoSepp, error)

NewGoSeppCustomCerts returns a new GoSepp client using custom certs.

func (*GoSepp) ConnectStatusCh

func (rtm *GoSepp) ConnectStatusCh() chan bool

ConnectStatusCh allow to monitor the websockets connection status.

func (*GoSepp) RcvCh

func (rtm *GoSepp) RcvCh() chan MsgInterface

RcvCh get the channel where message adhering to the ConfMsgInterface can be retrieved.

func (*GoSepp) SendMsg

func (rtm *GoSepp) SendMsg(msg interface{}) error

SendMsg sends a message over the underlying websocket. In order to support concurrent writes, messages are send through an internal channel. Therefore messages are not sent immediately down the wire.

func (*GoSepp) Stop

func (rtm *GoSepp) Stop()

Stop the internal messaging loop.

type Media added in v2.2.0

type Media struct {
	MediaID string `json:"mid"`
	PlayID  string `json:"playid"`
}

type Member added in v2.2.0

type Member struct {
	ClientID string  `json:"cid"`
	Platform *string `json:"p,omitempty"`
}

type MsgBase

type MsgBase struct {
	Type  string `json:"type"`
	MsgID string `json:"msg_id"`
	From  string `json:"from"`
	To    string `json:"to"`
}

MsgBase base struct for all conf messages.

func (*MsgBase) GetFrom

func (msg *MsgBase) GetFrom() string

GetFrom retrieves the from header.

func (*MsgBase) GetMsgID

func (msg *MsgBase) GetMsgID() string

GetMsgID get the message-id of a conf message.

func (*MsgBase) GetTo

func (msg *MsgBase) GetTo() string

GetTo retrieves the message to header.

func (*MsgBase) GetType

func (msg *MsgBase) GetType() string

GetType get the message-type of a conf message.

func (*MsgBase) SetFrom

func (msg *MsgBase) SetFrom(from string)

SetFrom allows to set the from header of that message.

func (*MsgBase) SetTo

func (msg *MsgBase) SetTo(to string)

SetTo allows to set the message base to header.

type MsgCallAccepted

type MsgCallAccepted struct {
	MsgBase
	Data MsgCallAcceptedData `json:"data"`
}

MsgCallAccepted message

type MsgCallAcceptedData

type MsgCallAcceptedData struct {
	CallID string `json:"call_id"`
	Sdp    Sdp    `json:"sdp"`
}

MsgCallAcceptedData data

type MsgCallRejected

type MsgCallRejected struct {
	MsgBase
	Data MsgCallRejectedData `json:"data"`
}

MsgCallRejected message

type MsgCallRejectedData

type MsgCallRejectedData struct {
	RejectCode int `json:"reject_code"`
}

MsgCallRejectedData data

type MsgCallResume added in v2.1.0

type MsgCallResume struct {
	MsgBase
	Data MsgCallResumeData `json:"data"`
}

MsgCallResume message

type MsgCallResumeData added in v2.1.0

type MsgCallResumeData struct {
	Sdp    Sdp    `json:"sdp"`
	CallID string `json:"call_id"`
}

MsgCallResumeData carries data for the call_resume message.

type MsgCallResumed added in v2.1.0

type MsgCallResumed struct {
	MsgBase
	Data MsgCallResumedData `json:"data"`
}

MsgCallResumed message

type MsgCallResumedData added in v2.1.0

type MsgCallResumedData struct {
	CallID string `json:"call_id"`
	Sdp    Sdp    `json:"sdp"`
}

MsgCallResumedData data

type MsgCallStart

type MsgCallStart struct {
	MsgBase
	Data MsgCallStartData `json:"data"`
}

MsgCallStart message

type MsgCallStartData

type MsgCallStartData struct {
	Sdp         Sdp    `json:"sdp"`
	DisplayName string `json:"display_name"`
}

MsgCallStartData carries data of for the call_start message.

type MsgCallTerminate

type MsgCallTerminate struct {
	MsgBase
	Data MsgCallTerminateData `json:"data"`
}

MsgCallTerminate message

type MsgCallTerminateData

type MsgCallTerminateData struct {
	CallID   string `json:"call_id"`
	TermCode int    `json:"term_code"`
}

MsgCallTerminateData data

type MsgCallTerminated

type MsgCallTerminated struct {
	MsgBase
	Data MsgCallTerminatedData `json:"data"`
}

MsgCallTerminated message

type MsgCallTerminatedData

type MsgCallTerminatedData struct {
	CallID   string `json:"call_id"`
	TermCode int    `json:"term_code"`
}

MsgCallTerminatedData data

type MsgChat added in v2.2.0

type MsgChat struct {
	MsgBase
	Data MsgChatData `json:"data"`
}

type MsgChatData added in v2.2.0

type MsgChatData struct {
	CallID    string `json:"call_id"`
	ClientID  string `json:"cid"`
	Content   string `json:"content"`
	ID        string `json:"id"`
	Timestamp string `json:"ts"`
}

type MsgDesktopstreaming added in v2.2.0

type MsgDesktopstreaming struct {
	MsgBase
	Data MsgDesktopstreamingData `json:"data"`
}

type MsgDesktopstreamingData added in v2.2.0

type MsgDesktopstreamingData struct {
	CallID   string `json:"call_id"`
	On       bool   `json:"on"`
	ClientID string `json:"cid"`
}

type MsgInterface

type MsgInterface interface {
	GetMsgID() string
	GetType() string
	GetFrom() string
	GetTo() string
	SetFrom(string)
	SetTo(string)
}

MsgInterface define a messages which allows to get and modify the base-message. This helps to dispatch matches without having to deserialize the whole message.

type MsgMemberlist added in v2.2.0

type MsgMemberlist struct {
	MsgBase
	Data MsgMemberlistData `json:"data"`
}

type MsgMemberlistData added in v2.2.0

type MsgMemberlistData struct {
	CallID string   `json:"call_id"`
	Count  int      `json:"count"`
	Add    []Member `json:"add"`
	Del    []string `json:"del"`
	Media  []Media  `json:"media"`
}

type MsgMuteVideo added in v2.2.0

type MsgMuteVideo struct {
	MsgBase
	Data MsgMuteVideoData `json:"data"`
}

type MsgMuteVideoData added in v2.2.0

type MsgMuteVideoData struct {
	CallID   string `json:"call_id"`
	On       bool   `json:"on"`
	ClientID string `json:"cid"`
}

type MsgRecording added in v2.2.0

type MsgRecording struct {
	MsgBase
	Data MsgRecordingData `json:"data"`
}

type MsgRecordingData added in v2.2.0

type MsgRecordingData struct {
	CallID  string `json:"call_id"`
	Active  bool   `json:"active"`
	Enabled bool   `json:"enabled"`
}

type MsgSdpUpdate

type MsgSdpUpdate struct {
	MsgBase
	Data MsgSdpUpdateData `json:"data"`
}

MsgSdpUpdate message

type MsgSdpUpdateData

type MsgSdpUpdateData struct {
	CallID string `json:"call_id"`
	Sdp    Sdp    `json:"sdp"`
}

MsgSdpUpdateData data

type MsgSetPresenter added in v2.2.0

type MsgSetPresenter struct {
	MsgBase
	Data MsgSetPresenterData `json:"data"`
}

type MsgSetPresenterData added in v2.2.0

type MsgSetPresenterData struct {
	CallID   string `json:"call_id"`
	On       bool   `json:"on"`
	ClientID string `json:"cid"`
}

type MsgSourceUpdate added in v2.2.0

type MsgSourceUpdate struct {
	MsgBase
	Data MsgSourceUpdateData `json:"data"`
}

type MsgSourceUpdateData added in v2.2.0

type MsgSourceUpdateData struct {
	CallID             string      `json:"call_id"`
	AudioSources       []int       `json:"asrc"`
	VideoSources       []int       `json:"vsrc"`
	Broadcast          *bool       `json:"bcast,omitempty"`
	Dimensions         []Dimension `json:"dims"`
	Layout             int         `json:"l"`
	Sources            []string    `json:"src"`
	TextOverlay        *bool       `json:"tovl,omitempty"`
	PresenterSrc       *int        `json:"psrc,omitempty"`
	DesktopstreamerSrc *int        `json:"dsrc,omitempty"`
}

type Sdp

type Sdp struct {
	SdpType string `json:"type"`
	Sdp     string `json:"sdp"`
}

Sdp combines the actual sdp with an type. The type can be either "offer" or "answer".

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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