Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.cache/
dist/
/.cache/
/dist/
/node_modules/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ mopidy = null;

### Web application

![Web demo](examples/web.png)
![Web demo](examples/web/screenshot.png)

In the `examples/` directory of the Git repo, you can find a small demo web
application using Mopidy.js. The left half of the screen shows what's
Expand All @@ -411,7 +411,7 @@ To run the demo application yourself:
5. Run `npm start` to run the demo application at http://localhost:1234/.

This setup uses hot module reloading, so any changes you do to the demo
application files, `examples/web.{html,js}`, will instantly be visible in
application files, `examples/web/*`, will instantly be visible in
your browser. Thus, this can serve as a nice playing ground to get to know
the capabilities of Mopidy and Mopidy.js.

Expand Down
2 changes: 1 addition & 1 deletion examples/mpc.js → examples/mpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Output when playing:
volume:100% repeat: off random: on single: off consume: off
*/

const Mopidy = require("../src/mopidy");
import Mopidy from "..";

const mopidy = new Mopidy({
autoConnect: false,
Expand Down
92 changes: 92 additions & 0 deletions examples/web/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
html,
body {
box-sizing: border-box;
margin: 0;
padding: 0;
height: 100%;
}

body {
background: #333;
color: #ccc;
font-family: "Roboto", "Open Sans", sans-serif;
font-size: 1.2rem;
line-height: 1.4;
}

.container {
display: grid;
grid-template-columns: 1fr 1fr;
align-content: stretch;
height: 100%;
}

.player {
grid-column: 1;
padding: 2rem;

font-weight: 300;
text-align: center;
}

.event-log {
grid-column: 2;
margin: 0;
padding: 1rem;
max-height: 100vh;
overflow: auto;

background: #444;
font-family: "Ubuntu Sans Mono", "Open Sans Mono", monospace;
font-size: 0.7rem;
line-height: 1.2;
}

h1 {
font-size: 1.4rem;
font-weight: 300;
}

button {
background: #444;
color: #ccc;
border: none;
padding: 0.4rem 0.8rem;
}

button:hover {
background: #555;
}

button:active,
button.active {
background: #999;
color: #fff;
}

code {
padding: 0.1rem;
}

.help {
margin-top: 2rem;
}

.cover {
margin: auto;
max-width: 80%;
}
.cover img {
height: auto;
max-width: 100%;
}

.controls p {
display: inline-block;
margin: 0.5rem;
text-align: center;
}

.state {
font-size: 0.8rem;
}
25 changes: 15 additions & 10 deletions examples/web.js → examples/web/app.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* global window */
/* global window, Mopidy */
/* eslint no-console:off, camelcase:off */

import Mopidy from "../src/mopidy";

const mopidy = new Mopidy({
webSocketUrl: "ws://localhost:6680/mopidy/ws",
});
Expand All @@ -12,19 +10,23 @@ window.mopidy = mopidy;

// Utilities

function el(id) {
return document.getElementById(id);
function el(id: string): HTMLElement {
const el = document.getElementById(id);
if (el === null) {
throw new Error(`Element #${id} not found`);
}
return el;
}

function hide(selector) {
function hide(selector: string): void {
document.querySelectorAll(selector).forEach((e) => {
e.hidden = true;
(e as HTMLElement).hidden = true;
});
}

function show(selector) {
function show(selector: string): void {
document.querySelectorAll(selector).forEach((e) => {
e.hidden = false;
(e as HTMLElement).hidden = false;
});
}

Expand Down Expand Up @@ -53,7 +55,7 @@ mopidy.on("websocket:outgoingMessage", (data) =>

// Player

function updatePlaybackState(state, timePosition) {
function updatePlaybackState(state, timePosition?: number) {
if (timePosition) {
el("playback-state").innerText = `${state} at ${timePosition / 1000}s`;
} else {
Expand Down Expand Up @@ -82,6 +84,9 @@ function updateCover(trackUri, images) {
}

function updateCurrentTrack(track) {
if (track === null) {
return;
}
const artists = track.artists.map((a) => a.name).join(", ");
let albumName = track.album.name;
if (track.album.date) {
Expand Down
98 changes: 3 additions & 95 deletions examples/web.html → examples/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,101 +2,9 @@
<html>
<head>
<title>Mopidy.js demo</title>
<style>
html,
body {
box-sizing: border-box;
margin: 0;
padding: 0;
height: 100%;
}

body {
background: #333;
color: #ccc;
font-family: "Roboto", "Open Sans", sans-serif;
font-size: 1.2rem;
line-height: 1.4;
}

.container {
display: grid;
grid-template-columns: 1fr 1fr;
align-content: stretch;
height: 100%;
}

.player {
grid-column: 1;
padding: 2rem;

font-weight: 300;
text-align: center;
}

.event-log {
grid-column: 2;
margin: 0;
padding: 1rem;
max-height: 100vh;
overflow: auto;

background: #444;
font-family: "Ubuntu Sans Mono", "Open Sans Mono", monospace;
font-size: 0.7rem;
line-height: 1.2;
}

h1 {
font-size: 1.4rem;
font-weight: 300;
}

button {
background: #444;
color: #ccc;
border: none;
padding: 0.4rem 0.8rem;
}

button:hover {
background: #555;
}

button:active,
button.active {
background: #999;
color: #fff;
}

code {
padding: 0.1rem;
}

.help {
margin-top: 2rem;
}

.cover {
margin: auto;
max-width: 80%;
}
.cover img {
height: auto;
max-width: 100%;
}

.controls p {
display: inline-block;
margin: 0.5rem;
text-align: center;
}

.state {
font-size: 0.8rem;
}
</style>
<script src="web.js"></script>
<link rel="stylesheet" href="app.css">
<script type="module" src="mopidy.umd.js"></script>
<script type="module" src="app.js"></script>
<script
defer
src="https://use.fontawesome.com/releases/v5.4.1/js/all.js"
Expand Down
File renamed without changes
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
projects: [
{
displayName: "Browser tests",
preset: "ts-jest",
testEnvironment: "jsdom",
setupFilesAfterEnv: ["jest-extended"],
},
{
displayName: "Node tests",
preset: "ts-jest",
testEnvironment: "node",
setupFilesAfterEnv: ["jest-extended"],
},
{
displayName: "ESLint",
preset: "ts-jest",
runner: "jest-runner-eslint",
testMatch: ["**/*.js"],
testPathIgnorePatterns: ["/dist/", "/node_modules/"],
Expand Down
Loading