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

Commit

Permalink
add serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
karkakol committed Jan 15, 2024
1 parent 2db92df commit 3694c32
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Sources/MembraneRTC/Events/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,15 @@ struct OfferDataEvent: ReceivableEvent, Codable {

struct TracksAddedEvent: ReceivableEvent, Codable {
struct Data: Codable {
struct TrackData: Codable{
let metadata: Metadata
let simulcastConfig: SimulcastConfig?
}
let endpointId: String
let trackIdToMetadata: [String: Metadata]
let tracks: [String: TrackData]
}


let type: ReceivableEventType
let data: Data
Expand Down
29 changes: 21 additions & 8 deletions Sources/MembraneRTC/Types/SimulcastConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// `"h"` - original encoding
/// `"m"` - original encoding scaled down by 2
/// `"l"` - original encoding scaled down by 4
public enum TrackEncoding: Int, CustomStringConvertible {
public enum TrackEncoding: Int, CustomStringConvertible, Codable {
case l = 0
case m
case h
Expand All @@ -15,26 +15,39 @@ public enum TrackEncoding: Int, CustomStringConvertible {
}
}

static func fromString(_ s: String) -> TrackEncoding? {
switch s {
enum TrackEncodingCodingError: Error {
case decoding(String)
}

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let encodingString = try container.decode(String.self)

switch encodingString {
case "l":
return .l
self = .l
case "m":
return .m
self = .m
case "h":
return .h
self = .h
default:
return nil
throw TrackEncodingCodingError.decoding("\(encodingString) is not a valid encoding")
}
}

public func encode(to encoder: Swift.Encoder) throws {
var container = encoder.singleValueContainer()
let encodingString = description
try container.encode(encodingString)
}
}

/// Simulcast configuration.
///
/// At the moment, simulcast track is initialized in three versions - low, medium and high.
/// High resolution is the original track resolution, while medium and low resolutions
/// are the original track resolution scaled down by 2 and 4 respectively.
public struct SimulcastConfig {
public struct SimulcastConfig: Codable {
/**
* Whether to simulcast track or not.
*/
Expand Down

0 comments on commit 3694c32

Please sign in to comment.