James Kuszmaul | 4a42b18 | 2021-01-17 11:32:46 -0800 | [diff] [blame] | 1 | #include "helper/handler.h" |
| 2 | #include "helper/utils.h" |
| 3 | #include <rawrtc.h> |
| 4 | #include <rawrtcc.h> |
| 5 | #include <rawrtcdc.h> |
| 6 | #include <re.h> |
| 7 | |
| 8 | #define DEBUG_MODULE "ice-gatherer-app" |
| 9 | #define DEBUG_LEVEL 7 |
| 10 | #include <re_dbg.h> |
| 11 | |
| 12 | /* |
| 13 | * Print the ICE gatherer's state. Stop once complete. |
| 14 | */ |
| 15 | static void gatherer_state_change_handler( |
| 16 | enum rawrtc_ice_gatherer_state const state, // read-only |
| 17 | void* const arg // will be casted to `struct client*` |
| 18 | ) { |
| 19 | default_ice_gatherer_state_change_handler(state, arg); |
| 20 | if (state == RAWRTC_ICE_GATHERER_STATE_COMPLETE) { |
| 21 | re_cancel(); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | int main(int argc, char* argv[argc + 1]) { |
| 26 | struct rawrtc_ice_gather_options* gather_options; |
| 27 | struct rawrtc_ice_gatherer* gatherer; |
| 28 | char* const turn_zwuenf_org_urls[] = {"stun:turn.zwuenf.org"}; |
| 29 | char* const stun_google_com_ip_urls[] = {"stun:[2a00:1450:400c:c08::7f]:19302", |
| 30 | "stun:74.125.140.127:19302"}; |
| 31 | char* const unreachable_urls[] = {"stun:example.com:12345", |
| 32 | "stun:lets.assume.no-one-will-ever-register-this"}; |
| 33 | struct client client = {0}; |
| 34 | (void) argv; |
| 35 | |
| 36 | // Debug |
| 37 | dbg_init(DBG_DEBUG, DBG_ALL); |
| 38 | DEBUG_PRINTF("Init\n"); |
| 39 | |
| 40 | // Initialise |
| 41 | EOE(rawrtc_init(true)); |
| 42 | |
| 43 | // Create ICE gather options |
| 44 | EOE(rawrtc_ice_gather_options_create(&gather_options, RAWRTC_ICE_GATHER_POLICY_ALL)); |
| 45 | |
| 46 | // Add ICE servers to ICE gather options |
| 47 | EOE(rawrtc_ice_gather_options_add_server( |
| 48 | gather_options, turn_zwuenf_org_urls, ARRAY_SIZE(turn_zwuenf_org_urls), NULL, NULL, |
| 49 | RAWRTC_ICE_CREDENTIAL_TYPE_NONE)); |
| 50 | EOE(rawrtc_ice_gather_options_add_server( |
| 51 | gather_options, stun_google_com_ip_urls, ARRAY_SIZE(stun_google_com_ip_urls), NULL, NULL, |
| 52 | RAWRTC_ICE_CREDENTIAL_TYPE_NONE)); |
| 53 | EOE(rawrtc_ice_gather_options_add_server( |
| 54 | gather_options, unreachable_urls, ARRAY_SIZE(unreachable_urls), NULL, NULL, |
| 55 | RAWRTC_ICE_CREDENTIAL_TYPE_NONE)); |
| 56 | |
| 57 | // Setup client |
| 58 | client.name = "A"; |
| 59 | |
| 60 | // Create ICE gatherer |
| 61 | EOE(rawrtc_ice_gatherer_create( |
| 62 | &gatherer, gather_options, gatherer_state_change_handler, |
| 63 | default_ice_gatherer_error_handler, default_ice_gatherer_local_candidate_handler, &client)); |
| 64 | |
| 65 | // Start gathering |
| 66 | EOE(rawrtc_ice_gatherer_gather(gatherer, NULL)); |
| 67 | |
| 68 | // Start main loop |
| 69 | EOR(re_main(default_signal_handler)); |
| 70 | |
| 71 | // Close gatherer |
| 72 | EOE(rawrtc_ice_gatherer_close(gatherer)); |
| 73 | |
| 74 | // Un-reference & close |
| 75 | mem_deref(gatherer); |
| 76 | mem_deref(gather_options); |
| 77 | |
| 78 | // Bye |
| 79 | before_exit(); |
| 80 | return 0; |
| 81 | } |