Add macOS iOS Android companion platform client wrappers
This commit is contained in:
@@ -0,0 +1,248 @@
|
||||
import type {
|
||||
CompanionRuntimeClient,
|
||||
NodeCapabilitiesResult,
|
||||
NodeLocationGetResult,
|
||||
NodeLocationSetResult,
|
||||
NodeRegisterResult,
|
||||
NodeStatusSetResult,
|
||||
NodePushTokenSetResult,
|
||||
SetNodeLocationInput,
|
||||
SystemCapabilitiesResult,
|
||||
SystemNodesResult,
|
||||
} from './runtimeClient.js';
|
||||
|
||||
export interface PlatformClientOptions {
|
||||
runtime: CompanionRuntimeClient;
|
||||
nodeId: string;
|
||||
role?: string;
|
||||
capabilities?: string[];
|
||||
protocolVersion?: number;
|
||||
}
|
||||
|
||||
export interface RegisterPushTokenInput {
|
||||
token: string;
|
||||
topic?: string;
|
||||
environment?: 'sandbox' | 'production';
|
||||
}
|
||||
|
||||
export type SharedStatusInput = Omit<
|
||||
Parameters<CompanionRuntimeClient['setNodeStatus']>[0],
|
||||
'platform'
|
||||
>;
|
||||
|
||||
export class MacOSCompanionClient {
|
||||
private readonly runtime: CompanionRuntimeClient;
|
||||
private readonly nodeId: string;
|
||||
private readonly role: string;
|
||||
private readonly capabilities: string[];
|
||||
private readonly protocolVersion?: number;
|
||||
|
||||
constructor(options: PlatformClientOptions) {
|
||||
this.runtime = options.runtime;
|
||||
this.nodeId = options.nodeId;
|
||||
this.role = options.role ?? 'companion';
|
||||
this.capabilities = options.capabilities ?? ['ui.canvas', 'node.location.write', 'node.push.register'];
|
||||
this.protocolVersion = options.protocolVersion;
|
||||
}
|
||||
|
||||
connect(): Promise<void> {
|
||||
return this.runtime.connect();
|
||||
}
|
||||
|
||||
disconnect(): void {
|
||||
this.runtime.disconnect();
|
||||
}
|
||||
|
||||
register(): Promise<NodeRegisterResult> {
|
||||
return this.runtime.registerNode({
|
||||
nodeId: this.nodeId,
|
||||
role: this.role,
|
||||
protocolVersion: this.protocolVersion,
|
||||
capabilities: this.capabilities,
|
||||
});
|
||||
}
|
||||
|
||||
getCapabilities(): Promise<NodeCapabilitiesResult> {
|
||||
return this.runtime.getNodeCapabilities();
|
||||
}
|
||||
|
||||
setStatus(status: SharedStatusInput): Promise<NodeStatusSetResult> {
|
||||
return this.runtime.setNodeStatus({
|
||||
platform: 'macos',
|
||||
appVersion: status.appVersion,
|
||||
deviceName: status.deviceName,
|
||||
statusText: status.statusText,
|
||||
batteryPct: status.batteryPct,
|
||||
powerSource: status.powerSource,
|
||||
});
|
||||
}
|
||||
|
||||
setLocation(location: SetNodeLocationInput): Promise<NodeLocationSetResult> {
|
||||
return this.runtime.setNodeLocation(location);
|
||||
}
|
||||
|
||||
getLocation(): Promise<NodeLocationGetResult> {
|
||||
return this.runtime.getNodeLocation();
|
||||
}
|
||||
|
||||
registerPushToken(input: RegisterPushTokenInput): Promise<NodePushTokenSetResult> {
|
||||
return this.runtime.setNodePushToken({
|
||||
provider: 'apns',
|
||||
token: input.token,
|
||||
topic: input.topic,
|
||||
environment: input.environment,
|
||||
});
|
||||
}
|
||||
|
||||
getSystemCapabilities(): Promise<SystemCapabilitiesResult> {
|
||||
return this.runtime.getSystemCapabilities();
|
||||
}
|
||||
|
||||
listNodes(): Promise<SystemNodesResult> {
|
||||
return this.runtime.listSystemNodes({ platform: 'macos', role: this.role });
|
||||
}
|
||||
}
|
||||
|
||||
export class IOSCompanionClient {
|
||||
private readonly runtime: CompanionRuntimeClient;
|
||||
private readonly nodeId: string;
|
||||
private readonly role: string;
|
||||
private readonly capabilities: string[];
|
||||
private readonly protocolVersion?: number;
|
||||
|
||||
constructor(options: PlatformClientOptions) {
|
||||
this.runtime = options.runtime;
|
||||
this.nodeId = options.nodeId;
|
||||
this.role = options.role ?? 'companion';
|
||||
this.capabilities = options.capabilities ?? ['node.location.write', 'node.push.register'];
|
||||
this.protocolVersion = options.protocolVersion;
|
||||
}
|
||||
|
||||
connect(): Promise<void> {
|
||||
return this.runtime.connect();
|
||||
}
|
||||
|
||||
disconnect(): void {
|
||||
this.runtime.disconnect();
|
||||
}
|
||||
|
||||
register(): Promise<NodeRegisterResult> {
|
||||
return this.runtime.registerNode({
|
||||
nodeId: this.nodeId,
|
||||
role: this.role,
|
||||
protocolVersion: this.protocolVersion,
|
||||
capabilities: this.capabilities,
|
||||
});
|
||||
}
|
||||
|
||||
getCapabilities(): Promise<NodeCapabilitiesResult> {
|
||||
return this.runtime.getNodeCapabilities();
|
||||
}
|
||||
|
||||
setStatus(status: SharedStatusInput): Promise<NodeStatusSetResult> {
|
||||
return this.runtime.setNodeStatus({
|
||||
platform: 'ios',
|
||||
appVersion: status.appVersion,
|
||||
deviceName: status.deviceName,
|
||||
statusText: status.statusText,
|
||||
batteryPct: status.batteryPct,
|
||||
powerSource: status.powerSource,
|
||||
});
|
||||
}
|
||||
|
||||
setLocation(location: SetNodeLocationInput): Promise<NodeLocationSetResult> {
|
||||
return this.runtime.setNodeLocation(location);
|
||||
}
|
||||
|
||||
getLocation(): Promise<NodeLocationGetResult> {
|
||||
return this.runtime.getNodeLocation();
|
||||
}
|
||||
|
||||
registerPushToken(input: RegisterPushTokenInput): Promise<NodePushTokenSetResult> {
|
||||
return this.runtime.setNodePushToken({
|
||||
provider: 'apns',
|
||||
token: input.token,
|
||||
topic: input.topic,
|
||||
environment: input.environment,
|
||||
});
|
||||
}
|
||||
|
||||
getSystemCapabilities(): Promise<SystemCapabilitiesResult> {
|
||||
return this.runtime.getSystemCapabilities();
|
||||
}
|
||||
|
||||
listNodes(): Promise<SystemNodesResult> {
|
||||
return this.runtime.listSystemNodes({ platform: 'ios', role: this.role });
|
||||
}
|
||||
}
|
||||
|
||||
export class AndroidCompanionClient {
|
||||
private readonly runtime: CompanionRuntimeClient;
|
||||
private readonly nodeId: string;
|
||||
private readonly role: string;
|
||||
private readonly capabilities: string[];
|
||||
private readonly protocolVersion?: number;
|
||||
|
||||
constructor(options: PlatformClientOptions) {
|
||||
this.runtime = options.runtime;
|
||||
this.nodeId = options.nodeId;
|
||||
this.role = options.role ?? 'companion';
|
||||
this.capabilities = options.capabilities ?? ['node.location.write', 'node.push.register'];
|
||||
this.protocolVersion = options.protocolVersion;
|
||||
}
|
||||
|
||||
connect(): Promise<void> {
|
||||
return this.runtime.connect();
|
||||
}
|
||||
|
||||
disconnect(): void {
|
||||
this.runtime.disconnect();
|
||||
}
|
||||
|
||||
register(): Promise<NodeRegisterResult> {
|
||||
return this.runtime.registerNode({
|
||||
nodeId: this.nodeId,
|
||||
role: this.role,
|
||||
protocolVersion: this.protocolVersion,
|
||||
capabilities: this.capabilities,
|
||||
});
|
||||
}
|
||||
|
||||
getCapabilities(): Promise<NodeCapabilitiesResult> {
|
||||
return this.runtime.getNodeCapabilities();
|
||||
}
|
||||
|
||||
setStatus(status: SharedStatusInput): Promise<NodeStatusSetResult> {
|
||||
return this.runtime.setNodeStatus({
|
||||
platform: 'android',
|
||||
appVersion: status.appVersion,
|
||||
deviceName: status.deviceName,
|
||||
statusText: status.statusText,
|
||||
batteryPct: status.batteryPct,
|
||||
powerSource: status.powerSource,
|
||||
});
|
||||
}
|
||||
|
||||
setLocation(location: SetNodeLocationInput): Promise<NodeLocationSetResult> {
|
||||
return this.runtime.setNodeLocation(location);
|
||||
}
|
||||
|
||||
getLocation(): Promise<NodeLocationGetResult> {
|
||||
return this.runtime.getNodeLocation();
|
||||
}
|
||||
|
||||
registerPushToken(token: string): Promise<NodePushTokenSetResult> {
|
||||
return this.runtime.setNodePushToken({
|
||||
provider: 'fcm',
|
||||
token,
|
||||
});
|
||||
}
|
||||
|
||||
getSystemCapabilities(): Promise<SystemCapabilitiesResult> {
|
||||
return this.runtime.getSystemCapabilities();
|
||||
}
|
||||
|
||||
listNodes(): Promise<SystemNodesResult> {
|
||||
return this.runtime.listSystemNodes({ platform: 'android', role: this.role });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user