Skip to content

Commit b91ec83

Browse files
author
yngrtc
committed
add public init
1 parent 203b804 commit b91ec83

13 files changed

+70
-26
lines changed

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let package = Package(
2929
.library(name: "Utils", targets: ["Utils"]),
3030
],
3131
dependencies: [
32-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0")
32+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0")
3333
],
3434
targets: [
3535
// MARK: - Targets

Sources/SDP/Attribute.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public struct Attribute: Equatable, CustomStringConvertible {
2929
}
3030

3131
/// init constructs a new attribute
32-
init(key: String, value: String? = nil) {
32+
public init(key: String, value: String? = nil) {
3333
self.key = key
3434
self.value = value
3535
}

Sources/SDP/Codec.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public struct Codec: Equatable, CustomStringConvertible {
3131
}
3232

3333
// Initialize the Codec object with default values for its properties
34-
init(
34+
public init(
3535
payloadType: UInt8 = 0, name: String = "", clockRate: UInt32 = 0,
3636
encodingParameters: String = "", fmtp: String = "", rtcpFeedbacks: [String] = []
3737
) {

Sources/SDP/Desscription/CommonDescription.swift

+19
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public struct Address: Equatable, CustomStringConvertible {
3232
}
3333
return output
3434
}
35+
36+
public init(address: String, ttl: Int? = nil, range: Int? = nil) {
37+
self.address = address
38+
self.ttl = ttl
39+
self.range = range
40+
}
3541
}
3642

3743
/// ConnectionInformation defines the representation for the "c=" field
@@ -48,6 +54,12 @@ public struct ConnectionInformation: Equatable, CustomStringConvertible {
4854
return "\(self.networkType) \(self.addressType)"
4955
}
5056
}
57+
58+
public init(networkType: String, addressType: String, address: Address? = nil) {
59+
self.networkType = networkType
60+
self.addressType = addressType
61+
self.address = address
62+
}
5163
}
5264

5365
/// Bandwidth describes an optional field which denotes the proposed bandwidth
@@ -61,6 +73,12 @@ public struct Bandwidth: Equatable, CustomStringConvertible {
6173
let output = self.experimental ? "X-" : ""
6274
return "\(output)\(self.bandwidthType):\(self.bandwidth)"
6375
}
76+
77+
public init(experimental: Bool, bandwidthType: String, bandwidth: UInt64) {
78+
self.experimental = experimental
79+
self.bandwidthType = bandwidthType
80+
self.bandwidth = bandwidth
81+
}
6482
}
6583

6684
/// EncryptionKey describes the "k=" which conveys encryption key information.
@@ -78,6 +96,7 @@ public enum ConnectionRole: String, Equatable, CustomStringConvertible {
7896
/// Direction is a marker for transmission direction of an endpoint
7997
public enum Direction: String, Equatable, CustomStringConvertible {
8098
case sendrecv, sendonly, recvonly, inactive
99+
81100
public var description: String {
82101
self.rawValue
83102
}

Sources/SDP/Desscription/MediaDescription.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public struct RangedPort: Equatable, CustomStringConvertible {
2828
}
2929
}
3030

31-
init(value: Int, range: Int? = nil) {
31+
public init(value: Int, range: Int? = nil) {
3232
self.value = value
3333
self.range = range
3434
}
@@ -51,14 +51,14 @@ public struct MediaName: Equatable, CustomStringConvertible {
5151
return s.joined(separator: " ")
5252
}
5353

54-
init() {
54+
public init() {
5555
self.media = ""
5656
self.port = RangedPort(value: 0)
5757
self.protos = []
5858
self.formats = []
5959
}
6060

61-
init(media: String, port: RangedPort, protos: [String], formats: [String]) {
61+
public init(media: String, port: RangedPort, protos: [String], formats: [String]) {
6262
self.media = media
6363
self.port = port
6464
self.protos = protos
@@ -113,7 +113,7 @@ public struct MediaDescription: Equatable {
113113
return (false, nil)
114114
}
115115

116-
init() {
116+
public init() {
117117
self.mediaName = MediaName()
118118
self.mediaTitle = nil
119119
self.connectionInformation = nil
@@ -122,7 +122,7 @@ public struct MediaDescription: Equatable {
122122
self.attributes = []
123123
}
124124

125-
init(
125+
public init(
126126
mediaName: MediaName,
127127
mediaTitle: Information? = nil,
128128
connectionInformation: ConnectionInformation? = nil,
@@ -140,7 +140,7 @@ public struct MediaDescription: Equatable {
140140

141141
/// creates a new MediaName with
142142
/// some settings that are required by the JSEP spec.
143-
init(codecType: String, _codecPrefs: [String]) {
143+
public init(codecType: String, _codecPrefs: [String]) {
144144
self.mediaName = MediaName(
145145
media: codecType,
146146
port: RangedPort(value: 9),

Sources/SDP/Desscription/SessionDescription.swift

+34-4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ public struct Origin: Equatable, CustomStringConvertible {
5757
return
5858
"\(self.username) \(self.sessionId) \(self.sessionVersion) \(self.networkType) \(self.addressType) \(self.unicastAddress)"
5959
}
60+
61+
public init(username: String, sessionId: UInt64, sessionVersion: UInt64, networkType: String, addressType: String, unicastAddress: String) {
62+
self.username = username
63+
self.sessionId = sessionId
64+
self.sessionVersion = sessionVersion
65+
self.networkType = networkType
66+
self.addressType = addressType
67+
self.unicastAddress = unicastAddress
68+
}
6069
}
6170

6271
/// SessionName describes a structured representations for the "s=" field
@@ -82,6 +91,11 @@ public struct TimeZone: Equatable, CustomStringConvertible {
8291
public var description: String {
8392
return "\(self.adjustmentTime) \(self.offset)"
8493
}
94+
95+
public init(adjustmentTime: UInt64, offset: Int64) {
96+
self.adjustmentTime = adjustmentTime
97+
self.offset = offset
98+
}
8599
}
86100

87101
/// Timing defines the "t=" field's structured representation for the start and
@@ -93,6 +107,11 @@ public struct Timing: Equatable, CustomStringConvertible {
93107
public var description: String {
94108
return "\(self.startTime) \(self.stopTime)"
95109
}
110+
111+
public init(startTime: UInt64, stopTime: UInt64) {
112+
self.startTime = startTime
113+
self.stopTime = stopTime
114+
}
96115
}
97116

98117
/// RepeatTime describes the "r=" fields of the session description which
@@ -109,6 +128,12 @@ public struct RepeatTime: Equatable, CustomStringConvertible {
109128
}
110129
return output
111130
}
131+
132+
public init(interval: Int64, duration: Int64, offsets: [Int64]) {
133+
self.interval = interval
134+
self.duration = duration
135+
self.offsets = offsets
136+
}
112137
}
113138

114139
/// TimeDescription describes "t=", "r=" fields of the session description
@@ -132,13 +157,18 @@ public struct TimeDescription: Equatable, CustomStringConvertible {
132157
}
133158
return result
134159
}
160+
161+
public init(timing: Timing, repeatTimes: [RepeatTime]) {
162+
self.timing = timing
163+
self.repeatTimes = repeatTimes
164+
}
135165
}
136166

137167
/// https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-26#section-5.2.1
138168
/// Session ID is recommended to be constructed by generating a 64-bit
139169
/// quantity with the highest bit set to zero and the remaining 63-bits
140170
/// being cryptographically random.
141-
func newSessionId() -> UInt64 {
171+
public func newSessionId() -> UInt64 {
142172
let c = UInt64.max ^ (UInt64(1) << 63)
143173
return UInt64.random(in: UInt64.min...UInt64.max) & c
144174
}
@@ -229,7 +259,7 @@ public struct SessionDescription: Equatable, CustomStringConvertible {
229259
return self.marshal()
230260
}
231261

232-
init() {
262+
public init() {
233263
self.version = 0
234264
self.origin = Origin(
235265
username: "",
@@ -253,7 +283,7 @@ public struct SessionDescription: Equatable, CustomStringConvertible {
253283
self.mediaDescriptions = []
254284
}
255285

256-
init(identity: Bool) {
286+
public init(identity: Bool) {
257287
self.version = 0
258288
self.origin = Origin(
259289
username: "-",
@@ -285,7 +315,7 @@ public struct SessionDescription: Equatable, CustomStringConvertible {
285315
self.mediaDescriptions = []
286316
}
287317

288-
init(version: Version,
318+
public init(version: Version,
289319
origin: Origin,
290320
sessionName: SessionName,
291321
sessionInformation: Information? = nil,

Sources/SDP/ExtMap.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public struct ExtMap: Equatable, CustomStringConvertible {
5353
return output
5454
}
5555

56-
init(value: Int, direction: Direction? = nil, uri: String? = nil, extAttr: String? = nil) {
56+
public init(value: Int, direction: Direction? = nil, uri: String? = nil, extAttr: String? = nil) {
5757
self.value = value
5858
self.direction = direction
5959
self.uri = uri

Sources/SDP/Lexer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Lexer {
1919
let input: String
2020
var index: String.Index
2121

22-
init(desc: SessionDescription, input: String) {
22+
public init(desc: SessionDescription, input: String) {
2323
self.desc = desc
2424
self.input = input
2525
self.index = input.startIndex

Sources/SDP/SDPError.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
enum SDPError: Error, CustomStringConvertible {
15+
public enum SDPError: Error, CustomStringConvertible {
1616
case codecNotFound
1717
case missingWhitespace
1818
case missingColon
@@ -24,7 +24,7 @@ enum SDPError: Error, CustomStringConvertible {
2424
case syntaxError(String, Int)
2525
case parseInt(String, String)
2626

27-
var description: String {
27+
public var description: String {
2828
switch self {
2929
case .codecNotFound:
3030
return "codec not found"

Tests/SDPTests/DirectionTests.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414
import XCTest
15-
16-
@testable import SDP
15+
import SDP
1716

1817
final class DirectionTests: XCTestCase {
1918
func testNewDirection() throws {

Tests/SDPTests/ExtMapTests.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414
import XCTest
15-
16-
@testable import SDP
15+
import SDP
1716

1817
final class ExtMapTests: XCTestCase {
1918
let exampleAttrExtMap1: String = "extmap:1 http://example.com/082005/ext.htm#ttime"

Tests/SDPTests/MediaDescriptionTests.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414
import XCTest
15-
16-
@testable import SDP
15+
import SDP
1716

1817
final class MediaDescriptionTests: XCTestCase {
1918
func testAttributeMissing() throws {

Tests/SDPTests/SessionDescriptionTests.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414
import XCTest
15-
16-
@testable import SDP
15+
import SDP
1716

1817
final class SessionDescriptionTests: XCTestCase {
19-
2018
let canonicalMashalSdp: String = """
2119
v=0\r\n\
2220
o=jdoe 2890844526 2890842807 IN IP4 10.47.16.5\r\n\

0 commit comments

Comments
 (0)