Categories
Javascript Snippets

Gesture-based controls for OBS-Studio in Virtual Reality

This Project is hosted here

Working with the applet functionality provided by OVR-Toolkit provides useful methods for in-game multi-tasking through its ability to access your minimised windows as virtual displays in the VR playspace or what I’m exploring the Chromium Embedded Framework.
Not only does OVR-Toolkit have CEF they have built an API to pull data from your VR Headset and VR Controls and this inspired me to work on this applet.

one of the many challenges with this project I wanted to tackle was making setting persistent some people may immediately think to use the steam API to store and retrieve settings but that would myself to support and maintain a database that would contain IDs and potentially fingerprintable information, so I decided to load and save a JSON Config file through JavaScript.

THIS BLOG IS ONGOING…

const downloadToFile = (content, filename, contentType) => {
  const a = document.createElement('a');
  const file = new Blob([content], {type: contentType});

  a.href= URL.createObjectURL(file);
  a.download = filename;
  a.click();

	URL.revokeObjectURL(a.href);
};

function readConfig(e){
		let files = e.files;
		//console.log(reader.readAsText(file));

		if (files.length == 0) return;

		const file = files[0];

		let reader = new FileReader();

		reader.onload = (e) => {
			const file = e.target.result;
			const lines = file.split(/\r\n|\n/);
			confige.innerHTML = lines.join('\n');
		};


		reader.onerror = (e) => alert(e.target.error.name);

		reader.readAsText(file);
}

function saveState(){
	downloadToFile(JSON.stringify(config), 'config.json', 'text/plain');
}