Skip to content
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
20 changes: 20 additions & 0 deletions examples/optimizeHMDScreentop.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<html>
<head>
<title>HMD/Screentop Optimization - Leap</title>
<script src="../leap-1.1.1.js"></script>
<script>
var controller = new Leap.Controller({optimizeScreentop: true}).connect();
</script>
</head>
<body>
<button onclick="controller.setOptimizeHMD(true);">controller.setOptimizeHMD(true);</button>
<button onclick="controller.setOptimizeHMD(false);">controller.setOptimizeHMD(false);</button>
<br/>
<br/>
<button onclick="controller.setOptimizeScreentop(true);">controller.setOptimizeScreentop(true);</button>
<button onclick="controller.setOptimizeScreentop(false);">controller.setOptimizeScreentop(false);</button>
<pre>
<div id="out"></div>
</pre>
</body>
</html>
24 changes: 24 additions & 0 deletions leap-1.1.1.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ var BaseConnection = module.exports = function(opts) {
port: this.getPort(),
background: false,
optimizeHMD: false,
optimizeScreentop: false,
requestProtocolVersion: BaseConnection.defaultProtocolVersion
}, opts || {});
this.host = this.opts.host;
Expand All @@ -208,12 +209,16 @@ var BaseConnection = module.exports = function(opts) {
this.protocolVersionVerified = false;
this.background = null;
this.optimizeHMD = null;
this.optimizeScreentop = null;
this.on('ready', function() {
this.setBackground(this.opts.background);
this.setOptimizeHMD(this.opts.optimizeHMD);
this.setOptimizeScreentop(this.opts.optimizeScreentop);

if (this.opts.optimizeHMD){
console.log("Optimized for head mounted display usage.");
}else if (this.opts.optimizeScreentop){
console.log("Optimized for screentop usage.");
}else {
console.log("Optimized for desktop usage.");
}
Expand Down Expand Up @@ -249,11 +254,21 @@ BaseConnection.prototype.setBackground = function(state) {
BaseConnection.prototype.setOptimizeHMD = function(state) {
this.opts.optimizeHMD = state;
if (this.protocol && this.protocol.sendOptimizeHMD && this.optimizeHMD !== this.opts.optimizeHMD) {
if (state === true) this.optimizeScreentop = false;
this.optimizeHMD = this.opts.optimizeHMD;
this.protocol.sendOptimizeHMD(this, this.opts.optimizeHMD);
}
}

BaseConnection.prototype.setOptimizeScreentop = function(state) {
this.opts.optimizeScreentop = state;
if (this.protocol && this.protocol.sendOptimizeScreentop && this.optimizeScreentop !== this.opts.optimizeScreentop) {
if (state === true) this.optimizeHMD = false;
this.optimizeScreentop = this.opts.optimizeScreentop;
this.protocol.sendOptimizeScreentop(this, this.opts.optimizeScreentop);
}
}

BaseConnection.prototype.handleOpen = function() {
if (!this.connected) {
this.connected = true;
Expand Down Expand Up @@ -298,6 +313,7 @@ BaseConnection.prototype.disconnect = function(allowReconnect) {
delete this.protocol;
delete this.background; // This is not persisted when reconnecting to the web socket server
delete this.optimizeHMD;
delete this.optimizeScreentop;
delete this.focusedState;
if (this.connected) {
this.connected = false;
Expand Down Expand Up @@ -590,6 +606,11 @@ Controller.prototype.setOptimizeHMD = function(state) {
return this;
}

Controller.prototype.setOptimizeScreentop = function(state) {
this.connection.setOptimizeScreentop(state);
return this;
}

Controller.prototype.inBrowser = function() {
return !this.inNode;
}
Expand Down Expand Up @@ -2954,6 +2975,9 @@ exports.chooseProtocol = function(header) {
protocol.sendOptimizeHMD = function(connection, state) {
connection.send(protocol.encode({optimizeHMD: state}));
}
protocol.sendOptimizeScreentop = function(connection, state) {
connection.send(protocol.encode({optimizeScreentop: state}));
}
break;
default:
throw "unrecognized version";
Expand Down
3 changes: 1 addition & 2 deletions leap-1.1.1.min.js

Large diffs are not rendered by default.

Loading