Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 65 additions & 10 deletions types/webvr-api/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
// Type definitions for WebVR API
// Project: https://w3c.github.io/webvr/
// Definitions by: six a <https://github.com/lostfictions>
// Definitions by: efokschaner <https://github.com/efokschaner>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

// Typescript doesn't allow redefinition of type aliases even if they match,
// thus the _dt_alias to signal this being an alias for the use of DefinitelyTyped
type VRDisplayEventReason_dt_alias = "mounted" | "navigation" | "requested" | "unmounted";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are these defined? Can you just change the originals?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nm this is in lib.dom.d.ts. I had no idea this stuff was built-in to the browser.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're defined in https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es6.d.ts

We wouldn't want to change those. Think of this typing as a backport of the official definitions for TS versions that don't yet have them. And these typings in here need to work even when the official definitions are visible and doing it this way works. The type alias' don't conflict nor do the functions they're used by.


// Typescript doesn't allow redefinition of type aliases even if they match,
// thus the _dt_alias to signal this being an alias for the use of DefinitelyTyped
type VREye_dt_alias = "left" | "right";

interface VRDisplay extends EventTarget {
/**
Expand Down Expand Up @@ -55,7 +62,7 @@ interface VRDisplay extends EventTarget {
exitPresent(): Promise<void>;

/* Return the current VREyeParameters for the given eye. */
getEyeParameters(whichEye: string): VREyeParameters;
getEyeParameters(whichEye: VREye_dt_alias): VREyeParameters;

/**
* Populates the passed VRFrameData with the information required to render
Expand All @@ -69,6 +76,7 @@ interface VRDisplay extends EventTarget {
getLayers(): VRLayer[];

/**
* @deprecated
* Return a VRPose containing the future predicted pose of the VRDisplay
* when the current frame will be presented. The value returned will not
* change until JavaScript has returned control to the browser.
Expand Down Expand Up @@ -138,6 +146,11 @@ interface VRDisplayCapabilities {
readonly maxLayers: number;
}

declare var VRDisplayCapabilities: {
prototype: VRDisplayCapabilities;
new(): VRDisplayCapabilities;
};

interface VREyeParameters {
/** @deprecated */
readonly fieldOfView: VRFieldOfView;
Expand All @@ -146,13 +159,23 @@ interface VREyeParameters {
readonly renderWidth: number;
}

declare var VREyeParameters: {
prototype: VREyeParameters;
new(): VREyeParameters;
};

interface VRFieldOfView {
readonly downDegrees: number;
readonly leftDegrees: number;
readonly rightDegrees: number;
readonly upDegrees: number;
}

declare var VRFieldOfView: {
prototype: VRFieldOfView;
new(): VRFieldOfView;
};

interface VRFrameData {
readonly leftProjectionMatrix: Float32Array;
readonly leftViewMatrix: Float32Array;
Expand All @@ -163,9 +186,9 @@ interface VRFrameData {
}

declare var VRFrameData: {
prototype: VRFrameData
new(): VRFrameData
}
prototype: VRFrameData;
new(): VRFrameData;
};

interface VRPose {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not make VRDisplayCapabalities, VREyeParameters, VRFieldOfView, VRPose and VRFrameData declare class instead? You could just change the interface lines and get rid of the new declare vars entirely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think i've done it precisely the same as they are in https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es6.d.ts

So although I agree it's a weird pattern I see no reason not to match the official defs to avoid confusion.

Does that seem sound?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. :)

readonly angularAcceleration: Float32Array | null;
Expand All @@ -177,6 +200,11 @@ interface VRPose {
readonly timestamp: number;
}

declare var VRPose: {
prototype: VRPose;
new(): VRPose;
};

interface VRStageParameters {
sittingToStandingTransform?: Float32Array;
sizeX?: number;
Expand All @@ -188,13 +216,40 @@ interface Navigator {
readonly activeVRDisplays: ReadonlyArray<VRDisplay>;
}

interface VRDisplayEventInit extends EventInit {
display: VRDisplay;
reason?: VRDisplayEventReason_dt_alias;
}

interface VRDisplayEvent extends Event {
readonly display: VRDisplay;
readonly reason: VRDisplayEventReason_dt_alias | null;
}

declare var VRDisplayEvent: {
prototype: VRDisplayEvent;
new(type: string, eventInitDict: VRDisplayEventInit): VRDisplayEvent;
};

interface Window {
onvrdisplayconnected: ((this: Window, ev: Event) => any) | null;
onvrdisplaydisconnected: ((this: Window, ev: Event) => any) | null;
onvrdisplayactivate: ((this: Window, ev: Event) => any) | null;
onvrdisplayblur: ((this: Window, ev: Event) => any) | null;
onvrdisplayconnect: ((this: Window, ev: Event) => any) | null;
onvrdisplaydeactivate: ((this: Window, ev: Event) => any) | null;
onvrdisplaydisconnect: ((this: Window, ev: Event) => any) | null;
onvrdisplayfocus: ((this: Window, ev: Event) => any) | null;
onvrdisplaypointerrestricted: ((this: Window, ev: Event) => any) | null;
onvrdisplaypointerunrestricted: ((this: Window, ev: Event) => any) | null;
onvrdisplaypresentchange: ((this: Window, ev: Event) => any) | null;
addEventListener(type: "vrdisplayconnected", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "vrdisplaydisconnected", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "vrdisplaypresentchange", listener: (ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "vrdisplayactivate", listener: (this: Window, ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "vrdisplayblur", listener: (this: Window, ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "vrdisplayconnect", listener: (this: Window, ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "vrdisplaydeactivate", listener: (this: Window, ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "vrdisplaydisconnect", listener: (this: Window, ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "vrdisplayfocus", listener: (this: Window, ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "vrdisplaypointerrestricted", listener: (this: Window, ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "vrdisplaypointerunrestricted", listener: (this: Window, ev: Event) => any, useCapture?: boolean): void;
addEventListener(type: "vrdisplaypresentchange", listener: (this: Window, ev: Event) => any, useCapture?: boolean): void;
}

interface Gamepad {
Expand Down