server: fix plugin fork mixin event bug

This commit is contained in:
Koushik Dutta
2022-08-19 12:00:04 -07:00
parent 4737cad3dd
commit d5d6e31b35
3 changed files with 17 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
import ffmpegInstaller from '@ffmpeg-installer/ffmpeg';
import { BufferConverter, DeviceManager, FFmpegInput, MediaManager, MediaObject, MediaObjectOptions, MediaStreamUrl, ScryptedInterface, ScryptedInterfaceProperty, ScryptedMimeTypes, ScryptedNativeId, SystemDeviceState, SystemManager } from "@scrypted/types";
import axios from 'axios';
import ffmpegInstaller from '@ffmpeg-installer/ffmpeg';
import fs from 'fs';
import https from 'https';
import mimeType from 'mime';
@@ -65,7 +65,19 @@ export abstract class MediaManagerBase implements MediaManager {
fromMimeType: ScryptedMimeTypes.SchemePrefix + 'file',
toMimeType: ScryptedMimeTypes.MediaObject,
convert: async (data, fromMimeType, toMimeType) => {
const filename = data.toString().substring('file:'.length);
const url = data.toString();
const filename = url.substring('file:'.length);
if (toMimeType === ScryptedMimeTypes.FFmpegInput) {
const ffmpegInput: FFmpegInput = {
url,
inputArguments: [
'-i', filename,
]
};
return this.createFFmpegMediaObject(ffmpegInput);
}
const ab = await fs.promises.readFile(filename);
const mt = mimeType.getType(data.toString());
const mo = this.createMediaObject(ab, mt);

View File

@@ -90,7 +90,7 @@ export class PluginAPIProxy extends PluginAPIManagedListeners implements PluginA
return this.api.onDeviceEvent(nativeId, eventInterface, eventData);
}
onMixinEvent(id: string, nativeId: ScryptedNativeId, eventInterface: any, eventData?: any): Promise<void> {
return this.api.onMixinEvent(nativeId, eventInterface, eventData);
return this.api.onMixinEvent(id, nativeId, eventInterface, eventData);
}
onDeviceRemoved(nativeId: string): Promise<void> {
return this.api.onDeviceRemoved(nativeId);

View File

@@ -394,13 +394,14 @@ export function startPluginRemote(pluginId: string, peerSend: (message: RpcMessa
try {
peer.evalLocal(script, zipOptions?.filename || '/plugin/main.nodejs.js', params);
pluginConsole?.log('plugin successfully loaded');
if (zipOptions?.fork) {
pluginConsole?.log('plugin forked');
const fork = exports.fork;
return fork();
}
pluginConsole?.log('plugin loaded');
let pluginInstance = exports.default;
// support exporting a plugin class, plugin main function,
// or a plugin instance