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

Fix accessibility to view in webotsview #5551

Merged
merged 2 commits into from
Nov 23, 2022
Merged
Changes from 1 commit
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
91 changes: 45 additions & 46 deletions resources/web/wwi/WebotsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default class WebotsView extends HTMLElement {
#hasAnimation;
#hasScene;
#initialCallbackDone;
#view;
constructor() {
super();
this.#hasAnimation = false;
Expand Down Expand Up @@ -117,50 +116,50 @@ export default class WebotsView extends HTMLElement {
this.#closeAnimation();
else if (this.#hasScene)
this.#closeScene();
else if (typeof this.#view !== 'undefined' && typeof this.#view.stream !== 'undefined' &&
typeof this.#view.stream.socket !== 'undefined')
else if (typeof this._view !== 'undefined' && typeof this._view.stream !== 'undefined' &&
typeof this._view.stream.socket !== 'undefined')
this.#disconnect();
}

resize() {
if (typeof this.#view !== 'undefined')
this.#view.onresize();
if (typeof this._view !== 'undefined')
this._view.onresize();
}

setWebotsMessageCallback(callback) {
if (typeof this.#view !== 'undefined')
this.#view.messageCallback = callback;
if (typeof this._view !== 'undefined')
this._view.messageCallback = callback;
}

setWebotsErrorMessageCallback(callback) {
if (typeof this.#view !== 'undefined')
this.#view.errorMessageCallback = callback;
if (typeof this._view !== 'undefined')
this._view.errorMessageCallback = callback;
}

hasView() {
return typeof this.#view !== 'undefined';
return typeof this._view !== 'undefined';
}

resetViewpoint() {
if (typeof WbWorld.instance !== 'undefined' && typeof WbWorld.instance.viewpoint !== 'undefined') {
WbWorld.instance.viewpoint.resetViewpoint();
this.#view.x3dScene.render();
this._view.x3dScene.render();
}
}

// The value is updated only on the web side, do not used with simulation.
updateNode(nodeId, field, value, render) {
if (typeof nodeId === 'undefined' || typeof field === 'undefined' || typeof value === 'undefined' ||
typeof this.#view === 'undefined')
typeof this._view === 'undefined')
return;

let pose = {
'id': nodeId,
[field]: value
};
this.#view.x3dScene.applyPose(pose);
this._view.x3dScene.applyPose(pose);
if (render)
this.#view.x3dScene.render();
this._view.x3dScene.render();
}

getNode(id) {
Expand Down Expand Up @@ -197,18 +196,18 @@ export default class WebotsView extends HTMLElement {

console.time('Loaded in: ');

if (typeof this.#view === 'undefined')
this.#view = new webots.View(this, isMobileDevice);
this.#view.onready = () => {
this.toolbar = new Toolbar(this.#view, 'animation', this);
if (typeof this._view === 'undefined')
this._view = new webots.View(this, isMobileDevice);
this._view.onready = () => {
this.toolbar = new Toolbar(this._view, 'animation', this);
if (typeof this.onready === 'function')
this.onready();
};
this.#view.open(scene, 'undefined', thumbnail);
this._view.open(scene, 'undefined', thumbnail);
if (play !== 'undefined' && play === false)
this.#view.setAnimation(animation, 'pause', true);
this._view.setAnimation(animation, 'pause', true);
else
this.#view.setAnimation(animation, 'play', true);
this._view.setAnimation(animation, 'play', true);
this.#hasAnimation = true;
this.#closeWhenDOMElementRemoved();
}
Expand All @@ -230,14 +229,14 @@ export default class WebotsView extends HTMLElement {
}

#closeAnimation() {
this.#view.animation.pause();
this._view.animation.pause();
if (typeof this.toolbar !== 'undefined') {
this.toolbar.removeAnimationToolbar();
this.toolbar = undefined;
}
this.#view.removeLabels();
this.#view.destroyWorld();
this.#view.animation = undefined;
this._view.removeLabels();
this._view.destroyWorld();
this._view.animation = undefined;
this.#hasAnimation = false;
this.innerHTML = null;
}
Expand All @@ -247,8 +246,8 @@ export default class WebotsView extends HTMLElement {
}

setAnimationStepCallback(callbackFunction) {
if (typeof this.#view !== 'undefined' && typeof this.#view.animation !== 'undefined') {
this.#view.animation.stepCallback = callbackFunction;
if (typeof this._view !== 'undefined' && typeof this._view.animation !== 'undefined') {
this._view.animation.stepCallback = callbackFunction;
return true;
}
}
Expand All @@ -273,23 +272,23 @@ export default class WebotsView extends HTMLElement {
this.close();
console.time('Loaded in: ');

if (typeof this.#view === 'undefined')
this.#view = new webots.View(this, isMobileDevice);
this.#view.broadcast = broadcast;
if (typeof this._view === 'undefined')
this._view = new webots.View(this, isMobileDevice);
this._view.broadcast = broadcast;
if (typeof timeout === 'undefined')
timeout = -1; // disable timeout that stops the simulation after a given time
this.#view.setTimeout(timeout);
this._view.setTimeout(timeout);

this.#view.onready = () => {
this._view.onready = () => {
if (typeof this.toolbar === 'undefined')
this.toolbar = new Toolbar(this.#view, 'streaming', this);
this.toolbar = new Toolbar(this._view, 'streaming', this);
if (document.getElementById('robot-window-button') !== null)
document.getElementsByTagName('webots-view')[0].toolbar.loadRobotWindows();
if (typeof this.onready === 'function')
this.onready();
};
this.#view.open(server, mode, thumbnail);
this.#view.onquit = () => {
this._view.open(server, mode, thumbnail);
this._view.onquit = () => {
if (typeof this.ondisconnect === 'function')
this.ondisconnect();
};
Expand All @@ -306,10 +305,10 @@ export default class WebotsView extends HTMLElement {
this.toolbar.removeStreamingToolbar();
this.toolbar = undefined;
}
this.#view.close();
this._view.close();
this.innerHTML = null;
if (this.#view.mode === 'mjpeg')
this.#view.multimediaClient = undefined;
if (this._view.mode === 'mjpeg')
this._view.multimediaClient = undefined;

if (typeof this.ondisconnect === 'function')
this.ondisconnect();
Expand All @@ -326,8 +325,8 @@ export default class WebotsView extends HTMLElement {
}

sendMessage(message) {
if (typeof this.#view !== 'undefined' && this.#view.stream.socket.readyState === 1)
this.#view.stream.socket.send(message);
if (typeof this._view !== 'undefined' && this._view.stream.socket.readyState === 1)
this._view.stream.socket.send(message);
}

// Scene functions
Expand All @@ -344,15 +343,15 @@ export default class WebotsView extends HTMLElement {

console.time('Loaded in: ');

if (typeof this.#view === 'undefined')
this.#view = new webots.View(this, isMobileDevice);
if (typeof this._view === 'undefined')
this._view = new webots.View(this, isMobileDevice);

this.#view.onready = () => {
this.toolbar = new Toolbar(this.#view, 'scene', this);
this._view.onready = () => {
this.toolbar = new Toolbar(this._view, 'scene', this);
if (typeof this.onready === 'function')
this.onready();
};
this.#view.open(scene, 'undefined', thumbnail);
this._view.open(scene, 'undefined', thumbnail);
this.#hasScene = true;
this.#closeWhenDOMElementRemoved();
}
Expand All @@ -367,7 +366,7 @@ export default class WebotsView extends HTMLElement {
this.toolbar.removeToolbar();
this.toolbar = undefined;
}
this.#view.destroyWorld();
this._view.destroyWorld();
this.#hasScene = false;
this.innerHTML = null;
}
Expand Down