Using Nintendo Switch Joy-Con Controllers on the Web with the WebHID API

Thomas Steiner:

WebHID allows websites to access devices that use the human interface devices (HID) protocol via JavaScript. Here is a little Christmas present 🎄 to the community to celebrate the API approval: releasing Joy-Con WebHID, a WebHID “driver” for Nintendo Joy-Con controllers so you can use them in the browser. If you have Joy-Cons, be sure to check out the demo to get a feel for what is possible.

Installation per NPM:

npm install joy-con-webhid

Once a Joy-Con has been paired, you can listen to hidinput events:

joyCon.addEventListener('hidinput', ({ detail }) => {
    // Careful, this fires at ~60fps.
    console.log(`Input report from ${joyCon.device.productName}:`, detail);
});

💡 The code does not use on the Gamepad API but the WebHID API as the former does not have support for orientation, a feature the Joy-Con controllers use extensively.

Releasing Joy-Con WebHID →
Joy-Con WebHID Repo (GitHub) →

Automatically Fix Bluetooth Audio Balance Drift in macOS with “Balance Lock”

It’s been over 10 years that I’ve been using macOS (then OS X) and every now and then I notice that the audio balance of my Bluetooth headset is off for no apparent reason.


Hmm, why is the balance for my headphone suddenly off?

Back in 2014 I was lucky enough to see this tweet by Shaun Inman float by, in which he linked to a manual solution using macOS’s built-in Audio Midi Setup.app:

Ever since then I’ve been taking those manual steps to fix it whenever the issue occurred (which is quite often).

☝️ I know, you can also do it through the System Preferences nowadays. Back then that wasn’t the case though.

~

As I encountered the issue again today, I wondered if there was no automatic way to fixing this issue. Turns out there is, with the utility app Balance Lock

Headphones a little off or noticing your audio isn’t quite centered? Balance Lock will keep your audio centered and fix the annoying left/right drift bug.

It’s simple to use and runs in the background un-intrusively.

You can find Balance Lock for free on the App Store, or install it using mas

mas install 1019371109

Come on Apple, fix this longstanding bug or Sherlock the shit out of this app 😉

Balance Lock →

💁‍♂️ I’ve also added this handy tool to ./freshinstall, a tool which I built to automatically configure macOS (Preferences, Dotfiles, Installed Software, etc).

~

Did this help you out? Like what you see?
Thank me with a coffee.

I don't do this for profit but a small one-time donation would surely put a smile on my face. Thanks!

☕️ Buy me a Coffee (€3)

To stay in the loop you can follow @bramus or follow @bramusblog on Twitter.

react-native-ble-plx – React Native Bluetooth Low Energy (BLE) library

This is React Native Bluetooth Low Energy library using RxBluetoothKit and RxAndroidBle under the hood.

scanAndConnect() {
    this.manager = new BleManager();

    // Wait for PoweredOn state

    this.manager.startDeviceScan(null, null, (error, device) => {
        if (error) {
            return;
        }

        // Check if it is a device you are looking for based on advertisement data
        // or other criteria.
        if (device.name === 'TI BLE Sensor Tag' || 
            device.name === 'SensorTag') {
            
            // Stop scanning as it's not necessary if you are scanning for one device.
            this.manager.stopDeviceScan();

            // Proceed with connection.
            device.connect()
                .then((device) => {
                    return device.discoverAllServicesAndCharacteristics()
                })
                .then((device) => {
                   // Do work on device with services and characteristics
                })
                .catch((error) => {
                    // Handle errors
                });
        }
    });
}

Damnit, now I want to take on a new React Native project where I can use this library 😅

react-native-ble-plx (GitHub) →
react-native-ble-plx Documentation →

Fly and Control a Drone Using JavaScript

Whilst the video is only a sneak peek of a Code School tutorial, you can puzzle the pieces together yourself. The key part is the rolling-spider Node package which uses Bluetooth to communicate with the drone.

var RollingSpider = require('rolling-spider');
var temporal = require('temporal');
var rollingSpider = new RollingSpider({
    uuid: 'Mambo_434915'
});

rollingSpider.connect(function() {
  rollingSpider.setup(function() {
    rollingSpider.flatTrim();
    rollingSpider.startPing();
    rollingSpider.flatTrim();

    temporal.queue([
      {
        delay: 5000,
        task: function () {
          rollingSpider.takeOff();
          rollingSpider.flatTrim();
        }
      },
      {
        delay: 3000,
        task: function () {
          rollingSpider.forward({steps: 12});
        }
      },
      {
        delay: 5000,
        task: function () {
          rollingSpider.land();
        }
      },
      {
        delay: 5000,
        task: function () {
          temporal.clear();
          process.exit(0);
        }
      }
    ]);
  });
});

Flying a drone using JavaScript →
rolling-spider (GitHub) →

Quite sure this can be rebuilt using the Web Bluetooth API, bypassing the need for a Node server.

Web Bluetooth API in Chrome

navigator.bluetooth.requestDevice({ filters: [{ services: ['battery_service'] }] })
.then(device => {
  // Human-readable name of the device.
  console.log(device.name);
  // Indicates whether or not the device is paired with the system.
  console.log(device.paired);
  // Filtered UUIDs of GATT services the website origin has access to.
  console.log(device.uuids);

  // Attempts to connect to remote GATT Server.
  return device.connectGATT();
})
.then(server => {...})
.catch(error => { console.log(error); });

Web Bluetooth API is at the time of writing partially implemented in Chrome OS M45 behind an experimental flag. [Once enabled] you should be able to scan for and connect to nearby Bluetooth devices and read/write Bluetooth characteristics.

In future releases you should also be able to subscribe to notifications and stuff like that.

Interact with BLE devices on the Web →

1Keyboard

menubar-ipad-selected

1Keyboard is a virtual bluetooth keyboard application for OS X. Turn your Mac into a Bluetooth keyboard that works with all of your devices, comfortably type on your iPhone, iPad, Apple TV or game console.

Recommended for anyone with a multitude of iDevices. Works like a charm!

1Keyboard →

Note: Make sure your AppleTV is updated to the latest version (5.2.x) to get it to work there.