Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
19 changes: 12 additions & 7 deletions Promptly/MQTT/MQTTManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,27 @@ class MQTTManager: ObservableObject {
client?.unsubscribe(from: topic)
}

func subscribeToShowChanges(onChange: @escaping (String, String) -> Void) {
func subscribeToShowChanges(onChange: @escaping (String, String, String, String?) -> Void) {
let showsPattern = "shows/#"

client?.messagePublisher
.filter { message in
let components = message.topic.split(separator: "/")
return components.count == 2 && components.first == "shows"
return components.count >= 2 && components.first == "shows"
}
.sink { message in
.sink { [weak self] message in
let topic = message.topic
let messageString = message.payload.string ?? ""
let components = topic.split(separator: "/").map(String.init)

if let showId = topic.split(separator: "/").last.map(String.init) {
DispatchQueue.main.async {
onChange(showId, messageString)
}
guard components.count >= 2 else { return }

let showId = components[1]
let property = components.count > 2 ? components[2] : ""
let title = self?.receivedMessages["shows/\(showId)/title"]

DispatchQueue.main.async {
onChange(showId, property, messageString, title)
}
}
.store(in: &cancellables)
Expand Down
12 changes: 6 additions & 6 deletions Promptly/Views/Home Screen/HomeScreenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct HomeScreenView: View {
@State var navStackMessage: String = ""
@State var addShow: Bool = false
@State var showNetworkSettings: Bool = false
@State var availableShows: [String] = []
@State var availableShows: [String: String] = [:]

@StateObject private var mqttManager = MQTTManager()

Expand All @@ -38,9 +38,9 @@ struct HomeScreenView: View {

mqttManager.connect(to: Constants.mqttIP, port: Constants.mqttPort)

mqttManager.subscribeToShowChanges { showId, message in
if UUID(uuidString: showId) != nil && !availableShows.contains(showId) {
availableShows.append(showId)
mqttManager.subscribeToShowChanges { showId, property, message, title in
if UUID(uuidString: showId) != nil && availableShows[showId] == nil {
availableShows[showId] = title ?? "Unknown Show"
}
}
}
Expand Down Expand Up @@ -81,9 +81,9 @@ struct HomeScreenView: View {
Text("No available shows")
.foregroundStyle(.secondary)
} else {
ForEach(availableShows, id: \.self) { showId in
ForEach(Array(availableShows.keys), id: \.self) { showId in
NavigationLink(destination: MultiPlayerShowDetail(showID: showId, mqttManager: self.mqttManager)) {
Text("Show \(showId)")
Text(availableShows[showId] ?? "Unknown Show")
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion Promptly/Views/Performance Mode/LivePerforemanceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,7 @@ extension DSMPerformanceView {
}

calledCues.insert(cue.id)

let execution = ReportCueExecution(
timestamp: Date(),
cueLabel: cue.label,
Expand All @@ -1644,13 +1645,24 @@ extension DSMPerformanceView {
)
cueExecutions.append(execution)

if cue.hasAlert {
showCueAlert()
}

if cue.type.isStandby {
logCall("REMOTE STANDBY: \(cue.label)", type: .call)
} else {
logCall("REMOTE GO: \(cue.label)", type: .action)
}

// SEND THE UPDATE HERE TOO
let timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: false) { _ in
withAnimation(.easeOut(duration: 0.3)) {
hiddenCues.insert(cue.id)
}
cueHideTimers.removeValue(forKey: cue.id)
}
cueHideTimers[cue.id] = timer

let uuidStrings = calledCues.map { $0.uuidString }
if let jsonData = try? JSONEncoder().encode(uuidStrings),
let jsonString = String(data: jsonData, encoding: .utf8) {
Expand Down
Loading