Compare commits

..

No commits in common. "df92d0ec0a07ace6e0e5e417da60050c092577bb" and "0984f1b284bac56a55ffbf6f7838c135f01ab79a" have entirely different histories.

5 changed files with 17 additions and 44 deletions

1
.gitignore vendored
View File

@ -1,3 +1,2 @@
.idea
goldgorilla
ice.servers.json

14
app.go
View File

@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/pion/webrtc/v3"
"io"
"net/http"
"os"
@ -26,28 +25,17 @@ type App struct {
func (a *App) Init(srcListenAddr string, svcAddr string, logjamBaseUrl string, targetRoom string) {
println("initializing ..")
a.src = srcListenAddr
var iceServers []webrtc.ICEServer
iceconfjson, err := os.ReadFile("./ice.servers.json")
if err != nil {
println("[E] error reading ice.servers.json: " + err.Error())
} else {
err = json.Unmarshal(iceconfjson, &iceServers)
if err != nil {
panic("[E] can't parse ice.servers.json: " + err.Error())
}
}
a.conf = &models.ConfigModel{
LogjamBaseUrl: logjamBaseUrl + "/auxiliary-node",
TargetRoom: targetRoom,
ServiceAddress: svcAddr,
ICEServers: iceServers,
}
roomRepo := repositories.NewRoomRepository(a.conf)
a.router = &routers.Router{}
respHelper := controllers.NewResponseHelper()
roomCtrl := controllers.NewRoomController(respHelper, roomRepo, a.conf)
err = a.router.RegisterRoutes(roomCtrl)
err := a.router.RegisterRoutes(roomCtrl)
panicIfErr(err)
{

View File

@ -1,7 +0,0 @@
[
{
"urls": ["turn:turn.example.com:4499"],
"username": "user",
"credential": "1234"
}
]

View File

@ -1,10 +1,7 @@
package models
import "github.com/pion/webrtc/v3"
type ConfigModel struct {
ServiceAddress string `json:"serviceAddress"`
LogjamBaseUrl string `json:"logjamBaseUrl"`
TargetRoom string `json:"targetRoom"`
ICEServers []webrtc.ICEServer `json:"iceServers"`
ServiceAddress string `json:"serviceAddress"`
LogjamBaseUrl string `json:"logjamBaseUrl"`
TargetRoom string `json:"targetRoom"`
}

View File

@ -109,10 +109,10 @@ func (r *RoomRepository) CreatePeer(roomId string, id uint64, canPublish bool, i
room := r.Rooms[roomId]
r.Unlock()
room.Lock()
defer room.Unlock()
peerConn, err := webrtc.NewPeerConnection(webrtc.Configuration{
ICEServers: r.conf.ICEServers,
})
peerConn, err := webrtc.NewPeerConnection(webrtc.Configuration{})
if err != nil {
return models.NewError("can't create peer connection", 500, models.MessageResponse{Message: err.Error()})
}
@ -130,8 +130,6 @@ func (r *RoomRepository) CreatePeer(roomId string, id uint64, canPublish bool, i
println("[PC] negotiating with peer", id)
r.offerPeer(peerConn,roomId,id)
})*/
room.Lock()
defer room.Unlock()
room.Peers[id] = &Peer{
ID: id,
Conn: peerConn,
@ -177,8 +175,8 @@ func (r *RoomRepository) onPeerConnectionStateChange(roomId string, id uint64, n
r.Unlock()
return
}
room := r.Rooms[roomId]
r.Unlock()
room := r.Rooms[roomId]
room.Lock()
defer room.Unlock()
@ -331,20 +329,20 @@ func (r *RoomRepository) SetPeerAnswer(roomId string, id uint64, answer webrtc.S
r.Unlock()
return models.NewError("room doesn't exists", 403, map[string]any{"roomId": roomId})
}
room := r.Rooms[roomId]
r.Unlock()
room := r.Rooms[roomId]
room.Lock()
defer room.Unlock()
if !r.doesPeerExists(roomId, id) {
room.Unlock()
return models.NewError("no such a peer with this id in this room", 403, map[string]any{"roomId": roomId, "peerId": id})
}
peer := room.Peers[id]
room.Unlock()
err := peer.Conn.SetRemoteDescription(answer)
err := room.Peers[id].Conn.SetRemoteDescription(answer)
if err != nil {
return models.NewError(err.Error(), 500, models.MessageResponse{Message: err.Error()})
}
peer.HandshakeLock.Unlock()
room.Peers[id].HandshakeLock.Unlock()
return nil
}
func (r *RoomRepository) SetPeerOffer(roomId string, id uint64, offer webrtc.SessionDescription) (sdpAnswer *webrtc.SessionDescription, err error) {
@ -410,17 +408,15 @@ func (r *RoomRepository) ClosePeer(roomId string, id uint64) error {
r.Unlock()
return models.NewError("room doesn't exists", 403, map[string]any{"roomId": roomId})
}
room := r.Rooms[roomId]
r.Unlock()
room := r.Rooms[roomId]
room.Lock()
peer := room.Peers[id]
defer room.Unlock()
if !r.doesPeerExists(roomId, id) {
room.Unlock()
return models.NewError("no such a peer with this id in this room", 403, map[string]any{"roomId": roomId, "peerId": id})
}
room.Unlock()
return peer.Conn.Close()
return room.Peers[id].Conn.Close()
}
func (r *RoomRepository) ResetRoom(roomId string) error {