Adding some missing functionality
This commit is contained in:
parent
d6c5275895
commit
f373131b34
@ -24,5 +24,7 @@ ipcMain.on('basic-action', (event, action, ...args: any[]) => {
|
|||||||
window.webContents.openDevTools();
|
window.webContents.openDevTools();
|
||||||
} else if(action === "reload-window") {
|
} else if(action === "reload-window") {
|
||||||
window.reload();
|
window.reload();
|
||||||
|
} else if(action === "quit") {
|
||||||
|
window.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
@ -231,6 +231,7 @@ async function loadCachedOrRemoteUiPack(channel: string, callbackStatus: (messag
|
|||||||
const requiredClientVersion = parseVersion(remoteVersion.requiredClientVersion);
|
const requiredClientVersion = parseVersion(remoteVersion.requiredClientVersion);
|
||||||
if(requiredClientVersion.newerThan(clientVersion) && !is_debug) {
|
if(requiredClientVersion.newerThan(clientVersion) && !is_debug) {
|
||||||
/* We can't use the newer version. Use the latest available. Update prompt should come when starting the client */
|
/* We can't use the newer version. Use the latest available. Update prompt should come when starting the client */
|
||||||
|
console.log("Ignoring remote version since our client is too old to use it. Required client: %s, Client version: %s", remoteVersion.requiredClientVersion, clientVersion.toString());
|
||||||
} else if(remoteVersion.timestamp <= newestLocalVersion && !ignoreNewVersionTimestamp) {
|
} else if(remoteVersion.timestamp <= newestLocalVersion && !ignoreNewVersionTimestamp) {
|
||||||
/* We've already a equal or newer version. Don't use the remote version */
|
/* We've already a equal or newer version. Don't use the remote version */
|
||||||
/* if remote is older than current bundled version its not a drop since it could be used as a fallback */
|
/* if remote is older than current bundled version its not a drop since it could be used as a fallback */
|
||||||
|
@ -1,78 +1,6 @@
|
|||||||
import * as native from "tc-native/connection";
|
import * as native from "tc-native/connection";
|
||||||
import {AudioBackend, OutputDevice} from "tc-shared/audio/Player";
|
import {AudioBackend, OutputDevice} from "tc-shared/audio/Player";
|
||||||
|
|
||||||
//FIXME: Native audio initialize handle!
|
|
||||||
export interface Device {
|
|
||||||
device_id: string;
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
let _initialized_callbacks: (() => any)[] = [];
|
|
||||||
export let _initialized = false;
|
|
||||||
export let _initializing = false;
|
|
||||||
export let _current_device: native.audio.AudioDevice;
|
|
||||||
|
|
||||||
export function initialized() : boolean {
|
|
||||||
return _initialized;
|
|
||||||
}
|
|
||||||
export function on_ready(cb: () => any) {
|
|
||||||
if(_initialized)
|
|
||||||
cb();
|
|
||||||
else
|
|
||||||
_initialized_callbacks.push(cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function initialize() {
|
|
||||||
if(_initializing) return;
|
|
||||||
_initializing = true;
|
|
||||||
|
|
||||||
native.audio.initialize(() => {
|
|
||||||
_initialized = true;
|
|
||||||
for(const callback of _initialized_callbacks)
|
|
||||||
callback();
|
|
||||||
_initialized_callbacks = [];
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function available_devices() : Promise<Device[]> {
|
|
||||||
return native.audio.available_devices().filter(e => e.output_supported || e.output_default);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function set_device(device_id?: string) : Promise<void> {
|
|
||||||
const dev = native.audio.available_devices().filter(e => e.device_id == device_id);
|
|
||||||
if(dev.length == 0) {
|
|
||||||
console.warn("Missing audio device with is %s", device_id);
|
|
||||||
throw "invalid device id";
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
native.audio.playback.set_device(dev[0].device_id);
|
|
||||||
} catch(error) {
|
|
||||||
if(error instanceof Error)
|
|
||||||
throw error.message;
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
_current_device = dev[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function current_device() : Device {
|
|
||||||
if(_current_device)
|
|
||||||
return _current_device;
|
|
||||||
|
|
||||||
const dev = native.audio.available_devices().filter(e => e.output_default);
|
|
||||||
if(dev.length > 0)
|
|
||||||
return dev[0];
|
|
||||||
return {device_id: "default", name: "default"} as Device;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function get_master_volume() : number {
|
|
||||||
return native.audio.playback.get_master_volume();
|
|
||||||
}
|
|
||||||
export function set_master_volume(volume: number) {
|
|
||||||
native.audio.playback.set_master_volume(volume);
|
|
||||||
}
|
|
||||||
|
|
||||||
export class NativeAudioPlayer implements AudioBackend {
|
export class NativeAudioPlayer implements AudioBackend {
|
||||||
private readonly audioContext: AudioContext;
|
private readonly audioContext: AudioContext;
|
||||||
private initializedPromises: (() => void)[];
|
private initializedPromises: (() => void)[];
|
||||||
@ -112,7 +40,20 @@ export class NativeAudioPlayer implements AudioBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getAvailableDevices(): Promise<OutputDevice[]> {
|
async getAvailableDevices(): Promise<OutputDevice[]> {
|
||||||
return native.audio.available_devices().filter(e => e.output_supported || e.output_default).map(entry => ({
|
const devices = native.audio.available_devices().filter(e => e.output_supported || e.output_default);
|
||||||
|
/* Fixup MMEs character limit of 31 by trying to resolve a name somewhere else */
|
||||||
|
devices.forEach(device => {
|
||||||
|
if(device.driver !== "MME") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fallback = devices.find(fallbackDevice => fallbackDevice.name.substring(0, 31) === device.name && fallbackDevice.name.length > 31);
|
||||||
|
if(fallback) {
|
||||||
|
device.name = fallback.name;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return devices.map(entry => ({
|
||||||
device_id: entry.device_id,
|
device_id: entry.device_id,
|
||||||
driver: entry.driver,
|
driver: entry.driver,
|
||||||
name: entry.name
|
name: entry.name
|
||||||
|
@ -65,7 +65,8 @@ class InputDeviceList extends AbstractDeviceList {
|
|||||||
if(fallback) {
|
if(fallback) {
|
||||||
device.name = fallback.name;
|
device.name = fallback.name;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
this.setState("healthy");
|
this.setState("healthy");
|
||||||
return this.cachedDevices;
|
return this.cachedDevices;
|
||||||
}
|
}
|
||||||
|
@ -513,7 +513,9 @@ void AudioOutput::fill_buffer(void *output, size_t out_frame_count, size_t out_c
|
|||||||
|
|
||||||
void AudioOutput::set_device(const std::shared_ptr<AudioDevice> &new_device) {
|
void AudioOutput::set_device(const std::shared_ptr<AudioDevice> &new_device) {
|
||||||
lock_guard lock(this->device_lock);
|
lock_guard lock(this->device_lock);
|
||||||
if(this->device == new_device) return;
|
if(this->device == new_device) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this->close_device();
|
this->close_device();
|
||||||
this->device = new_device;
|
this->device = new_device;
|
||||||
@ -537,7 +539,9 @@ bool AudioOutput::playback(std::string& error) {
|
|||||||
error = "invalid device handle";
|
error = "invalid device handle";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(this->playback_) return true;
|
if(this->playback_) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
this->playback_ = this->device->playback();
|
this->playback_ = this->device->playback();
|
||||||
if(!this->playback_) {
|
if(!this->playback_) {
|
||||||
|
@ -99,14 +99,13 @@ NAN_METHOD(player::set_playback_device) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto null_device = info[0]->IsNullOrUndefined();
|
if(info.Length() != 1 || !info[0]->IsString()) {
|
||||||
if(info.Length() != 1 || !(info[0]->IsString() || null_device)) {
|
|
||||||
Nan::ThrowError("invalid arguments");
|
Nan::ThrowError("invalid arguments");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto device = null_device ? nullptr : audio::find_device_by_id(*Nan::Utf8String(info[0]), false);
|
auto device = audio::find_device_by_id(*Nan::Utf8String(info[0]), false);
|
||||||
if(!device && !null_device) {
|
if(!device) {
|
||||||
Nan::ThrowError("invalid device id");
|
Nan::ThrowError("invalid device id");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user