LiveKit部署

LiveKit私有化部署

  1. livekit简介
    LiveKit 是一个实时平台,使开发人员能够在他们的应用程序中构建视频、语音和数据功能。 它基于 WebRTC 构建,支持广泛的前端和后端平台。
  2. 部署
    参考官方文档: https://docs.livekit.io/home/self-hosting/local/
  3. 下载安装物料:
shell 复制代码
curl -sSL https://get.livekit.io | bash
  1. 编写配置文件:livekit.yaml
python 复制代码
#  服务端口
port: 7880
rtc:
    udp_port: 7882
    tcp_port: 7881
    # rtc 是使用内网 所以 用false
    use_external_ip: false
    # node_ip 部署服务器ip
    node_ip: 10.50.103.1
    enable_loopback_candidate: false
keys:
	# apiKey: secret 
    2yJimTMFeF9h15PHEv: Mvi9ZgqGJ3LqwEAcTVvWse3conEyQt92FEKTVERzd
logging:
    json: false
    level: info

redis:
  # reids 地址
  address: 10.50.103.2:6379
  db: 0
  1. 执行启动命令
python 复制代码
livekit-server --config ./livekit.yaml --node-ip=10.50.103.1 --bind 0.0.0.0
  1. 验证部署情况
    浏览器输入:http://10.50.103.1:7880 地址,返回OK即代表成功。
  2. go生成token
安装 Livekit 服务器 SDK
go 复制代码
 go get github.com/livekit/server-sdk-go
密钥和配置

在 API 密钥和密钥处创建一个新文件,并使用 API 密钥和密钥创建新文件:development.env

go 复制代码
export LIVEKIT_API_KEY=<your API Key>
export LIVEKIT_API_SECRET=<your API Secret>
创建一个返回令牌的端点
go 复制代码
// server.go
import (
	"http"
	"log"
	"time"

	lksdk "github.com/livekit/server-sdk-go"
	"github.com/livekit/protocol/auth"
)

func getJoinToken(room, identity string) string {
	config = readFile(config)
	at := auth.NewAccessToken(os.GetEnv("LIVEKIT_API_KEY"), os.GetEnv("LIVEKIT_API_SECRET"))
	grant := &auth.VideoGrant{
		RoomJoin: true,
		Room:     room,
	}
	at.AddGrant(grant).
		SetIdentity(identity).
		SetValidFor(time.Hour)

	return at.ToJWT()
}

func main() {
	http.HandleFunc("/getToken", func(w http.ResponseWriter, r *http.Request) {
		w.write(getJoinToken("my-room", "identity"))
	})
	log.Fatal(http.ListenAndServe(":8080", nil))
}
加载环境变量并运行服务器:
go 复制代码
$ source development.env
$ go run server.go
相关推荐
程序员爱钓鱼15 小时前
GoHTML解析利器:github.com/PuerkitoBio/goquery实战指南
后端·google·go
我叫黑大帅16 小时前
Go中的interface的两大用法
后端·面试·go
用户9003486133461 天前
GO语言基础:Context 上下文的概念、取消信号、截止时间、值传递
go
程序员爱钓鱼1 天前
Go语言WebP图像处理实战:golang.org/x/image/webp
后端·google·go
PFinal社区_南丞1 天前
Go语言开发AI智能体:从Function Calling到Agent框架
后端·go
golang学习记2 天前
Fiber v3 适配器模式:17 种写法随便用,老代码"即插即用"🔌
后端·go
用户9003486133462 天前
GO语言基础:变量
go
用户9003486133462 天前
GO语言基础:接口和结构体
go
Nyarlathotep01132 天前
gin03:请求中的参数
后端·go