Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Fix handling of null metadata #49

Merged
merged 1 commit into from
Oct 4, 2023
Merged
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
10 changes: 5 additions & 5 deletions Sources/MembraneRTC/Types/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ public struct Endpoint: Codable {
public let metadata: Metadata
public let trackIdToMetadata: [String: Metadata]?

public init(id: String, type: String, metadata: Metadata, trackIdToMetadata: [String: Metadata]?) {
public init(id: String, type: String, metadata: Metadata?, trackIdToMetadata: [String: Metadata]?) {
self.id = id
self.type = type
self.metadata = metadata
self.metadata = metadata ?? Metadata()
self.trackIdToMetadata = trackIdToMetadata
}

Expand All @@ -22,9 +22,9 @@ public struct Endpoint: Codable {
)
}

public func withTrack(trackId: String, metadata: Metadata) -> Self {
public func withTrack(trackId: String, metadata: Metadata?) -> Self {
var newTrackIdToMetadata = self.trackIdToMetadata
newTrackIdToMetadata?[trackId] = metadata
newTrackIdToMetadata?[trackId] = metadata ?? Metadata()

return Endpoint(id: self.id, type: self.type, metadata: self.metadata, trackIdToMetadata: newTrackIdToMetadata)
}
Expand All @@ -44,7 +44,7 @@ public struct Endpoint: Codable {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(String.self, forKey: .id)
self.type = try container.decode(String.self, forKey: .type)
self.metadata = try container.decode(Metadata.self, forKey: .metadata)
self.metadata = try container.decodeIfPresent(Metadata.self, forKey: .metadata) ?? Metadata()
self.trackIdToMetadata = try container.decodeIfPresent(
[String: Metadata].self, forKey: .trackIdToMetadata)
}
Expand Down