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
相关推荐
王码码20356 小时前
Go语言的内存管理:原理与实战
后端·golang·go·接口
~|Bernard|10 小时前
一.go语言中slice底层原理(2026-5-7)
golang·go
审判长烧鸡12 小时前
Go 内存优化骚操作
go·内存优化
焗猪扒饭18 小时前
极简案列入门golang依赖注入工具wire
后端·go
讲不出 再见2 天前
go语言-指针
go·指针
HySpark2 天前
VAD 与流式 ASR 踩坑复盘及完整解决方案
webrtc·vad·离线语音转写·流式asr·qwen-asr·音频预处理
讲不出 再见2 天前
go语言-包
golang·go·package··包冲突
徐子元竟然被占了!!2 天前
WebRTC协议
webrtc
ZC跨境爬虫2 天前
跟着 MDN 学 HTML day_28:(使用选择器 API 在 DOM 树中进行选择与遍历)
前端·ui·html·音视频·webrtc
王中阳Go3 天前
用Go写AI Agent:我从实战图书里总结了这些核心逻辑
后端·go·ai编程