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

Commit

Permalink
Fix handling of null metadata (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
incubo4u authored Oct 4, 2023
1 parent 0f411bf commit 4c53127
Showing 1 changed file with 5 additions and 5 deletions.
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

0 comments on commit 4c53127

Please sign in to comment.