mirror of
https://github.com/koush/scrypted.git
synced 2026-02-10 09:12:03 +00:00
server: fix plugin default export when device is a class or function. fix pluginId state missing.
This commit is contained in:
4
server/package-lock.json
generated
4
server/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/server",
|
||||
"version": "0.0.168",
|
||||
"version": "0.0.169",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/server",
|
||||
"version": "0.0.168",
|
||||
"version": "0.0.169",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@mapbox/node-pre-gyp": "^1.0.8",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@scrypted/server",
|
||||
"version": "0.0.168",
|
||||
"version": "0.0.169",
|
||||
"description": "",
|
||||
"dependencies": {
|
||||
"@mapbox/node-pre-gyp": "^1.0.8",
|
||||
|
||||
@@ -561,16 +561,17 @@ export function attachPluginRemote(peer: RpcPeer, options?: PluginRemoteAttachOp
|
||||
try {
|
||||
peer.evalLocal(script, zipOptions?.filename || '/plugin/main.nodejs.js', params);
|
||||
pluginConsole?.log('plugin successfully loaded');
|
||||
await options?.onPluginReady?.(ret, params, exports.default);
|
||||
|
||||
const defaultExport = exports.default;
|
||||
let pluginInstance = exports.default;
|
||||
// support exporting a plugin class, plugin main function,
|
||||
// or a plugin instance
|
||||
if (defaultExport.toString().startsWith('class '))
|
||||
return new defaultExport();
|
||||
if (typeof defaultExport === 'function')
|
||||
return await defaultExport();
|
||||
return defaultExport;
|
||||
if (pluginInstance.toString().startsWith('class '))
|
||||
pluginInstance = new pluginInstance();
|
||||
if (typeof pluginInstance === 'function')
|
||||
pluginInstance = await pluginInstance();
|
||||
|
||||
await options?.onPluginReady?.(ret, params, pluginInstance);
|
||||
return pluginInstance;
|
||||
}
|
||||
catch (e) {
|
||||
pluginConsole?.error('plugin failed to start', e);
|
||||
|
||||
@@ -125,6 +125,8 @@ export class SystemManagerImpl implements SystemManager {
|
||||
getDeviceByName(name: string): any {
|
||||
for (const id of Object.keys(this.state)) {
|
||||
const s = this.state[id];
|
||||
if ((s.interfaces?.value as string[])?.includes(ScryptedInterface.ScryptedPlugin) && s.pluginId?.value === name)
|
||||
return this.getDeviceById(id);
|
||||
if (s.name.value === name)
|
||||
return this.getDeviceById(id);
|
||||
}
|
||||
|
||||
@@ -765,7 +765,8 @@ export class ScryptedRuntime extends PluginHttp<HttpPluginData> {
|
||||
setState(pluginDevice, ScryptedInterfaceProperty.providedInterfaces, PluginDeviceProxyHandler.sortInterfaces(interfaces));
|
||||
}
|
||||
|
||||
if (!pluginDevice.pluginId) {
|
||||
const pluginId: string = getState(pluginDevice, ScryptedInterfaceProperty.pluginId);
|
||||
if (!pluginId) {
|
||||
dirty = true;
|
||||
setState(pluginDevice, ScryptedInterfaceProperty.pluginId, pluginDevice.pluginId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user