Skip to content

Commit

Permalink
Access Control: changed 'var connection: NWConnection?' to public.
Browse files Browse the repository at this point in the history
I want to test 'NWConnection.State' possibilities.
We should integrate some kind of status checking.

added public var state: NWConnection.State

correction: self.state

Update OSCClient.swift

Update OSCClient.swift

Update OSCClient.swift

Update OSCServer.swift

Update OSCClient.swift

Update OSCClient.swift

Update OSCServer.swift

Update OSCServer.swift

Update OSCServer.swift
  • Loading branch information
soundflix committed Jan 8, 2022
1 parent 2a87ca9 commit c48403c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 8 additions & 1 deletion Framework/SwiftOSC/Network/OSCClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import Network

public class OSCClient {

var connection: NWConnection?
public var connection: NWConnection? // Access Control: changed 'var connection: NWConnection?' to public.
public private(set) var ready: Bool = false
var queue: DispatchQueue

public private(set) var host: NWEndpoint.Host
Expand Down Expand Up @@ -47,18 +48,24 @@ public class OSCClient {
connection?.stateUpdateHandler = { [weak self] (newState) in
switch newState {
case .ready:
self?.ready = true
NSLog("SwiftOSC Client is ready. \(String(describing: self?.connection))")
case .failed(let error):
self?.ready = false
NSLog("SwiftOSC Client failed with error \(error)")
NSLog("SWiftOSC Client is restarting.")
self?.setupConnection()
case .cancelled:
self?.ready = false
break
case .waiting(let error):
self?.ready = false
NSLog("SwiftOSC Client waiting with error \(error)")
case .preparing:
self?.ready = false
break
case .setup:
self?.ready = false
break
}
}
Expand Down
11 changes: 5 additions & 6 deletions Framework/SwiftOSC/Network/OSCServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public class OSCServer {

public weak var delegate: OSCDelegate?

var listener: NWListener?
public var listener: NWListener?
public private(set) var port: NWEndpoint.Port
public private(set) var name: String?
var queue: DispatchQueue
var connection: NWConnection?

public private(set) var running: Bool = false
public private(set) var ready: Bool = false
var bonjour: Bool = false

public init?(port: Int, bonjourName: String? = nil) {
Expand Down Expand Up @@ -77,14 +77,14 @@ public class OSCServer {
switch newState {
case .ready:
NSLog("Listening on port \(String(describing: self?.listener?.port))")
self?.running = true
self?.ready = true
case .failed(let error):
NSLog("Listener failed with error \(error)")
self?.running = false
self?.ready = false
self?.restart()
case .cancelled:
NSLog("Listener cancelled")
self?.running = false
self?.ready = false
default:
break
}
Expand Down Expand Up @@ -267,7 +267,6 @@ public class OSCServer {
// destroy connection and listener
connection?.forceCancel()
listener?.cancel()
self.running = false
}

public func restart() {
Expand Down

0 comments on commit c48403c

Please sign in to comment.