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 小时前
webrtc 拥塞控制GCC 和PCC
webrtc
Cxiaomu17 小时前
React接入WebRTC实时视频实践
react.js·音视频·webrtc
踏着七彩祥云的小丑19 小时前
Go 学习第6天:结构体 + 切片 + range遍历
开发语言·学习·golang·go
AndyHuang197619 小时前
WebRTC 强制 Relay 模式下 TCP 重连失败深度排查与优化实战
webrtc
换个昵称都难19 小时前
webrtc pacing 平滑发包模块
webrtc
壮Sir不壮20 小时前
GO语言——GMP调度模型
linux·开发语言·golang·go·操作系统·线程·协程
换个昵称都难21 小时前
webrtc 音频混音介绍
音视频·webrtc
ShuiShenHuoLe21 小时前
go语言time模块
go
2601_951645782 天前
Linux 编程语言全解析:C、C++、Python、Go、Rust 谁更强?
linux·python·go·c·编程语言