定制 agence104/livekit-server-sdk 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

agence104/livekit-server-sdk

Composer 安装命令:

composer require agence104/livekit-server-sdk

包简介

Server-side SDK for LiveKit.

README 文档

README

Use this SDK to interact with livekit server APIs and create access tokens from your PHP Backend.

Installation

Requirements

  • php: >= 8.1

Composer

composer require agence104/livekit-server-sdk

Usage

Environment Variables

You may store credentials in environment variables. If host, api-key or api-secret is not passed in when creating a RoomServiceClient or AccessToken, the values in the following env vars will be used:

  • LIVEKIT_URL
  • LIVEKIT_API_KEY
  • LIVEKIT_API_SECRET

Creating Access Tokens

Creating a token for participant to join a room.

use Agence104\LiveKit\AccessToken;
use Agence104\LiveKit\AccessTokenOptions;
use Agence104\LiveKit\VideoGrant;

// If this room doesn't exist, it'll be automatically created when the first
// client joins.
$roomName = 'name-of-room';
// The identifier to be used for participant.
$participantName = 'user-name';

// Define the token options.
$tokenOptions = (new AccessTokenOptions())
  ->setIdentity($participantName);

// Define the video grants.
$videoGrant = (new VideoGrant())
  ->setRoomJoin()
  ->setRoomName($roomName);

// Initialize and fetch the JWT Token.
$token = (new AccessToken('api-key', 'secret-key'))
  ->init($tokenOptions)
  ->setGrant($videoGrant)
  ->toJwt();

By default, the token expires after 6 hours. you may override this by passing in ttl in the access token options. ttl is expressed in seconds (as number) .

Parsing the Access Tokens

Converting the JWT Token into a ClaimGrants.

use Agence104\LiveKit\AccessToken;

// Initialize and parse the JWT Token.
$claimGrants = (new AccessToken('api-key', 'secret-key'))
  ->fromJwt($token);

Permissions in Access Tokens

It's possible to customize the permissions of each participant:

use Agence104\LiveKit\VideoGrant;

$videoGrant = (new VideoGrant())
  ->setRoomJoin() // TRUE by default.
  ->setRoomName('name-of-room')
  ->setCanPublish(FALSE)
  ->setCanSubscribe() // TRUE by default.
  ->setGrant($videoGrant);

This will allow the participant to subscribe to tracks, but not publish their own to the room.

Managing Rooms

RoomServiceClient gives you APIs to list, create, and delete rooms. It also requires a pair of api key/secret key to operate.

use Agence104\LiveKit\RoomServiceClient;
use Agence104\LiveKit\RoomCreateOptions;

$host = 'https://my.livekit.host';
$svc = new RoomServiceClient($host, 'api-key', 'secret-key');

// List rooms.
$rooms = $svc->listRooms();

// Create a new room.
$opts = (new RoomCreateOptions())
  ->setName('myroom')
  ->setEmptyTimeout(10)
  ->setMaxParticipants(20);
$room = $svc->createRoom($opts);

// Delete a room.
$svc->deleteRoom('myroom');

Running Tests

We'll utilize Lando to streamline the test execution process. However, should you choose to run the tests on your local environment directly, you can certainly proceed with that approach.

Step 1:

Generate your environment file by duplicating example.env and renaming the copy to .env, then enter your credentials accordingly.

Step 2:

Start the lando project.

lando start

Step 3:

Run the tests. This single command handles everything automatically: creating a test room, starting load test participants, setting up an RTMP tunnel, running PHPUnit, and cleaning up when done.

lando test


LiveKit Ecosystem
LiveKit SDKsBrowser · iOS/macOS/visionOS · Android · Flutter · React Native · Rust · Node.js · Python · Unity · Unity (WebGL) · ESP32
Server APIsNode.js · Golang · Ruby · Java/Kotlin · Python · Rust · PHP (community) · .NET (community)
UI ComponentsReact · Android Compose · SwiftUI
Agents FrameworksPython · Node.js · Playground
ServicesLiveKit server · Egress · Ingress · SIP
ResourcesDocs · Example apps · Cloud · Self-hosting · CLI

agence104/livekit-server-sdk 适用场景与选型建议

agence104/livekit-server-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 357.16k 次下载、GitHub Stars 达 88, 最近一次更新时间为 2022 年 05 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 agence104/livekit-server-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 agence104/livekit-server-sdk 我们能提供哪些服务?
定制开发 / 二次开发

基于 agence104/livekit-server-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 357.16k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 88
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 88
  • Watchers: 3
  • Forks: 47
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-02