nx_callsig.nx source
↩ module page · 42 lines · 2200 B
1// nx_callsig.nx -- sovereign CALL SIGNALING state machine: a telephone-style ring/accept/reject flow so the
2// boy and girl can call each other and the callee is actively NOTIFIED (ringing) -- not silently ignored.
3// Telephone semantics by construction:
4// * a call must be EXPLICITLY accepted from RINGING -> no accidental tap can connect it
5// * an unanswered ring TIMES OUT to MISSED -> a persistent record the callee still sees (notifications not lost)
6// * only accept/reject/cancel/timeout leave RINGING; ANY stray event keeps it ringing (can't be fat-fingered away)
7// The invite/accept/reject events themselves ride the E2E relay (nx_e2e); this is the pure state logic.
8// license_tier: ORIGINAL
9
10const CS_IDLE: i64 = 0
11const CS_RINGING: i64 = 1
12const CS_CONNECTED: i64 = 2
13const CS_REJECTED: i64 = 3
14const CS_MISSED: i64 = 4
15const CS_CANCELLED: i64 = 5
16const CS_ENDED: i64 = 6
17
18const EV_INVITE: i64 = 1
19const EV_ACCEPT: i64 = 2
20const EV_REJECT: i64 = 3
21const EV_CANCEL: i64 = 4
22const EV_TIMEOUT: i64 = 5
23const EV_HANGUP: i64 = 6
24
25func cs_step(state: i64, ev: i64) -> i64 {
26 if state == CS_IDLE { if ev == EV_INVITE { return CS_RINGING } return CS_IDLE }
27 if state == CS_RINGING {
28 if ev == EV_ACCEPT { return CS_CONNECTED }
29 if ev == EV_REJECT { return CS_REJECTED }
30 if ev == EV_CANCEL { return CS_CANCELLED }
31 if ev == EV_TIMEOUT { return CS_MISSED }
32 return CS_RINGING // any stray event -> STILL ringing (no accidental dismiss)
33 }
34 if state == CS_CONNECTED { if ev == EV_HANGUP { return CS_ENDED } return CS_CONNECTED }
35 return state // REJECTED/MISSED/CANCELLED/ENDED are terminal (sticky)
36}
37// the callee should be actively ringing/notified in this state
38func cs_is_ringing(state: i64) -> i64 { if state == CS_RINGING { return 1 } return 0 }
39// a persistent missed-call record the callee must still see (notification never silently dropped)
40func cs_is_missed(state: i64) -> i64 { if state == CS_MISSED { return 1 } return 0 }
41// the call is live (media flows)
42func cs_is_connected(state: i64) -> i64 { if state == CS_CONNECTED { return 1 } return 0 }