Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FEC-8046): 360 Support #1

Merged
merged 16 commits into from
Jun 20, 2018
Merged

feat(FEC-8046): 360 Support #1

merged 16 commits into from
Jun 20, 2018

Conversation

yairans
Copy link
Contributor

@yairans yairans commented Jun 11, 2018

src/vr.js Outdated
*/
_addBindings(): void {
this.eventManager.listen(this.player, this.player.Event.SOURCE_SELECTED, () => {
if (this.player.is360()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be source attribute, not player

Copy link
Contributor

Choose a reason for hiding this comment

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

If we do it as player we should abstract it more and get change name to VR as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@OrenMe what do u mean 'abstract it more'?

src/vr.js Outdated
this.eventManager.listen(
this.player,
this.player.Event.FIRST_PLAY,
this._initComponents.bind(this)
Copy link
Contributor

Choose a reason for hiding this comment

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

you can use () => ... as the eventManager saves reference internally to callbacks and we call destroy on event manager which clears them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/vr.js Outdated
_appendCanvasOverlayAction(): void {
this._canvasOverlayAction = document.createElement('div');
this._canvasOverlayAction.id = CANVAS_360_OVERLAY_ID;
this.player.getView().appendChild(this._canvasOverlayAction);
Copy link
Contributor

Choose a reason for hiding this comment

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

use playkit-js utils for DOM manipulation

Copy link
Contributor

Choose a reason for hiding this comment

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

for all of above actions

Copy link
Contributor

Choose a reason for hiding this comment

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

didn't we say this will be abstracted away form the plugin and managed as an API? with the controller interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/vr.js Outdated
this._renderer = new THREE.WebGLRenderer();
this._canvas = this._renderer.domElement;
Utils.Dom.addClassName(this._canvas, CANVAS_360_CLASS);
this.player.getView().insertBefore(this._canvas, videoElement.nextSibling);
Copy link
Contributor

Choose a reason for hiding this comment

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

use playkit-js utils for DOM manipulation, add method if missing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/vr.js Outdated
this._scene = new THREE.Scene();
this._scene.add(sphere);

// this.effect = new THREE.StereoEffect(this._renderer);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/vr.js Outdated
* @returns {void}
*/
destroy(): void {
this.reset();
Copy link
Contributor

Choose a reason for hiding this comment

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

a bit strange that on destroy we call reset which in turn calls _initMembers and _addBindings

Copy link
Contributor

Choose a reason for hiding this comment

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

@yairans please comment to this.
on destroy you don't want to re-register the source selected event

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/vr.js Outdated
* @returns {void}
*/
reset(): void {
this.player.getView().removeChild(this._canvas);
Copy link
Contributor

Choose a reason for hiding this comment

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

use playkit-js utils removeChild

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/vr.js Outdated
*/
reset(): void {
this.player.getView().removeChild(this._canvas);
this._canvasOverlayAction.parentNode.removeChild(this._canvasOverlayAction);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here on removeChild

src/vr.js Outdated
});
this.eventManager.listen(window, 'mouseup', this._onDocumentPointerUp.bind(this));
this.eventManager.listen(window, 'touchend', this._onDocumentPointerUp.bind(this));
this.eventManager.listen(window, 'devicemotion', this._onDeviceMotion.bind(this));
Copy link
Contributor

Choose a reason for hiding this comment

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

You can check for support before registering window.DeviceMotionEvent
Ref: https://developers.google.com/web/fundamentals/native-hardware/device-orientation/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/vr.js Outdated
this.eventManager.listen(window, 'mouseup', this._onDocumentPointerUp.bind(this));
this.eventManager.listen(window, 'touchend', this._onDocumentPointerUp.bind(this));
this.eventManager.listen(window, 'devicemotion', this._onDeviceMotion.bind(this));
this.eventManager.listen(window, 'deviceorientation', this._onMobileOrientation.bind(this));
Copy link
Contributor

Choose a reason for hiding this comment

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

You can check for support before registering window.DeviceOrientationEvent
Ref: https://developers.google.com/web/fundamentals/native-hardware/device-orientation/

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this method even exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

src/index.js Outdated
declare var __VERSION__: string;
declare var __NAME__: string;

export default Vr;
Copy link
Contributor

Choose a reason for hiding this comment

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

Plz use our new conventions

  1. No default exports
  2. Export plugin class as Plugin
    export {Vr as Plugin}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/style.css Outdated
height: 100%;
}

.indicator {
Copy link
Contributor

Choose a reason for hiding this comment

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

add playkit- prefix to all classes to avoid collisions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

irrelevant

src/vr.js Outdated
* Your class description.
* @classdesc
*/
export default class Vr extends BasePlugin {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use new conventions without default export

class Vr { .. }
export {Vr};

Copy link
Contributor

Choose a reason for hiding this comment

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

please follow @dan-ziv 's comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/vr.js Outdated
if (this.player.is360()) {
this.logger.debug('360 entry has detected');
this._appendCanvasOverlayAction();
this.eventManager.listen(this.player, this.player.Event.FIRST_PLAY, this._initComponents.bind(this));
Copy link
Contributor

Choose a reason for hiding this comment

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

Use arrow function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

output: {
path: __dirname + '/dist',
filename: '[name].js',
library: ['playkit', 'vr'],
Copy link
Contributor

Choose a reason for hiding this comment

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

library: ['playkit', 'plugins', 'vr'],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/vr.js Outdated
if (this.player.env.browser.name === 'IE') {
// a workaround for ie11 texture issue
// see https://github.com/mrdoob/three.js/issues/7560
const ctx2d = document.createElement('canvas').getContext('2d');
Copy link
Contributor

Choose a reason for hiding this comment

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

use playkit utils for DOM manipulation

Copy link
Contributor

Choose a reason for hiding this comment

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

also, you don't seem to destroy/remove it anywhere
and give it an id...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@OrenMe this element not attached to the dom but used by THREE.Texture

src/vr.js Outdated
* Your class description.
* @classdesc
*/
export default class Vr extends BasePlugin {
Copy link
Contributor

Choose a reason for hiding this comment

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

please follow @dan-ziv 's comment

clearColor: 0xffffff,
antialias: true
});
const canvas = this._renderer.domElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

don't see this gets removed from DOM on cleanup anywhere

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, now I see you do....

src/vr.js Outdated
* @returns {boolean} - Whether the plugin is valid.
*/
static isValid(): boolean {
return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this always valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

src/vr.js Outdated
* @returns {void}
*/
destroy(): void {
this.reset();
Copy link
Contributor

Choose a reason for hiding this comment

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

@yairans please comment to this.
on destroy you don't want to re-register the source selected event

src/vr.js Outdated
}
}

_getCanvasDimensions(): Object {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe define the dimensions object?

type dimensions = {
   width: number,
   height: number
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/vr.js Outdated
this._texture.render(videoElement);
}
}
this._requestId = requestAnimationFrame(this._render.bind(this));
Copy link
Contributor

Choose a reason for hiding this comment

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

better use some abbreviation - it is usually referred to as RAF so you can change to rafId

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/vr.js Outdated
}

_onPlay(): void {
if (!this._requestId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this condition is not clear

Copy link
Contributor Author

@yairans yairans Jun 20, 2018

Choose a reason for hiding this comment

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

a comment has been added

src/vr.js Outdated

toggleStereoMode(): void {
this._stereoMode = !this._stereoMode;
this._updateCanvasSize();
Copy link
Contributor

Choose a reason for hiding this comment

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

if this will be externlized as API need to add protection if plugin is active and able to go to stereo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_updateCanvasSize is already protected

}

_updateCanvasSize(): void {
if (this._renderer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any way the renderer can be not defined when calling this?
The only place I see this happening is when calling toggleStereoMode and there is where you need to add protection

Copy link
Contributor Author

Choose a reason for hiding this comment

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

flow requires this protection

src/vr.js Outdated
this.eventManager.listen(this.player, this.player.Event.ENDED, this._cancelAnimationFrame.bind(this));
this.eventManager.listen(this.player, this.player.Event.PLAY, this._onPlay.bind(this));
this.eventManager.listen(this.player, this.player.Event.PLAYING, this._onPlaying.bind(this));
this.eventManager.listen(window, 'resize', () => this._updateCanvasSize());
Copy link
Contributor

Choose a reason for hiding this comment

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

don't you need to add fullscreen event listener as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fullscreen fires resize

src/vr.js Outdated
* @returns {void}
*/
_initComponents(): void {
this.logger.debug('Init 360 components');
Copy link
Contributor

Choose a reason for hiding this comment

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

init VR components :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/vr.js Outdated
* @type {string}
* @const
*/
const CANVAS_360_CLASS: string = 'playkit-360-canvas';
Copy link
Contributor

Choose a reason for hiding this comment

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

CANVAS_VR_CLASS, playkit-vr-canvas

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

src/vr.js Outdated
import './style.css';

/**
* The 360 canvas class.
Copy link
Contributor

Choose a reason for hiding this comment

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

VR

@yairans yairans merged commit 65d7856 into master Jun 20, 2018
@yairans yairans deleted the FEC-8046 branch June 20, 2018 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants