Part of AppLink login process

This commit is contained in:
simojenki
2021-02-21 09:35:34 +11:00
parent 302efd2878
commit c26a325ee1
20 changed files with 644 additions and 253 deletions

View File

@@ -1,22 +1,23 @@
import { SonosDevice } from "@svrooij/sonos/lib";
import { v4 as uuid } from 'uuid';
import { v4 as uuid } from "uuid";
import { MusicService, Credentials } from "../src/music_service";
import { Service, Device } from "../src/sonos";
const randomInt = (max: number) => Math.floor(Math.random() * max)
const randomIpAddress = () => `127.0.${randomInt(255)}.${randomInt(255)}`
const randomInt = (max: number) => Math.floor(Math.random() * max);
const randomIpAddress = () => `127.0.${randomInt(255)}.${randomInt(255)}`;
export const aService = (fields: Partial<Service> = {}): Service => ({
name: `Test Music Service ${uuid()}`,
sid: randomInt(500),
uri: "https://sonos.testmusic.com/",
secureUri: "https://sonos.testmusic.com/",
uri: "https://sonos-test.example.com/",
secureUri: "https://sonos-test.example.com/",
strings: {
uri: "https://sonos.testmusic.com/strings.xml",
uri: "https://sonos-test.example.com/strings.xml",
version: "22",
},
presentation: {
uri: "https://sonos.testmusic.com/presentation.xml",
uri: "https://sonos-test.example.com/presentation.xml",
version: "33",
},
pollInterval: 1200,
@@ -35,9 +36,7 @@ export function aDevice(fields: Partial<Device> = {}): Device {
};
}
export function aSonosDevice(
fields: Partial<SonosDevice> = {}
): SonosDevice {
export function aSonosDevice(fields: Partial<SonosDevice> = {}): SonosDevice {
return {
Name: `device-${uuid()}`,
GroupName: `group-${uuid()}`,
@@ -46,3 +45,33 @@ export function aSonosDevice(
...fields,
} as SonosDevice;
}
export function getAppLinkMessage() {
return {
householdId: "",
hardware: "",
osVersion: "",
sonosAppName: "",
callbackPath: "",
};
}
export class InMemoryMusicService implements MusicService {
users: Record<string, string> = {};
login({ username, password }: Credentials) {
return username != undefined && password != undefined && this.users[username] == password;
}
hasUser(credentials: Credentials) {
this.users[credentials.username] = credentials.password;
}
hasNoUsers() {
this.users = {};
}
clear() {
this.users = {};
}
}