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
相关推荐
rocksun6 小时前
Neovim,会是你的下一款“真香”开发神器吗?
linux·python·go
Charlie_Byte7 小时前
在 Kratos 中设置自定义 HTTP 响应格式
后端·go
qq_310658511 天前
webrtc源码走读(四)核心引擎层——视频引擎
服务器·c++·音视频·webrtc
qq_310658511 天前
webrtc源码走读(三)核心引擎层——音频引擎
服务器·c++·音视频·webrtc
DICOM医学影像1 天前
14. Go-Ethereum测试Solidity ERC20合约 - Go-Ethereum调用区块链方法
开发语言·golang·go·区块链·solidity·以太坊·go-ethereum
锦瑟弦音2 天前
go2rtc实现获取rtsp视频到vue
go
book_bbyuan2 天前
webrtc AGC的通俗说明
webrtc
qq_310658512 天前
webrtc源码走读(一)WebRTC源码结构拆分
服务器·c++·音视频·webrtc
qq_310658512 天前
webrtc源码走读(二)应用层如何使用WebRTC API实现功能
服务器·c++·音视频·webrtc
王中阳Go3 天前
手把手教你用 Go + Eino 搭建一个企业级 RAG 知识库(含代码与踩坑)
人工智能·后端·go