How to access a development server powered by VueCLI from a smartphone in your local network and handle media (such as a microphone)

Asked 1 years ago, Updated 1 years ago, 284 views

I would like to handle the sound of microphones connected to smartphones and PCs within a web application configured with VueCLI.I would like to access the development server built on the development PC from my iPhone or other PC from within the local network to check the movement, but I cannot handle the microphone on any device other than the development PC.I checked and found that HTTPS needs to set up a server, so it may work well in production, but would it be difficult to access media such as audio and video on other devices in the local network during development?

javascript vuejs

2022-11-16 18:45

1 Answers

Would you like to use the secure context in your local development environment?Of course it's possible.

First, an API such as MediaDevices.getUserMedia() indicated in the questionnaire requires a Secure Context, which can be used primarily in the following environments, as described in MDN:

  • Locally distributed resources
    • http://127.0.0.1 (loopback address)
    • http://localhost, http://*.localhost (domain guaranteed to point to loopback address)
  • Resources through TLS
    • Origin starting with https://
  • http://127.0.0.1 (loopback address)
  • http://localhost, http://*.localhost (domain guaranteed to point to loopback address)
  • Origin starting with https://

You can use the variables available at the global scope, window.isSecureContext to see if the current page is affected.

By the way, what if the certificate is incorrect (ignoring the warning screen, such as domain mismatch or expiration)?Apparently, this is accepted as a secure context.

Now, based on the above, you will roughly do one of the following:

  • Access via localhost from a remote device
  • Access the page using https

Let's take an overview of each of these examples.

This is done by port forwarding.It forwards the local port of the remote machine (client) and the port of the host (developer).

For Android Chrome

For Android Chrome, this is easy to do with the features provided by Chrome's remote debugging.

When using SSH

Modern PCs can use OpenSSH on both Windows and macOS.Allows port forwarding over SSH.It seems that there are several applications that enable this on iOS devices.I will omit the details here.

There are two main approaches.

  • Portforward to services that provide an entrance for https
  • Waiting at https using the Ore certificate (self-signed certificate) on the development machine (in VueCLI here)

Using External Services

You can wait at https with external service and forward your request to the development machine.A famous service that can do this is ngrok.
One caveat is that anyone who knows the address can access it.(For free plans)

Register and follow the instructions on the dashboard to download and set up ngrok for port forwarding.

Using the Ore Certificate

I've been writing a series of troubling methods so far, but the vue-cli actually supports serving at https.You don't have to worry about preparing a certificate.

Simply add --https to the vue-cli-service serve option.

For example, if you normally start the server with yarn serve, you can start the server with https using the Ore certificate by simply tapping the command like yarn serve--https, or npm run serve.


2022-11-17 00:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.