// A call's ring, or its stop, handed over the chat socket (`{t:"ring", kind: ring|stop, …}`).//// The Worker rings an open phone over its chat socket INSTEAD of a push (`apps/business/src/calling/calls.ts`// `ringIn`, `frameTo`: "Over its open socket when it has one, else by push"), so a phone with Comms open is rung only// here. The chat socket (`ChatCenter`) reads the frame and posts it; the calls engine (`CallingEngine`) takes it as it// takes a VoIP push, without CallKit's push report (the core's `system_call_incoming` reports the ring). Android does// the same (`ChatFrames.ring`).importFoundationpublicenumCallRingFrame: Equatable, Sendable {/// `at`: when the ring began, as the object kept it (to a phone that speaks the new way), so one rung late starts there.case ring(room: String, video: Bool, box: String?, at: Int64? = nil)/// `box`: a missed call's caller, sealed as the ring was, so a phone that never heard the ring writes its row;/// `times`: when it rang and ended, for that row.case stop(room: String, reason: String, box: String?, times: CallTimes? = nil)/// A missed call kept for this phone and told once as its socket opened: it writes the row and rings nothing.case missed(room: String, reason: String, box: String?, times: CallTimes?)/// `{t:"ring", kind: ring|stop|missed, room, video:"1"|"0" | stop, box?, at?, ended?}`; nil for any other frame.publicinit?(frame: JSONValue) {guard frame["t"]?.string == "ring", let room = frame["room"]?.string, !room.isEmpty else { returnnil }let box = frame["box"]?.string.flatMap { $0.isEmpty ? nil : $0 }let times = CallTimes(at: frame["at"]?.string.flatMap { Int64($0) }, ended: frame["ended"]?.string.flatMap { Int64($0) })switch frame["kind"]?.string {case"stop": self = .stop(room: room, reason: frame["stop"]?.string ?? "", box: box, times: times)case"missed": self = .missed(room: room, reason: frame["stop"]?.string ?? "missed", box: box, times: times)default: self = .ring(room: room, video: frame["video"]?.string == "1", box: box, at: frame["at"]?.string.flatMap { Int64($0) }.flatMap { $0 > 0 ? $0 : nil }) } }publicvar room: String {switchself {case .ring(let room, _, _, _), .stop(let room, _, _, _), .missed(let room, _, _, _): room } }/// What this build says it speaks as its chat socket opens (`{t:"hello", can}`): it acks each ring frame, takes a/// late ring, and a missed call kept for it. A build that says nothing is rung as before (CALLS FIX 2).publicstaticlet can: [String] = ["ring_ack"]/// Where the chat socket posts a ring for the calls engine (the frame as `object`).publicstaticlet arrived = Notification.Name("com.cottondb.calls.ring-frame")}/// When a ring began and ended (ms since 1970), as the person's object kept them: a missed call's row says when it rang.publicstructCallTimes: Equatable, Sendable {publicvar at: Int64publicvar ended: Int64publicinit(at: Int64, ended: Int64) {self.at = atself.ended = ended }/// Both, or none.publicinit?(at: Int64?, ended: Int64?) {guardlet at, let ended, at > 0, ended >= at else { returnnil }self.init(at: at, ended: ended) }}