func (n *Negotiator) StartConnection(opts ConnectionOptions) error {
	peerConnection, err := n.startPeerConnection()
	if err != nil {
		return err
	}
	n.connection.SetPeerConnection(peerConnection)
	if n.connection.GetType() == enums.ConnectionTypeMedia && opts.Stream != nil {
		for _, track := range opts.Stream.GetTracks() {
			peerConnection.AddTrack(track.(webrtc.TrackLocal))
		}
	}
	if opts.Originator {
		if n.connection.GetType() == enums.ConnectionTypeData {
			dataConnection := n.connection.(*DataConnection)
			config := &webrtc.DataChannelInit{
				Ordered: &opts.Reliable,
			}
			dataChannel, err := peerConnection.CreateDataChannel(dataConnection.Label, config)
			if err != nil {
				return err
			}
			dataConnection.Initialize(dataChannel)
		}
		n.makeOffer()
	} else {
		err = n.handleSDP(enums.ServerMessageTypeOffer, opts.SDP)
		if err != nil {
			return err
		}
	}
	return nil
}
StartConnection Returns a PeerConnection object set up correctly (for data, media).
package peer
import (
	"encoding/json"
	"fmt"
	"github.com/muka/peerjs-go/enums"
	"github.com/muka/peerjs-go/models"
	"github.com/pion/webrtc/v3"
	"github.com/sirupsen/logrus"
)
const DefaultBrowser = "peerjs-go"
func newWebrtcAPI() *webrtc.API {
	mediaEngine := new(webrtc.MediaEngine)
	mediaEngine.RegisterDefaultCodecs()
	return webrtc.NewAPI(webrtc.WithMediaEngine(mediaEngine))
}
func NewNegotiator(conn Connection, opts ConnectionOptions) *Negotiator {
	return &Negotiator{
		connection: conn,
		log:        createLogger("negotiator", opts.Debug),
		webrtc:     newWebrtcAPI(),
	}
}
type Negotiator struct {
	connection Connection
	log        *logrus.Entry
	webrtc     *webrtc.API
}