@@ -11,12 +11,12 @@ import OSLog
11
11
import Pulse
12
12
#endif
13
13
14
- protocol RemoteLoggerConnectionDelegate : AnyObject {
14
+ public protocol RemoteLoggerConnectionDelegate : AnyObject {
15
15
func connection( _ connection: RemoteLogger . Connection , didChangeState newState: NWConnection . State )
16
16
func connection( _ connection: RemoteLogger . Connection , didReceiveEvent event: RemoteLogger . Connection . Event )
17
17
}
18
18
19
- extension RemoteLogger {
19
+ public extension RemoteLogger {
20
20
final class Connection {
21
21
var endpoint : NWEndpoint { connection. endpoint }
22
22
private let connection : NWConnection
@@ -31,14 +31,15 @@ extension RemoteLogger {
31
31
self . init ( NWConnection ( to: endpoint, using: parameters) )
32
32
}
33
33
34
- init ( _ connection: NWConnection ) {
34
+ public init ( _ connection: NWConnection , delegate : RemoteLoggerConnectionDelegate ? = nil ) {
35
35
self . connection = connection
36
+ self . delegate = delegate
36
37
37
38
let isLogEnabled = UserDefaults . standard. bool ( forKey: " com.github.kean.pulse.debug " )
38
39
self . log = isLogEnabled ? OSLog ( subsystem: " com.github.kean.pulse " , category: " RemoteLogger " ) : . disabled
39
40
}
40
-
41
- func start( on queue: DispatchQueue ) {
41
+
42
+ public func start( on queue: DispatchQueue ) {
42
43
connection. stateUpdateHandler = { [ weak self] state in
43
44
guard let self = self else { return }
44
45
DispatchQueue . main. async {
@@ -49,15 +50,15 @@ extension RemoteLogger {
49
50
connection. start ( queue: queue)
50
51
}
51
52
52
- enum Event {
53
+ public enum Event {
53
54
case packet( Packet )
54
55
case error( Error )
55
56
case completed
56
57
}
57
58
58
- struct Packet {
59
- let code : UInt8
60
- let body : Data
59
+ public struct Packet {
60
+ public let code : UInt8
61
+ public let body : Data
61
62
}
62
63
63
64
private func receive( ) {
@@ -130,7 +131,7 @@ extension RemoteLogger {
130
131
}
131
132
}
132
133
133
- func send( code: UInt8 , data: Data ) {
134
+ public func send( code: UInt8 , data: Data ) {
134
135
do {
135
136
let data = try encode ( code: code, body: data)
136
137
let log = self . log
@@ -144,7 +145,7 @@ extension RemoteLogger {
144
145
}
145
146
}
146
147
147
- func send< T: Encodable > ( code: UInt8 , entity: T ) {
148
+ public func send< T: Encodable > ( code: UInt8 , entity: T ) {
148
149
do {
149
150
let data = try JSONEncoder ( ) . encode ( entity)
150
151
send ( code: code, data: data)
@@ -206,7 +207,7 @@ extension RemoteLogger {
206
207
}
207
208
}
208
209
209
- func cancel( ) {
210
+ public func cancel( ) {
210
211
connection. cancel ( )
211
212
}
212
213
}
0 commit comments