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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use {VRDisplayData, VRGamepadData, VRGamepadState};

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))]
pub enum VREvent {
    Display(VRDisplayEvent),
    Gamepad(VRGamepadEvent),
}

#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))]
pub enum VRDisplayEventReason {
    Navigation,
    // The VRDisplay has detected that the user has put it on.
    Mounted,

    // The VRDisplay has detected that the user has taken it off.
    Unmounted
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))]
pub enum VRDisplayEvent {
    // Indicates that a VRDisplay has been connected.
    Connect(VRDisplayData),

    // Indicates that a VRDisplay has been disconnected.
    // param: display_id
    Disconnect(u32),

    // Indicates that something has occured which suggests the VRDisplay should be presented to
    Activate(VRDisplayData, VRDisplayEventReason),

    // Indicates that something has occured which suggests the VRDisplay should exit presentation
    Deactivate(VRDisplayData, VRDisplayEventReason),

    // Indicates that some of the VRDisplay's data has changed (eye parameters, tracking data, chaperone, ipd, etc.)
    Change(VRDisplayData),

    // Indicates that presentation to the display by the page is paused by the user agent, OS, or VR hardware
    Blur(VRDisplayData),

    // Indicates that presentation to the display by the page has resumed after being blurred.
    Focus(VRDisplayData),

    // Indicates that a VRDisplay has begun or ended VR presentation
    PresentChange(VRDisplayData, bool),

    // Indicates that VRDisplay presentation loop must be paused (i.e Android app goes to background)
    Pause(u32),

    // Indicates that VRDisplay presentation loop must be resumed (i.e Android app goes to foreground)
    Resume(u32),

    // Indicates that user has exited VRDisplay presentation (i.e. User clicked back key on android)
    Exit(u32)
}

impl Into<VREvent> for VRDisplayEvent {
    fn into(self) -> VREvent {
        VREvent::Display(self)
    }
}


#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))]
pub enum VRGamepadEvent {
    // Indicates that a VRGamepad has been connected.
    // params: name, displa_id, state
    Connect(VRGamepadData, VRGamepadState),

    // Indicates that a VRGamepad has been disconnected.
    // param: gamepad_id
    Disconnect(u32)
}

impl Into<VREvent> for VRGamepadEvent {
    fn into(self) -> VREvent {
        VREvent::Gamepad(self)
    }
}