38 lines
960 B
Go
38 lines
960 B
Go
package boot
|
|
|
|
import (
|
|
"g365sfu/logger"
|
|
"g365sfu/sfu"
|
|
"g365sfu/socket"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/joho/godotenv"
|
|
"github.com/pion/webrtc/v4"
|
|
)
|
|
|
|
func Bootstrap() {
|
|
godotenv.Load()
|
|
sfu.InitWebRTCEngines()
|
|
if os.Getenv("SECRET") == "" {
|
|
logger.LogErrorMessage("server failed to start because not set secret key in .env variables")
|
|
return
|
|
}
|
|
http.HandleFunc("/", socket.HandleWebSocket)
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "1001"
|
|
}
|
|
sfu.OnLocalICECandidate = OnLocalICECandidate
|
|
logger.LogInfoMessage("server started at x.x.x.x:" + port)
|
|
http.ListenAndServe(":"+port, nil)
|
|
}
|
|
|
|
func OnLocalICECandidate(roomID, peerID string, candidate webrtc.ICECandidateInit) {
|
|
logger.LogInfoMessage("new local ICE candidate for peer " + peerID + " in room " + roomID)
|
|
}
|
|
|
|
func OnServerOffer(roomID string, peerID string, offer webrtc.SessionDescription) {
|
|
logger.LogInfoMessage("new server offer for peer " + peerID + " in room " + roomID)
|
|
}
|