<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Takahiro</title>
    <description>The latest articles on DEV Community by Takahiro (@takahirox).</description>
    <link>https://dev.to/takahirox</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F647588%2F45e39ac1-0e04-41d4-a035-0ca09bb32497.png</url>
      <title>DEV Community: Takahiro</title>
      <link>https://dev.to/takahirox</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/takahirox"/>
    <language>en</language>
    <item>
      <title>How to test &amp;lt;model-viewer&amp;gt; on mobile and WSL2</title>
      <dc:creator>Takahiro</dc:creator>
      <pubDate>Mon, 14 Jun 2021 03:41:19 +0000</pubDate>
      <link>https://dev.to/takahirox/how-to-test-model-viewer-on-mobile-and-wsl2-f1e</link>
      <guid>https://dev.to/takahirox/how-to-test-model-viewer-on-mobile-and-wsl2-f1e</guid>
      <description>&lt;p&gt;This post is a note for running Google's &lt;a href="https://modelviewer.dev/" rel="noopener noreferrer"&gt;&amp;lt;model-viewer&amp;gt;&lt;/a&gt; server in guest WSL2 on host Windows 10 and testing it from mobile devices.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://modelviewer.dev/" rel="noopener noreferrer"&gt;&amp;lt;model-viewer&amp;gt;&lt;/a&gt; recommends to use WSL2 on Windows platform due to the dependency issues. But external mobile devices can't directly access the server running in WSL2. You need to set up port forwarding and open the port for the test.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is &amp;lt;model-viewer&amp;gt;?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://modelviewer.dev/" rel="noopener noreferrer"&gt;&amp;lt;model-viewer&amp;gt;&lt;/a&gt; is a Google's project that you can easily display interactive 3D models on the web &amp;amp; in AR with custom elements (HTML tags).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feemec6xs7eg2xdcqn1zl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feemec6xs7eg2xdcqn1zl.png" alt="&amp;lt;model-viewer&amp;gt;"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Clone and build &amp;lt;model-viewer&amp;gt;
&lt;/h2&gt;

&lt;p&gt;First, clone &lt;a href="https://github.com/google/model-viewer" rel="noopener noreferrer"&gt;the &amp;lt;model-viewer&amp;gt; GitHub repository&lt;/a&gt; and build it in your WSL2 as the instructions in the repository readme.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone --depth=1 https://github.com/google/model-viewer.git
$ cd model-viewer
$ npm install
$ npm run bootstrap
$ npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Run the web server
&lt;/h2&gt;

&lt;p&gt;Next, run the web server in WSL2. If you want to test with WebXR, you need to access the server with https protocol. Otherwise browsers disable WebXR API.&lt;/p&gt;

&lt;p&gt;Then you should first set up SSL certification and then run the server with SSL enabled.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem
$ node ./node_modules/.bin/http-server -p 8080 -c-1 -o /packages/modelviewer.dev -S -C cert.pem
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above &lt;code&gt;http-server&lt;/code&gt; command shows message like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Starting up http-server, serving ./ through https
Available on:
  https://127.0.0.1:8080
  https://xxx.xxx.xxx.xxx:8080 # Editor's note: WSL2 IP address
Hit CTRL-C to stop the server
open: https://127.0.0.1:8080/packages/modelviewer.dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, I let the guest WSL2 IP address be &lt;code&gt;xxx.xxx.xxx.xxx&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Open a web server on your host Windows 10 and access &lt;code&gt;https://xxx.xxx.xxx.xxx:8080&lt;/code&gt; to check if &amp;lt;model-viewer&amp;gt; works.&lt;/p&gt;

&lt;p&gt;Remember the WSL2 IP address for the next step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up port forwarding
&lt;/h2&gt;

&lt;p&gt;After you confirm &amp;lt;model-viewer&amp;gt; boots up in WSL2, you need to set up port forwarding from host Windows 10 to guest WSL2.&lt;/p&gt;

&lt;p&gt;Run Command prompt or Power shell as administrator in your host Windows 10, and then run the following command to set up the port forwarding.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; netsh.exe interface portproxy add v4tov4 listenport=8080 listenaddress=* connectaddress=xxx.xxx.xxx.xxx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to check if it succeeds, you can use &lt;code&gt;show&lt;/code&gt; command of &lt;code&gt;netsh&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; netsh.exe interface portproxy show all

Listen on ipv4:             Connect to ipv4:

Address         Port        Address         Port
--------------- ----------  --------------- ----------
*               8080        xxx.xxx.xxx.xxx  8080
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to delete the set up, you can use &lt;code&gt;delete&lt;/code&gt; command of &lt;code&gt;netsh&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; netsh.exe interface portproxy delete v4tov4 listenport=8080 listenaddress=* 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you finish the port forwarding set up, you need to start IP helper service with the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; sc.exe start iphlpsvc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to stop the service, you can use &lt;code&gt;stop&lt;/code&gt; command of &lt;code&gt;sc&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; sc.exe stop iphlpsvc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Open the port
&lt;/h2&gt;

&lt;p&gt;Setting up the port forwarding is not good enough. You also need to open the port for the test.&lt;/p&gt;

&lt;p&gt;Open &lt;code&gt;Windows Defender Firewall with Advanced Security&lt;/code&gt; in your host Windows 10. You can find it in the search bar placed at bottom left in the screen.&lt;/p&gt;

&lt;p&gt;In the window, select Inbound Rules in the left tab and then click the "New Rules" in the right Action tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4rta9eccklaowe2k3gge.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4rta9eccklaowe2k3gge.png" alt="Click Inbound Rules and New Rules"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Rule Type window, select Port and click Next.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0nfpiqi22ovyzsc0p3nm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0nfpiqi22ovyzsc0p3nm.png" alt="Rule Type window"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Protocol and Ports window, select TCP, set specific local ports 8080, and then click Next.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhe59xlzcm9qs8pmenfsr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhe59xlzcm9qs8pmenfsr.png" alt="Protocol and Ports window"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Action window, select Allow the connection and click Next.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyxt5kd3r5dfyokrqubfx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyxt5kd3r5dfyokrqubfx.png" alt="Action window"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Profile window, choose the option depends on your environment and click Next.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw6d19pnr561dnfq27f9r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw6d19pnr561dnfq27f9r.png" alt="Profile window"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Name window, name whatever you want and write  the description if you want. And click Finish.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdyeidefg3sa2wepf249x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdyeidefg3sa2wepf249x.png" alt="Name window"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don't forget to stop the IP helper service and close the port after you finish the test for the security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Test &amp;lt;model-viewer&amp;gt; on mobile devices
&lt;/h2&gt;

&lt;p&gt;Now it's ready for the test.&lt;/p&gt;

&lt;p&gt;Check your host Windows 10 IP address. For example you may use &lt;code&gt;ipconfig&lt;/code&gt; command. Here, I let the host Windows 10 IP address be &lt;code&gt;yyy.yyy.yyy.yyy&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Open a web browser in your mobile device which is in the same network with the host Windows 10.&lt;/p&gt;

&lt;p&gt;Enter &lt;code&gt;https://yyy.yyy.yyy.yyy:8080/packages/modelviewer.dev/&lt;/code&gt; in the URL bar. If you see an untrusted web page warning, select an ignore option.&lt;/p&gt;

&lt;p&gt;&amp;lt;model-viewer&amp;gt; starts on your mobile. Your mobile accesses the host Windows 10 and it forwards to the guest WSL2.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webxr</category>
      <category>ar</category>
    </item>
  </channel>
</rss>
