Download this file
| 1 | package callscore |
| 2 | |
| 3 | import ( |
| 4 | "sync" |
| 5 | |
| 6 | "amadan.net/oficina/calls/protocol" |
| 7 | ) |
| 8 | |
| 9 | // The app this core is running in, as spec §15.28 has every app say on |
| 10 | // its requests (protocol.ClientHeader): "mac 0.4.12". Set once by the |
| 11 | // host before it joins; nothing is sent until it has been, which is how |
| 12 | // an app from before §15.28 looks to the server, and the server calls |
| 13 | // that "native". |
| 14 | var client struct { |
| 15 | sync.Mutex |
| 16 | label string |
| 17 | } |
| 18 | |
| 19 | // SetClient records the host app and its version. An app that is not |
| 20 | // one protocol.ParseClient knows, or a version that is not digits and |
| 21 | // dots, is refused and leaves nothing set. |
| 22 | func SetClient(app, version string) bool { |
| 23 | label := app + " " + version |
| 24 | if parsed, _, ok := protocol.ParseClient(label); !ok || parsed == protocol.ClientNative { |
| 25 | return false |
| 26 | } |
| 27 | client.Lock() |
| 28 | client.label = label |
| 29 | client.Unlock() |
| 30 | return true |
| 31 | } |
| 32 | |
| 33 | // ClientLabel is what SetClient recorded, or "". |
| 34 | func ClientLabel() string { |
| 35 | client.Lock() |
| 36 | defer client.Unlock() |
| 37 | return client.label |
| 38 | } |
| 39 | |
| 40 | // RefreshICE asks the core for a fresh /ice answer now rather than at the |
| 41 | // schedule's time (spec §15.28: a connection about to be restarted on |
| 42 | // relay credentials that are due for renewal renews them first). The |
| 43 | // answer arrives as the usual "ice" event; nothing happens before |
| 44 | // admission, as for any fetch. |
| 45 | func (r *Room) RefreshICE() { |
| 46 | select { |
| 47 | case r.iceWake <- struct{}{}: |
| 48 | default: |
| 49 | } |
| 50 | } |
| 51 | |