mirror of
https://github.com/openlibrecommunity/olcrtc.git
synced 2026-06-04 19:39:45 +00:00
style(server,mobile): format function signatures and add provider name
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -19,6 +20,11 @@ type RoomInfo struct {
|
||||
ConnectorURL string `json:"connectorUrl"`
|
||||
}
|
||||
|
||||
var (
|
||||
errCreateRoomFailed = errors.New("create room failed")
|
||||
errPreconnectFailed = errors.New("preconnect failed")
|
||||
)
|
||||
|
||||
func createRoom(ctx context.Context) (*RoomInfo, error) {
|
||||
clientID := uuid.New().String()
|
||||
headers := map[string]string{
|
||||
@@ -60,10 +66,10 @@ func createRoom(ctx context.Context) (*RoomInfo, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("do create request: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() { _ = resp.Body.Close() }()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("create room failed: status %d", resp.StatusCode)
|
||||
return nil, fmt.Errorf("%w: status %d", errCreateRoomFailed, resp.StatusCode)
|
||||
}
|
||||
|
||||
var createResp struct {
|
||||
@@ -111,10 +117,10 @@ func createRoom(ctx context.Context) (*RoomInfo, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("do preconnect request: %w", err)
|
||||
}
|
||||
defer preResp.Body.Close()
|
||||
defer func() { _ = preResp.Body.Close() }()
|
||||
|
||||
if preResp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("preconnect failed: status %d", preResp.StatusCode)
|
||||
return nil, fmt.Errorf("%w: status %d", errPreconnectFailed, preResp.StatusCode)
|
||||
}
|
||||
|
||||
var preconnectResp struct {
|
||||
@@ -178,10 +184,10 @@ func joinRoom(ctx context.Context, roomID, password string) (*RoomInfo, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("do preconnect request: %w", err)
|
||||
}
|
||||
defer preResp.Body.Close()
|
||||
defer func() { _ = preResp.Body.Close() }()
|
||||
|
||||
if preResp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("preconnect failed: status %d", preResp.StatusCode)
|
||||
return nil, fmt.Errorf("%w: status %d", errPreconnectFailed, preResp.StatusCode)
|
||||
}
|
||||
|
||||
var preconnectResp struct {
|
||||
|
||||
@@ -41,11 +41,11 @@ type Peer struct {
|
||||
sendQueueClosed atomic.Bool
|
||||
onEnded func(string)
|
||||
sessionCloseCh chan struct{}
|
||||
sessionMu sync.Mutex
|
||||
wg sync.WaitGroup
|
||||
groupID string
|
||||
}
|
||||
|
||||
// NewPeer creates a new Jazz provider peer.
|
||||
func NewPeer(ctx context.Context, roomID, name string, onData func([]byte)) (*Peer, error) {
|
||||
var roomInfo *RoomInfo
|
||||
var err error
|
||||
|
||||
@@ -184,7 +184,13 @@ func (s *Server) setupMux() {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) addPeer(ctx context.Context, providerName, roomURL string, peerID int, cancel context.CancelFunc) error {
|
||||
func (s *Server) addPeer(
|
||||
ctx context.Context,
|
||||
providerName,
|
||||
roomURL string,
|
||||
peerID int,
|
||||
cancel context.CancelFunc,
|
||||
) error {
|
||||
peer, err := provider.New(ctx, providerName, provider.Config{
|
||||
RoomURL: roomURL,
|
||||
Name: names.Generate(),
|
||||
|
||||
@@ -108,6 +108,7 @@ func Start(roomID, keyHex string, socksPort int, socksUser, socksPass string) er
|
||||
|
||||
err := client.RunWithReady(
|
||||
ctx,
|
||||
"telemost",
|
||||
roomURL,
|
||||
keyHex,
|
||||
socksPort,
|
||||
|
||||
Reference in New Issue
Block a user