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
相关推荐
Soari15 小时前
挑战 100ms 延迟极限:深度拆解 dograh,构建企业级开源 WebRTC 实时语音智能体平台
开源·大模型·webrtc·实时音视频·voiceagent·语音智能体·dograh
被考核重击17 小时前
WebRTC技术解析
webrtc
审判长烧鸡17 小时前
【Go 时间类型】时间对比
go·时间
科学界的小白18 小时前
【硬核开源】手搓国产云原生网关:基于“零态流控”的Go语言百万并发实战(附完整代码)
go
审判长烧鸡20 小时前
【Go 时间类型】 int64/time.Time的选择
postgresql·go·time.time
审判长烧鸡20 小时前
【PHPer转Go】函数/方法返回类型的取舍,指针还是值
go·指针·类型·
用户398346161202 天前
Go-Spring 实战第 5 课 —— 配置来源:Reader、Provider、环境变量与命令行参数
spring·go
喵了几个咪2 天前
Kratos WebRTC 传输中间件:H5游戏P2P实时音视频与数据通信实战
游戏·微服务·中间件·golang·webrtc·实时音视频·kratos
weixin_421725262 天前
Linux 编程语言全解析:C、C++、Python、Go、Rust 谁更强?
linux·python·go·c·编程语言
yyyyyyyuande2 天前
LSEG美股行情接入经验分享
性能优化·go