Vapor 上的 LiveKit(服务器 API)的助手

活气蒸气

Vapor LiveKit Server API 的 Swift 助手。

这不是服务器 SDK。LiveKit有各种各样的服务器SDK

安装

将 LiveKitVapor 添加到您的 Vapor 包.swift。它应该看起来像这样:

// swift-tools-version:5.5
import PackageDescription

let package = Package(
    name: "my-app",
    dependencies: [
         // Other dependencies...
        .package(url: "https://github.com/iankoex/LiveKitVapor.git", from: "0.0.4")
    ],
    targets: [
        .target(name: "App", dependencies: [
            // Other dependencies...
            .product(name: "LiveKitVapor", package: "LiveKitVapor")
        ]),
        // Other targets...
    ]
)

用法

LiveKitVapor 需要一个 LiveKit 的工作实例。

跑:

liveKit-server

在您的代码上:

import LiveKitVapor

# returns 'token'
let videoGrant = VideoGrant(
            roomName: "myRoom",
            canCreateRoom: true,
            canListRooms: true,
            canJoinRoom: true,
            isRoomAdmin: true
        )
let token = try LiveKit.shared.generateToken(videoGrant: videoGrant)
return token

// Use your own api-key and api-secret
// in your configure
public func configure(_ app: Application) throws {
    // Other Configurations
    LiveKit.shared.apiKey = "myOtherDevKey"
    LiveKit.shared.secret = "my-256-bit-secret"
}

LiveKit Server APIs. For more information refer to the APIs docs.

LiveKit Server APIs (twirp) LiveKitVapor
CreateRoom createRoom
ListRooms getAllRoom
DeleteRoom deleteRoom
ListParticipants getAllParticipants
GetParticipant getParticipant
RemoveParticipant removeParticipant
MutePublishedTrack muteTrack
UpdateParticipant updateParticipant
UpdateSubscriptions updateSubscriptions
UpdateRoomMetadata updateRoomMetadata
SendData sendData

Tests

Before running tests, run:

liveKit-server

and then:

liveKit-cli join-room \
     --room TestRoom \
     --identity CLITestUser \
     --api-key devkey \
     --api-secret secret \
     --publish-demo

Test not implemented:

  • sendData
  • updateSubscriptions
  • removeParticipant

Test with an issue:

  • muteParticipant

To Do

  • Make codable structs mirror those of LiveKit swift client sdk.
  • Enums for track type and quality.
  • Test LiveKitVapor on Linux.
  • Something else.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

Run wild. Do as you wish.

GitHub

点击跳转