1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
mod common;
/// /data api bindings
pub mod data;
/// Definition of errors occur in this crate
pub mod error;
/// /media api bindings
pub mod media;
/// /peers api bindings
pub mod peer;
/// A "prelude" for users of this crate.
pub mod prelude;

use std::sync::Once;

static mut BASE_URL: String = String::new();
static INIT: Once = Once::new();
static INIT_CHECK: Once = Once::new();

/// Initialize this crate with base url of WebRTC Gateway.
pub fn initialize(base_url: impl Into<String>) {
    unsafe {
        INIT.call_once(|| {
            BASE_URL = base_url.into();
        });
    }
}

//use crate::common::{MyId, MySocket, PhantomId};
pub(crate) fn base_url() -> &'static str {
    unsafe {
        INIT_CHECK.call_once(|| {
            if BASE_URL.len() == 0 {
                panic!("not initialized");
            }
        });
        &BASE_URL
    }
}