Skip to content

Add local participant identity to all outgoing data packets #602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nanpa/data-packet-identity.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
minor type="fixed" "Outgoing data packets missing local participant identity"
5 changes: 5 additions & 0 deletions Sources/LiveKit/Core/Room+Engine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ extension Room {
log("publisher data channel is not .open", .error)
}

var packet = packet
if let identity = localParticipant.identity?.stringValue {
packet.participantIdentity = identity
}

// Should return true if successful
try publisherDataChannel.send(dataPacket: packet)
}
Expand Down
3 changes: 3 additions & 0 deletions Tests/LiveKitTests/Broadcast/IPCChannelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ final class IPCChannelTests: LKTestCase {
await fulfillment(of: [cancelThrowsError], timeout: 5.0)
}

// swiftformat:disable redundantSelf hoistAwait
func testConnectorCancelDuringInit() async throws {
try await assertInitCancellationThrows(
await IPCChannel(connectingTo: self.socketPath)
Expand All @@ -105,6 +106,8 @@ final class IPCChannelTests: LKTestCase {
)
}

// swiftformat:enable all

private struct TestHeader: Codable, Equatable {
let someField: Int
}
Expand Down
18 changes: 18 additions & 0 deletions Tests/LiveKitTests/RoomTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ class RoomTests: LKTestCase {
// Nothing to do here
}
}

func testSendDataPacket() async throws {
try await withRooms([RoomTestingOptions()]) { rooms in
let room = rooms[0]

let expectDataPacket = self.expectation(description: "Should send data packet")

let mockDataChannel = MockDataChannelPair { packet in
XCTAssertEqual(packet.participantIdentity, room.localParticipant.identity?.stringValue ?? "")
expectDataPacket.fulfill()
}
room.publisherDataChannel = mockDataChannel

try await room.send(dataPacket: Livekit_DataPacket())

await self.fulfillment(of: [expectDataPacket], timeout: 5)
}
}
}

extension RoomTests: RoomDelegate {
Expand Down
13 changes: 0 additions & 13 deletions Tests/LiveKitTests/RpcTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@
import XCTest

class RpcTests: LKTestCase {
// Mock DataChannelPair to intercept outgoing packets
class MockDataChannelPair: DataChannelPair {
var packetHandler: (Livekit_DataPacket) -> Void

init(packetHandler: @escaping (Livekit_DataPacket) -> Void) {
self.packetHandler = packetHandler
}

override func send(dataPacket packet: Livekit_DataPacket) throws {
packetHandler(packet)
}
}

// Test performing RPC calls and verifying outgoing packets
func testPerformRpc() async throws {
try await withRooms([RoomTestingOptions()]) { rooms in
Expand Down
30 changes: 30 additions & 0 deletions Tests/LiveKitTests/Support/MockDataChannelPair.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@testable import LiveKit

/// Mock ``DataChannelPair`` to intercept outgoing packets.
class MockDataChannelPair: DataChannelPair {
var packetHandler: (Livekit_DataPacket) -> Void

init(packetHandler: @escaping (Livekit_DataPacket) -> Void) {
self.packetHandler = packetHandler
}

override func send(dataPacket packet: Livekit_DataPacket) throws {
packetHandler(packet)
}
}
Loading