Skip to content

Commit

Permalink
fix swiftlint warning
Browse files Browse the repository at this point in the history
  • Loading branch information
huiping192 committed Jun 21, 2023
1 parent 026a7a4 commit ef40fbc
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 61 deletions.
10 changes: 10 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
disabled_rules:
- cyclomatic_complexity
included:
- Sources
- Tests
#excluded:
# - "the place where i committed many coding sins"
line_length: 200
#reporter: "json"
#allow_zero_lintable_files: true
2 changes: 1 addition & 1 deletion HPRTMP.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Pod::Spec.new do |s|
s.homepage = 'https://github.com/huiping192/HPRTMP'
s.license = 'MIT'
s.author = { 'huiping192' => '[email protected]' }
s.platforms = { :ios => '14.0', :osx => '11' }
s.platforms = { :ios => '14.0', :osx => '12' }
s.source = { :git => 'https://github.com/huiping192/HPRTMP.git', :tag => s.version.to_s }
s.swift_version = '5.5'

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription

let package = Package(
name: "HPRTMP",
platforms: [.iOS(.v14), .macOS(.v11)],
platforms: [.iOS(.v14), .macOS(.v12)],
products: [
.library(
name: "HPRTMP",
Expand Down
12 changes: 4 additions & 8 deletions Sources/HPRTMP/AMF/AFM3Decode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,7 @@ private extension Data {
mutating func decodeVectorNumber<T>(_ reference: inout AMF3ReferenceTable) throws -> [T] {
var decodeData = [T]()
let (length, type) = try self.decodeLengthWithType()

guard let first = self.first,
let _ = AMF3EncodeType.Vector(rawValue: first) else {
guard let first = self.first, AMF3EncodeType.Vector(rawValue: first) != nil else {
throw AMF3DecodeError.rangeError
}
self.remove(at: 0)
Expand Down Expand Up @@ -355,7 +353,7 @@ private extension Data {
switch objType {
case .value:
let range = 0..<typeLength
guard let _ = self[safe: range] else {
guard self[safe: range] != nil else {
throw AMF3DecodeError.rangeError
}
self.removeSubrange(range)
Expand All @@ -370,10 +368,8 @@ private extension Data {

mutating func decodeLengthWithType() throws -> (length: Int, type: AMF3EncodeType.U29) {
let value = self.convertLength()

let length = value >> 1
let u29Raw = UInt8(value & 0x01)

guard let type = AMF3EncodeType.U29(rawValue: u29Raw) else {
throw AMF3DecodeError.rangeError
}
Expand All @@ -391,12 +387,12 @@ private extension Data {
if isEnd { break }
lastIdx += 1
}
let value = numberArr.enumerated().reduce(0) { (rc, current) -> Int in
let value = numberArr.enumerated().reduce(0) { (rcValue, current) -> Int in
var shift = (lastIdx-current.offset)*7
if lastIdx == 3 && current.offset != 3 {
shift += 1
}
return rc + Int(current.element) << shift
return rcValue + Int(current.element) << shift
}

return value
Expand Down
6 changes: 3 additions & 3 deletions Sources/HPRTMP/Message/CommandMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ class DeleteStreamMessage: CommandMessage, Encodable {
}

public enum PubishType: String {
case live = "live"
case record = "record"
case append = "append"
case live
case record
case append
}

class PublishMessage: CommandMessage, Encodable {
Expand Down
15 changes: 8 additions & 7 deletions Sources/HPRTMP/Message/DataMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ public class RTMPBaseMessage: RTMPMessage {
self.streamId = streamId
}

private var _timeInterval: UInt32 = 0
public var timestamp: UInt32 {
set {
_timeInterval = newValue >= maxTimestamp ? maxTimestamp : newValue
} get {
return _timeInterval
}
private var _timeInterval: UInt32 = 0
public var timestamp: UInt32 {
get {
return _timeInterval
}
set {
_timeInterval = newValue >= maxTimestamp ? maxTimestamp : newValue
}
}
}

class DataMessage: RTMPBaseMessage {
Expand Down
51 changes: 26 additions & 25 deletions Sources/HPRTMP/Message/RTMPResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ struct ConnectResponse {

struct StatusResponse: Decodable {
enum Level: String, Decodable {
case warning = "warning"
case status = "status"
case error = "error"
case warning
case status
case error
}

enum StreamStatus: String, Decodable {
Expand Down Expand Up @@ -123,27 +123,27 @@ public struct MetaDataResponse {
public var audiocodecid: String = ""

enum CodingKeys: String, CodingKey {
case duration = "duration"
case height = "height"
case frameWidth = "frameWidth"
case moovposition = "moovposition"
case framerate = "framerate"
case avcprofile = "avcprofile"
case videocodecid = "videocodecid"
case frameHeight = "frameHeight"
case videoframerate = "videoframerate"
case audiochannels = "audiochannels"
case displayWidth = "displayWidth"
case displayHeight = "displayHeight"
case trackinfo = "trackinfo"
case width = "width"
case avclevel = "avclevel"
case audiosamplerate = "audiosamplerate"
case aacaot = "aacaot"
case audiocodecid = "audiocodecid"
case duration
case height
case frameWidth
case moovposition
case framerate
case avcprofile
case videocodecid
case frameHeight
case videoframerate
case audiochannels
case displayWidth
case displayHeight
case trackinfo
case width
case avclevel
case audiosamplerate
case aacaot
case audiocodecid
}

init?(commandObject: [String: Any?]?) { // swiftlint:disable:this cyclomatic_complexity
init?(commandObject: [String: Any?]?) { // swiftlint:disable:this function_body_length
guard let commandObject = commandObject else { return nil }

if let duration = commandObject["duration"] as? Double {
Expand Down Expand Up @@ -198,7 +198,7 @@ public struct MetaDataResponse {
self.audiocodecid = audiocodecid
}
if let trackinfoArray = commandObject["trackinfo"] as? [[String: Any?]] {
var trackinfo = [Trackinfo]()
var trackinfos = [Trackinfo]()
for trackinfoDict in trackinfoArray {
if let timescale = trackinfoDict["timescale"] as? Double,
let length = trackinfoDict["length"] as? Double,
Expand All @@ -210,10 +210,11 @@ public struct MetaDataResponse {
sampledescription.append(SampleDescription(sampletype: sampletype))
}
}
trackinfo.append(Trackinfo(sampledescription: sampledescription, language: language, timescale: timescale, length: length))
let trackinfo = Trackinfo(sampledescription: sampledescription, language: language, timescale: timescale, length: length)
trackinfos.append(trackinfo)
}
}
self.trackinfo = trackinfo
self.trackinfo = trackinfos
}
}
}
2 changes: 1 addition & 1 deletion Sources/HPRTMP/RTMPHandshake.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ actor RTMPHandshake {
// random
let randomSize = RTMPHandshake.packetSize - data.count
(0...randomSize).forEach { _ in
data.write(UInt8(arc4random_uniform(0xff)))
data.write(UInt8.random(in: 0...0xff))
}
return data
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/HPRTMP/RTMPPublishSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class RTMPPublishSession {
case failed(err: RTMPError)
case disconnected

public static func ==(lhs: Status, rhs: Status) -> Bool {
public static func == (lhs: Status, rhs: Status) -> Bool {
switch (lhs, rhs) {
case (.unknown, .unknown),
(.connect, .connect),
Expand Down
25 changes: 11 additions & 14 deletions Sources/HPRTMP/RTMPSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ public enum RTMPError: Error {
case command(desc: String)
case uknown(desc: String)
var localizedDescription: String {
get {
switch self {
case .handShake(let desc):
return desc
case .stream(let desc):
return desc
case .command(let desc):
return desc
case .uknown(let desc):
return desc
}
switch self {
case .handShake(let desc):
return desc
case .stream(let desc):
return desc
case .command(let desc):
return desc
case .uknown(let desc):
return desc
}
}
}
Expand Down Expand Up @@ -128,7 +126,6 @@ extension RTMPSocket {
await self.invalidate()
default:
self.logger.info("connection state: other")
break
}
}
}
Expand Down Expand Up @@ -221,7 +218,7 @@ extension RTMPSocket {
}
}

private func decode(data: Data) async {
private func decode(data: Data) async { // swiftlint:disable:this function_body_length
guard let message = await decoder.decode() else {
logger.info("[HPRTMP] decode message need more data.")
return
Expand Down Expand Up @@ -303,7 +300,7 @@ extension RTMPSocket {
}
}

private func handleCommandMessage(_ commandMessage: CommandMessage) async {
private func handleCommandMessage(_ commandMessage: CommandMessage) async { // swiftlint:disable:this function_body_length
if commandMessage.commandNameType == .onStatus {
guard let statusResponse = StatusResponse(info: commandMessage.info) else { return }
if statusResponse.level == .error {
Expand Down

0 comments on commit ef40fbc

Please sign in to comment.