Skip to content

Commit e74d63a

Browse files
committed
address feedbacks
1 parent 9a05c05 commit e74d63a

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

Sources/LaunchDarklyObservability/Plugin/PluginError.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import Foundation
22

33
public enum PluginError: LocalizedError {
44
case observabilityInstanceAlreadyExist
5+
case sessionReplayInstanceAlreadyExist
56

67
public var errorDescription: String? {
78
switch self {
89
case .observabilityInstanceAlreadyExist:
910
return "Observability plugin is already initialized, only a single instance can be initialized at runtime."
11+
case .sessionReplayInstanceAlreadyExist:
12+
return "Session Replay plugin is already initialized, only a single instance can be initialized at runtime."
1013
}
1114
}
1215
}

Sources/LaunchDarklySessionReplay/API/LDReplay.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import Foundation
22
import LaunchDarkly
33

4-
public final class LDReplay: AnyObject {
4+
public final class LDReplay {
55
public static var shared = LDReplay()
66

77
var client: SessionReplayServicing?
8-
8+
9+
private init() {
10+
// privacy for singleton
11+
}
12+
913
public func start() {
1014
Task { @MainActor in
1115
client?.start()

Sources/LaunchDarklySessionReplay/SessionReplay.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@ public final class SessionReplay: Plugin {
2121
os_log("%{public}@", log: options.log, type: .error, "Session Replay Service could not find Observability Service")
2222
return
2323
}
24-
24+
2525
observabilityContext = context
26-
26+
2727
do {
28+
guard LDReplay.shared.client == nil else {
29+
throw PluginError.sessionReplayInstanceAlreadyExist
30+
}
31+
2832
let sessionReplayService = try SessionReplayService(observabilityContext: context,
29-
sessonReplayOptions: options,
30-
metadata: metadata)
33+
sessonReplayOptions: options,
34+
metadata: metadata)
3135
LDReplay.shared.client = sessionReplayService
3236
self.sessionReplayService = sessionReplayService
33-
37+
3438
if options.isEnabled {
3539
start()
3640
}

Sources/LaunchDarklySessionReplay/SessionReplayService.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import Common
88

99
protocol SessionReplayServicing {
1010
@MainActor
11-
func start(
12-
13-
)
11+
func start()
12+
1413
@MainActor
1514
func stop()
1615
}

0 commit comments

Comments
 (0)