Project Complexity: ★★★★★
In this guide, we will build a Web application using the High Fidelity Spatial Audio API that has the following properties:
To accomplish these goals, we will make use of Express, a popular, fast, minimal Web framework for NodeJS. Developers use it to create dynamic Web applications, where the content of each page depends on variables such as a user's login status.
We will also make use of EJS, a simple templating language that allows a developer to generate dynamic HTML with JavaScript. We'll use EJS to pipe the securely-generated JWT into the code that each user's browser utilizes to connect to High Fidelity.
This guide builds on concepts from the Build a Simple Web App and Get a JWT guides.
Here, you will learn how to:
If you already have a High Fidelity Developer Account, you can jump straight to the next step.
Before your app can make use of the Spatial Audio API, you'll need a High Fidelity Developer Account. Sign up for an account or log in here.
If you already have an App and Space for your Express App, you can jump straight to the next step.
To authenticate our Express App with your Space, you'll first need to create an App and a Space. To do that:
Do not share the data you see on this page. It allows users to make authorized connections to your High Fidelity Spatial Audio Server.
To complete this guide, you will need to install the following software on your computer:
Next, let's create a skeleton version of a NodeJS project we'll use for development:
Create a new folder on your local disk that you'll use for development, such as C:\code\hifi-express\
.
npm init
to initialize a new NodeJS project, inputting data as prompted. The data you input isn't important for the purposes of this guide.In this guide, you don't need to install the NodeJS version of the High Fidelity Spatial Audio Client Library. The Library JavaScript code is embedded within the HTML that is served to application users via a <script>
tag.
Now, let's install all of the NodeJS dependencies used for this Express Web App project. We'll make use of these dependencies in the next steps.
express
by typing npm i express
and pressing enter.ejs
by typing npm i ejs
and pressing enter.jose
with npm install jose
jose
is a package used to create JWTs using NodeJS.Now that you have your development environment set up, you can download a .zip
file containing this project's code by clicking here.
Extract the files within to your development directory. Your development directory should now contain the following files:
index.js
http://localhost:8080
.views/index.ejs
<script>
tag that imports the JavaScript High Fidelity Spatial Audio Client Library automatically.package.json
package-lock.json
Open index.js
and fill in your APP_ID
, SPACE_ID
, and APP_SECRET
. You gained access to this information in the "Create an App and Space" step above. For reference, you can find these pieces of information in the High Fidelity Audio API Developer Console.
Finally, in the PowerShell or Terminal window you've been using, type node index.js
and press enter to execute the code. Visit http://localhost:8080 in multiple browser tabs to use the resulting Web application and explore!
In this guide, you learned how to create a dynamic Web App using the High Fidelity Spatial Audio API, Express, and EJS. You can use this guide's project as a starting point for your own dynamic applications!
For detailed technical information about the High Fidelity Spatial Audio Client API, visit the API documentation.
If you have any questions or comments, please reach out to support@highfidelity.com.