Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Initial thoughts #1

Merged
merged 3 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
237 changes: 235 additions & 2 deletions mixer.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,240 @@
declare module 'mixer' {
import { EventEmitter } from 'eventemitter3';
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to write these again? I know we're refactoring but we already have them elsewhere. I guess if we tidy up later its fine :)

Copy link
Contributor Author

@connor4312 connor4312 Aug 12, 2017

Choose a reason for hiding this comment

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

EventEmitter stuff? Or .d.ts?

My idea was that we'd keep this .d.ts (maybe autogen it later) and have it as an external in webpack. This removes even the necessity for developers to use a module loader if they don't want to.

For the eventemitter stuff, there's events as polyfilled by webpack but the version they use is super out of date again Node and also pretty hefty. Also I have a crush Arnout Kazemier. ee3 is great.

Copy link
Contributor

@ProbablePrime ProbablePrime Aug 12, 2017

Choose a reason for hiding this comment

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

I meant I<InteractiveWordThing>. Also another note about event emitter later on thanks for the info.

As a side note(not a reccomendation to actually use): https://github.com/developit/mitt :P, same dev as preact. I love preact developer's work its all small and coool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More importantly ee3 is very well-maintained and tested in a wide matrix of browsers (displayed in their readme) whereas the built-in one is not. I still have an open PR from forever ago to update it browserify/events#32

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that seems neat! I kind of prefer to use one that matches the Node API though 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Absoloutely in this case, Mitt is briefer and suffers with lack of matching API. It was just a general "Let's share cool stuff" comment. :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

definitely!


/**
* IControl is some kind of control on the protocol. The controlID is
* unique in the scene.
*
* This is a minimal interface: control types may extend this interface
* and define their own properties.
*/
export interface IControl {
readonly controlID: string;
readonly kind: string;
}

/**
* IScene is a scene on the protocol. It can contain many controls. The
* sceneID is globally unique.
*
* This is a minimal interface: scenes may extend this interface
* and define their own properties.
*/
export interface IScene {
readonly sceneID: string;
readonly controls: IControl[];
}

/**
* IGroup is a groups of participants on the protocol. Groups are assigned
* to a single scene.
*
* This is a minimal interface: integrations may extend this interface
* and define their own properties.
*/
export interface IGroup {
readonly sceneID: string;
readonly groupID: string;
}

/**
* ISceneCreate is an event triggered when a new scene is created.
*/
export interface ISceneCreate {
readonly scenes: IScene[];
}

/**
* ISceneUpdate is an event triggered when a an existing scene is updated.
*/
export interface ISceneUpdate {
Copy link
Contributor

Choose a reason for hiding this comment

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

Im tempted to say events should be past tense,

"ISceneUpdated" makes more sense with the doc comment

readonly scenes: IScene[];
}

/**
* ISceneDelete is an event triggered when a scene is deleted.
*/
export interface ISceneDelete {
readonly sceneID: string;
readonly reassignSceneID: string;
}

/**
* IControlChange is fired when new controls are created, updated, or
* deleted in the scene.
*/
export interface IControlChange {
readonly sceneID: string;
readonly controls: IControl[];
}

/**
* IGroupDelete is an event triggered when a group is deleted.
*/
export interface IGroupDelete {
readonly groupID: string;
readonly reassignGroupID: string;
}

/**
* IGroupCreate is fired when new groups are created.
*/
export interface IGroupCreate {
readonly groups: IGroup[];
}

/**
* IGroupUpdate is fired when groups are updated.
*/
export interface IGroupUpdate {
readonly groups: IGroup[];
}

/**
* IParticipant represents a user in Interactive. As far as controls are
* concerned, this means only the current user.
*
* This is a minimal interface: integrations may extend this interface
* and define their own properties.
*/
export interface IParticipant {
readonly sessionID: string;
readonly userID: number;
readonly username: string;
readonly level: number;
readonly lastInputAt: number; // milliseconds timestamp
readonly connectedAt: number; // milliseconds timestamp
readonly disabled: boolean;
readonly groupID: string;
}

/**
* IParticipantUpdate is fired when the participant's data is updated,
* and once when first connecting.
*/
export interface IParticipantUpdate {
readonly participants: [IParticipant];
}

/**
* IInput is an input event fired on a control. This is a minimal
* interface; custom properties may be added and they will be passed
* through to the game client.
*/
export interface IInput {
controlID: string;
event: string;
}

/**
* IReady is sent when when the integration indicates that it has set up
* and is ready to accept input.
*/
export interface IReady {
readonly isReady: boolean;
}

/**
* Attaches a handler function that will be triggered when the call comes in.
*/
export function on(call: string, data: any): void;
}
export interface Socket extends EventEmitter {
on(event: 'onParticipantJoin', handler: (ev: IParticipantUpdate) => void): this;
on(event: 'onParticipantUpdate', handler: (ev: IParticipantUpdate) => void): this;
on(event: 'onGroupCreate', handler: (ev: IGroupCreate) => void): this;
on(event: 'onGroupDelete', handler: (ev: IGroupDelete) => void): this;
on(event: 'onGroupUpdate', handler: (ev: IGroupUpdate) => void): this;
on(event: 'onSceneCreate', handler: (ev: ISceneCreate) => void): this;
on(event: 'onSceneDelete', handler: (ev: ISceneDelete) => void): this;
on(event: 'onSceneUpdate', handler: (ev: ISceneUpdate) => void): this;
on(event: 'onControlCreate', handler: (ev: IControlChange) => void): this;
on(event: 'onControlDelete', handler: (ev: IControlChange) => void): this;
on(event: 'onControlUpdate', handler: (ev: IControlChange) => void): this;
on(event: 'onReady', handler: (ev: IReady) => void): this;

call(method: 'giveInput', options: IInput): void;
call(method: string, options: object): Promise<object>;
call(method: string, options: object, waitForReply: true): Promise<object>;
call(method: string, options: object, waitForReply: false): void;
}

/**
* IVideoPositionOptions are passed into display.moveVideo() to change
* where the video is shown on the screen.
*/
export interface IVideoPositionOptions {
/**
* Position of the video on screen as a percent (0 - 100) of the screen width.
* If omitted, it's not modified.
*/
x?: number;

/**
* Position of the video on screen as a percent (0 - 100) of the screen height.
* If omitted, it's not modified.
*/
y?: number;

/**
* Width of the video on screen as a percent (0 - 100) of the screen.
* If omitted, it's not modified.
*/
width?: number;

/**
* Height of the video on screen as a percent (0 - 100) of the screen.
* If omitted, it's not modified.
*/
height?: number;

/**
* Duration of the movement easing in milliseconds. Defaults to 0.
*/
duration?: number;

/**
* CSS easing function. Defaults to 'linear'.
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function
*/
easing?: string;
}

/**
* Display modified the display of interactive controls.
*/
export interface Display {
/**
* Hides the controls and displays a loading spinner, optionally
* with a custom message. This is useful for transitioning. If called
* while the controls are already minimized, it will update the message.
*/
minimize(message?: string): void;

/**
* Restores previously minimize()'d controls.
*/
maximize(): void;

/**
* Moves the position of the video on the screen.
*/
moveVideo(options: IVideoPositionOptions): void;
}

/**
* Returns the fully qualified URL to a static project asset, from the
* `src/static` folder.
*/
export function asset(...path: string[]): string;

/**
* IPackageConfig describes the configuration you write in the "interactive"
* section of your package.json. It's injected automatically when your
* controls boot.
*/
export interface IPackageConfig {

}

export const socket: Socket;
export const display: Display;
}
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --content-base build/"
},
"interactive": {
"display": {
"mode": "legacy-grid"
}
},
"author": "Connor Peet <[email protected]>",
"license": "MIT",
"dependencies": {
"decko": "^1.2.0",
"eventemitter3": "^2.0.3",
"preact": "^8.2.1"
},
"devDependencies": {
Expand Down
Loading