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
13 changes: 11 additions & 2 deletions src/device/protocol/buttplugIo/buttplugIoDeviceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,20 @@ export default class ButtplugIoDeviceFactory

private readonly logger: Logger;

public constructor(uuidFactory: UuidFactory, dateFactory: DateFactory, settings: Settings, logger: Logger) {
private readonly useDeviceNameAsId: boolean;

public constructor(
uuidFactory: UuidFactory,
dateFactory: DateFactory,
settings: Settings,
logger: Logger,
useDeviceNameAsId: boolean
) {
this.uuidFactory = uuidFactory;
this.dateFactory = dateFactory;
this.settings = settings;
this.logger = logger;
this.useDeviceNameAsId = useDeviceNameAsId;
}

public create(buttplugDevice: ButtplugClientDevice, provider: string): ButtplugIoDevice {
Expand Down Expand Up @@ -86,7 +95,7 @@ export default class ButtplugIoDeviceFactory
private createKnownDevice(buttplugDevice: ButtplugClientDevice, provider: string): KnownDevice {
// Since we don't get a unique identifier for the Bluetooth device from Intiface,
// we need to use the index assigned to the device by Intiface. It's the best we have.
const deviceId = `buttplugio-${buttplugDevice.index}`;
const deviceId = `buttplugio-${this.useDeviceNameAsId ? buttplugDevice.name : buttplugDevice.index}`;
let knownDevice = this.settings.getKnownDeviceById(deviceId)

if (null !== knownDevice) {
Expand Down
32 changes: 32 additions & 0 deletions src/device/protocol/buttplugIo/buttplugIoDeviceFactoryFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import ButtplugIoDeviceFactory from "./buttplugIoDeviceFactory.js";
import UuidFactory from "../../../factory/uuidFactory.js";
import Logger from "../../../logging/Logger.js";
import DateFactory from "../../../factory/dateFactory.js";
import Settings from "../../../settings/settings.js";
import {ButtplugIoWebsocketConfig} from "./buttplugIoWebsocketDeviceProvider.js";

export default class ButtplugIoDeviceFactoryFactory
{
private readonly uuidFactory: UuidFactory;
private readonly dateFactory: DateFactory;
private readonly settings: Settings;
private readonly logger: Logger;

public constructor(uuidFactory: UuidFactory, dateFactory: DateFactory, settings: Settings, logger: Logger) {
this.uuidFactory = uuidFactory;
this.dateFactory = dateFactory;
this.settings = settings;
this.logger = logger;
}

public create(config: ButtplugIoWebsocketConfig): ButtplugIoDeviceFactory
{
return new ButtplugIoDeviceFactory(
this.uuidFactory,
this.dateFactory,
this.settings,
this.logger,
config.useDeviceNameAsId
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import ButtplugIoDeviceFactory from "./buttplugIoDeviceFactory.js";
import Logger from "../../../logging/Logger.js";
import DeviceProviderEvent from "../../provider/deviceProviderEvent.js";

export type ButtplugIoWebsocketConfig = {
address: string,
useDeviceNameAsId: boolean,
}

export default class ButtplugIoWebsocketDeviceProvider extends DeviceProvider
{
public static readonly name = 'buttplugIoWebsocket';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,33 @@
import DeviceProvider from "../../provider/deviceProvider.js";
import EventEmitter from "events";
import SerialDeviceTransportFactory from "../../transport/serialDeviceTransportFactory.js";
import DeviceProviderFactory from "../../provider/deviceProviderFactory.js";
import Logger from "../../../logging/Logger.js";
import ButtplugIoDeviceFactory from "./buttplugIoDeviceFactory.js";
import ButtplugIoWebsocketDeviceProvider from "./buttplugIoWebsocketDeviceProvider.js";

type ButtplugIoWebsocketConfig = {
address: string,
}
import ButtplugIoWebsocketDeviceProvider, {ButtplugIoWebsocketConfig} from "./buttplugIoWebsocketDeviceProvider.js";
import ButtplugIoDeviceFactoryFactory from "./buttplugIoDeviceFactoryFactory.js";

export default class ButtplugIoWebsocketDeviceProviderFactory implements DeviceProviderFactory
{
private readonly eventEmitter: EventEmitter;

private readonly deviceFactory: ButtplugIoDeviceFactory;

private readonly deviceTransportFactory: SerialDeviceTransportFactory;
private readonly deviceFactoryFactory: ButtplugIoDeviceFactoryFactory;

private readonly logger: Logger;

public constructor(
eventEmitter: EventEmitter,
deviceFactory: ButtplugIoDeviceFactory,
deviceFactoryFactory: ButtplugIoDeviceFactoryFactory,
logger: Logger
) {
this.eventEmitter = eventEmitter;
this.deviceFactory = deviceFactory;
this.deviceFactoryFactory = deviceFactoryFactory;
this.logger = logger;
}

public create(config: ButtplugIoWebsocketConfig): DeviceProvider
{
return new ButtplugIoWebsocketDeviceProvider(
this.eventEmitter,
this.deviceFactory,
this.deviceFactoryFactory.create(config),
config.address,
this.logger
);
Expand Down
1 change: 0 additions & 1 deletion src/device/provider/deviceProviderFactory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import DeviceProvider from "./deviceProvider.js";
import {JsonObject} from "../../types.js";

export default interface DeviceProviderFactory
{
Expand Down
2 changes: 2 additions & 0 deletions src/serviceMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import GetLogController from "./controller/automation/getLogController.js";
import RunScriptController from "./controller/automation/runScriptController.js";
import StopScriptController from "./controller/automation/stopScriptController.js";
import StatusScriptController from "./controller/automation/statusScriptController.js";
import ButtplugIoDeviceFactoryFactory from "./device/protocol/buttplugIo/buttplugIoDeviceFactoryFactory.js";

/* eslint-disable @typescript-eslint/naming-convention */
type ServiceMap = {
Expand All @@ -50,6 +51,7 @@ type ServiceMap = {
'device.serial.factory.slvCtrlPlus': SlvCtrlPlusDeviceFactory,
'device.provider.factory.buttplugIoWebsocket': DeviceProviderFactory,
'device.serial.factory.buttplugIo': ButtplugIoDeviceFactory,
'device.factory.factory.buttplugIo': ButtplugIoDeviceFactoryFactory,
'device.uniqueNameGenerator': DeviceNameGenerator,
'device.updater': DeviceUpdaterInterface,

Expand Down
12 changes: 2 additions & 10 deletions src/serviceProvider/deviceServiceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import SlvCtrlPlusSerialDeviceProvider from "../device/protocol/slvCtrlPlus/slvC
import ButtplugIoWebsocketDeviceProvider from "../device/protocol/buttplugIo/buttplugIoWebsocketDeviceProvider.js";
import ButtplugIoWebsocketDeviceProviderFactory
from "../device/protocol/buttplugIo/buttplugIoWebsocketDeviceProviderFactory.js";
import ButtplugIoDeviceFactory from "../device/protocol/buttplugIo/buttplugIoDeviceFactory.js";
import ButtplugIoDevice from "../device/protocol/buttplugIo/buttplugIoDevice.js";
import ButtplugIoDeviceUpdater from "../device/protocol/buttplugIo/buttplugIoDeviceUpdater.js";
import ServiceMap from "../serviceMap.js";
Expand All @@ -45,8 +44,8 @@ export default class DeviceServiceProvider implements ServiceProvider<ServiceMap
'device.provider.factory.buttplugIoWebsocket',
() => new ButtplugIoWebsocketDeviceProviderFactory(
new EventEmitter(),
container.get('device.serial.factory.buttplugIo'),
container.get('logger.default'),
container.get('device.factory.factory.buttplugIo'),
container.get('logger.default')
)
);

Expand All @@ -73,13 +72,6 @@ export default class DeviceServiceProvider implements ServiceProvider<ServiceMap
container.get('logger.default'),
));

container.set('device.serial.factory.buttplugIo', () => new ButtplugIoDeviceFactory(
container.get('factory.uuid'),
container.get('factory.date'),
container.get('settings'),
container.get('logger.default'),
));

container.set('device.updater', () => {
const plainToClass = container.get('serializer.plainToClass');
const deviceUpdater = new DelegateDeviceUpdater();
Expand Down
1 change: 0 additions & 1 deletion src/settings/deviceSource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Exclude, Expose} from "class-transformer";
import {JsonObject} from "../types.js";

@Exclude()
export default class DeviceSource
Expand Down
1 change: 0 additions & 1 deletion src/settings/knownDevice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {Exclude, Expose} from "class-transformer";
import {JsonObject} from "../types.js";

@Exclude()
export default class KnownDevice
Expand Down