mirror of
https://github.com/livekit/livekit.git
synced 2026-03-29 09:19:53 +00:00
initial commit
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -10,6 +10,8 @@
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
livekit-server
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
.idea/
|
||||
20
main.go
Normal file
20
main.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/node"
|
||||
)
|
||||
|
||||
func main() {
|
||||
n, err := node.NewLocalNode()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := n.DiscoverNetworkInfo(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("my IP", n.IP)
|
||||
}
|
||||
2
pkg/data/redis.go
Normal file
2
pkg/data/redis.go
Normal file
@@ -0,0 +1,2 @@
|
||||
package data
|
||||
|
||||
66
pkg/node/node.go
Normal file
66
pkg/node/node.go
Normal file
@@ -0,0 +1,66 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/pion/stun"
|
||||
)
|
||||
|
||||
const (
|
||||
googleStunServer = "stun.l.google.com:19302"
|
||||
)
|
||||
|
||||
type Node struct {
|
||||
ID string
|
||||
IP string
|
||||
Stats NodeStats
|
||||
}
|
||||
|
||||
type NodeStats struct {
|
||||
NumRooms int32
|
||||
NumClients int32
|
||||
NumVideoChannels int32
|
||||
NumAudioChannels int32
|
||||
BytesPerMin int64
|
||||
}
|
||||
|
||||
func NewLocalNode() (*Node, error) {
|
||||
id, err := uuid.NewRandom()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Node{
|
||||
ID: id.String(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (n *Node) DiscoverNetworkInfo() error {
|
||||
c, err := stun.Dial("udp", googleStunServer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
message, err := stun.Build(stun.TransactionID, stun.BindingRequest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var stunErr error
|
||||
err = c.Do(message, func(res stun.Event) {
|
||||
if res.Error != nil {
|
||||
stunErr = res.Error
|
||||
return
|
||||
}
|
||||
|
||||
var xorAddr stun.XORMappedAddress
|
||||
if err := xorAddr.GetFrom(res.Message); err != nil {
|
||||
stunErr = err
|
||||
return
|
||||
}
|
||||
n.IP = xorAddr.IP.String()
|
||||
})
|
||||
|
||||
if stunErr != nil {
|
||||
err = stunErr
|
||||
}
|
||||
return err
|
||||
}
|
||||
17
proto/model.proto
Normal file
17
proto/model.proto
Normal file
@@ -0,0 +1,17 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package livekit;
|
||||
|
||||
// internal types, declaring in proto to get serialization for free
|
||||
|
||||
message Node {
|
||||
string id = 1;
|
||||
string ip = 2;
|
||||
int32 port = 3;
|
||||
NodeStats stats = 4;
|
||||
}
|
||||
|
||||
message NodeStats {
|
||||
int32 num_rooms = 1;
|
||||
int32 num_clients = 2;
|
||||
}
|
||||
68
proto/service.proto
Normal file
68
proto/service.proto
Normal file
@@ -0,0 +1,68 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package livekit;
|
||||
|
||||
// Room service that can be performed on any node
|
||||
service RoomService {
|
||||
// TODO: how do we secure room service?
|
||||
// should be accessible to only internal servers, not external
|
||||
rpc CreateRoom(CreateRoomRequest) returns (CreateRoomResponse);
|
||||
rpc JoinRoom(JoinRoomRequest) returns (JoinRoomResponse);
|
||||
rpc DeleteRoom(DeleteRoomRequest) returns (DeleteRoomResponse);
|
||||
}
|
||||
|
||||
message CreateRoomRequest {
|
||||
|
||||
}
|
||||
|
||||
message CreateRoomResponse {
|
||||
|
||||
}
|
||||
|
||||
message JoinRoomRequest {
|
||||
string room = 1;
|
||||
string client_id = 2;
|
||||
}
|
||||
|
||||
message JoinRoomResponse {
|
||||
string node_ip = 1;
|
||||
string node_port = 2;
|
||||
}
|
||||
|
||||
message DeleteRoomRequest {
|
||||
string room = 1;
|
||||
}
|
||||
|
||||
message DeleteRoomResponse {
|
||||
}
|
||||
|
||||
// RTC methods performed on target node
|
||||
service RTCService {
|
||||
rpc Offer(SessionDescription) returns (SessionDescription);
|
||||
|
||||
// push channel to allow server to push commands to client
|
||||
rpc Signal(SignalRequest) returns (stream SignalResponse);
|
||||
rpc Trickle(TrickleRequest) returns (TrickleResponse);
|
||||
}
|
||||
|
||||
message SignalRequest {
|
||||
}
|
||||
|
||||
message SignalResponse {
|
||||
oneof payload {
|
||||
SessionDescription desc = 1;
|
||||
TrickleRequest trickle = 2;
|
||||
}
|
||||
}
|
||||
|
||||
message TrickleRequest {
|
||||
string candidate = 1;
|
||||
}
|
||||
|
||||
message TrickleResponse {
|
||||
}
|
||||
|
||||
message SessionDescription {
|
||||
string type = 1; // "answer" | "offer" | "pranswer" | "rollback"
|
||||
bytes sdp = 2;
|
||||
}
|
||||
Reference in New Issue
Block a user