-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignaling.go
46 lines (35 loc) · 1.19 KB
/
signaling.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package signaling
import (
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/fiber/v2/middleware/recover"
srv "github.com/cloudlink-omega/signaling/pkg/signaling"
"github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2"
)
type SignalingServer struct {
App *fiber.App
Server *srv.Server
}
// New initializes a new SignalingServer with the given allowed origins and
// TURN only setting. The returned SignalingServer object contains the
// underlying structs.Server and a func that can be used to mount the
// WebSocket handler on a fiber.Router.
func New(
// Authorized Origins is a list of origins that are allowed to connect to the signaling server.
Authorized_Origins []string,
// TURN Only is a boolean that determines if the signaling server should only be used for TURN.
TURN_Only bool,
) *SignalingServer {
s := srv.Initialize(Authorized_Origins, TURN_Only)
srv := &SignalingServer{Server: s}
// Initialize app
srv.App = fiber.New()
// Configure routes
srv.App.Use("/", s.Upgrader)
srv.App.Get("/", websocket.New(s.Handler))
// Initialize middleware
srv.App.Use(logger.New())
srv.App.Use(recover.New())
// Return created instance
return srv
}