Skip to content

Commit 14977e6

Browse files
authored
Convert stream timestamps from/to ms (#637)
Noticed that while working with text streams 🕙
1 parent dfba35d commit 14977e6

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

.nanpa/fix-stream-timestamps.kdl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch type="fixed" "Wrong stream timestamp conversion"

Sources/LiveKit/DataStream/Outgoing/OutgoingStreamManager.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,10 @@ extension Livekit_DataStream.Header {
272272
}
273273
}
274274

275+
// Stream timestamps are in ms (13 digits)
275276
var timestampDate: Date {
276-
get { Date(timeIntervalSince1970: TimeInterval(timestamp)) }
277-
set { timestamp = Int64(newValue.timeIntervalSince1970) }
277+
get { Date(timeIntervalSince1970: TimeInterval(timestamp) / TimeInterval(1000)) }
278+
set { timestamp = Int64(newValue.timeIntervalSince1970 * TimeInterval(1000)) }
278279
}
279280
}
280281

Tests/LiveKitTests/DataStream/ByteStreamInfoTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ByteStreamInfoTests: LKTestCase {
3232
XCTAssertEqual(header.streamID, info.id)
3333
XCTAssertEqual(header.mimeType, info.mimeType)
3434
XCTAssertEqual(header.topic, info.topic)
35-
XCTAssertEqual(header.timestamp, Int64(info.timestamp.timeIntervalSince1970))
35+
XCTAssertEqual(header.timestamp, Int64(info.timestamp.timeIntervalSince1970 * TimeInterval(1000)))
3636
XCTAssertEqual(header.totalLength, UInt64(info.totalLength ?? -1))
3737
XCTAssertEqual(header.attributes, info.attributes)
3838
XCTAssertEqual(header.byteHeader.name, info.name)

Tests/LiveKitTests/DataStream/TextStreamInfoTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TextStreamInfoTests: LKTestCase {
3434
let header = Livekit_DataStream.Header(info)
3535
XCTAssertEqual(header.streamID, info.id)
3636
XCTAssertEqual(header.topic, info.topic)
37-
XCTAssertEqual(header.timestamp, Int64(info.timestamp.timeIntervalSince1970))
37+
XCTAssertEqual(header.timestamp, Int64(info.timestamp.timeIntervalSince1970 * TimeInterval(1000)))
3838
XCTAssertEqual(header.totalLength, UInt64(info.totalLength ?? -1))
3939
XCTAssertEqual(header.attributes, info.attributes)
4040
XCTAssertEqual(header.textHeader.operationType.rawValue, info.operationType.rawValue)

0 commit comments

Comments
 (0)