Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.

Commit 4bb6dec

Browse files
fix: optional methods in video conf providers not being handled correctly (#785)
Co-authored-by: Pierre Lehnen <[email protected]>
1 parent aec2401 commit 4bb6dec

File tree

3 files changed

+47
-30
lines changed

3 files changed

+47
-30
lines changed
Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// deno-lint-ignore-file no-explicit-any
22
import { assertEquals, assertObjectMatch } from 'https://deno.land/[email protected]/assert/mod.ts';
33
import { beforeEach, describe, it } from 'https://deno.land/[email protected]/testing/bdd.ts';
4-
import { spy } from "https://deno.land/[email protected]/testing/mock.ts";
4+
import { spy } from 'https://deno.land/[email protected]/testing/mock.ts';
55

66
import { AppObjectRegistry } from '../../AppObjectRegistry.ts';
77
import videoconfHandler from '../videoconference-handler.ts';
8-
import { assertInstanceOf } from "https://deno.land/[email protected]/assert/assert_instance_of.ts";
9-
import { JsonRpcError } from "jsonrpc-lite";
8+
import { assertInstanceOf } from 'https://deno.land/[email protected]/assert/assert_instance_of.ts';
9+
import { JsonRpcError } from 'jsonrpc-lite';
1010

1111
describe('handlers > videoconference', () => {
1212
// deno-lint-ignore no-unused-vars
@@ -16,15 +16,18 @@ describe('handlers > videoconference', () => {
1616
// deno-lint-ignore no-unused-vars
1717
const mockMethodWithTwoParam = (call: any, user: any, read: any, modify: any, http: any, persis: any): Promise<string> => Promise.resolve('ok two');
1818
// deno-lint-ignore no-unused-vars
19-
const mockMethodWithThreeParam = (call: any, user: any, options: any, read: any, modify: any, http: any, persis: any): Promise<string> => Promise.resolve('ok three');
19+
const mockMethodWithThreeParam = (call: any, user: any, options: any, read: any, modify: any, http: any, persis: any): Promise<string> =>
20+
Promise.resolve('ok three');
2021
const mockProvider = {
2122
empty: mockMethodWithoutParam,
2223
one: mockMethodWithOneParam,
2324
two: mockMethodWithTwoParam,
2425
three: mockMethodWithThreeParam,
2526
notAFunction: true,
26-
error: () => { throw new Error('Method execution error example') }
27-
}
27+
error: () => {
28+
throw new Error('Method execution error example');
29+
},
30+
};
2831

2932
beforeEach(() => {
3033
AppObjectRegistry.clear();
@@ -36,9 +39,9 @@ describe('handlers > videoconference', () => {
3639

3740
const result = await videoconfHandler('videoconference:test-provider:empty', []);
3841

39-
assertEquals(result, 'ok none')
42+
assertEquals(result, 'ok none');
4043
assertEquals(_spy.calls[0].args.length, 4);
41-
44+
4245
_spy.restore();
4346
});
4447

@@ -47,7 +50,7 @@ describe('handlers > videoconference', () => {
4750

4851
const result = await videoconfHandler('videoconference:test-provider:one', ['call']);
4952

50-
assertEquals(result, 'ok one')
53+
assertEquals(result, 'ok one');
5154
assertEquals(_spy.calls[0].args.length, 5);
5255
assertEquals(_spy.calls[0].args[0], 'call');
5356

@@ -59,7 +62,7 @@ describe('handlers > videoconference', () => {
5962

6063
const result = await videoconfHandler('videoconference:test-provider:two', ['call', 'user']);
6164

62-
assertEquals(result, 'ok two')
65+
assertEquals(result, 'ok two');
6366
assertEquals(_spy.calls[0].args.length, 6);
6467
assertEquals(_spy.calls[0].args[0], 'call');
6568
assertEquals(_spy.calls[0].args[1], 'user');
@@ -72,7 +75,7 @@ describe('handlers > videoconference', () => {
7275

7376
const result = await videoconfHandler('videoconference:test-provider:three', ['call', 'user', 'options']);
7477

75-
assertEquals(result, 'ok three')
78+
assertEquals(result, 'ok three');
7679
assertEquals(_spy.calls[0].args.length, 7);
7780
assertEquals(_spy.calls[0].args[0], 'call');
7881
assertEquals(_spy.calls[0].args[1], 'user');
@@ -84,34 +87,36 @@ describe('handlers > videoconference', () => {
8487
it('correctly handles an error on execution of a videoconf method', async () => {
8588
const result = await videoconfHandler('videoconference:test-provider:error', []);
8689

87-
assertInstanceOf(result, JsonRpcError)
90+
assertInstanceOf(result, JsonRpcError);
8891
assertObjectMatch(result, {
8992
message: 'Method execution error example',
90-
code: -32000
91-
})
92-
})
93+
code: -32000,
94+
});
95+
});
9396

9497
it('correctly handles an error when provider is not found', async () => {
95-
const providerName = 'error-provider'
98+
const providerName = 'error-provider';
9699
const result = await videoconfHandler(`videoconference:${providerName}:method`, []);
97100

98-
assertInstanceOf(result, JsonRpcError)
101+
assertInstanceOf(result, JsonRpcError);
99102
assertObjectMatch(result, {
100103
message: `Provider ${providerName} not found`,
101-
code: -32000
102-
})
103-
})
104+
code: -32000,
105+
});
106+
});
104107

105108
it('correctly handles an error if method is not a function of provider', async () => {
106-
const methodName = 'notAFunction'
107-
const providerName = 'test-provider'
109+
const methodName = 'notAFunction';
110+
const providerName = 'test-provider';
108111
const result = await videoconfHandler(`videoconference:${providerName}:${methodName}`, []);
109112

110-
assertInstanceOf(result, JsonRpcError)
113+
assertInstanceOf(result, JsonRpcError);
111114
assertObjectMatch(result, {
112-
message: `Method ${methodName} not found on provider ${providerName}`,
113-
code: -32000
114-
})
115-
})
116-
115+
message: 'Method not found',
116+
code: -32601,
117+
data: {
118+
message: `Method ${methodName} not found on provider ${providerName}`,
119+
},
120+
});
121+
});
117122
});

deno-runtime/handlers/videoconference-handler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export default async function videoConferenceHandler(call: string, params: unkno
1818
const method = provider[methodName as keyof IVideoConfProvider];
1919

2020
if (typeof method !== 'function') {
21-
return new JsonRpcError(`Method ${methodName} not found on provider ${providerName}`, -32000);
21+
return JsonRpcError.methodNotFound({
22+
message: `Method ${methodName} not found on provider ${providerName}`,
23+
});
2224
}
2325

2426
const [videoconf, user, options] = params as Array<unknown>;

src/server/managers/AppVideoConfProvider.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { VideoConference } from '../../definition/videoConferences';
44
import type { IVideoConferenceUser } from '../../definition/videoConferences/IVideoConferenceUser';
55
import type { IVideoConferenceOptions, IVideoConfProvider, VideoConfData, VideoConfDataExtended } from '../../definition/videoConfProviders';
66
import type { ProxiedApp } from '../ProxiedApp';
7+
import { JSONRPC_METHOD_NOT_FOUND } from '../runtime/deno/AppsEngineDenoRuntime';
78
import type { AppLogStorage } from '../storage';
89
import type { AppAccessorManager } from './AppAccessorManager';
910

@@ -86,8 +87,17 @@ export class AppVideoConfProvider {
8687
params: runContextArgs,
8788
});
8889

89-
return result as string;
90+
return result as string | boolean | Array<IBlock> | undefined;
9091
} catch (e) {
92+
if (e?.code === JSONRPC_METHOD_NOT_FOUND) {
93+
if (method === AppMethod._VIDEOCONF_IS_CONFIGURED) {
94+
return true;
95+
}
96+
if (![AppMethod._VIDEOCONF_GENERATE_URL, AppMethod._VIDEOCONF_CUSTOMIZE_URL].includes(method)) {
97+
return undefined;
98+
}
99+
}
100+
91101
// @TODO add error handling
92102
console.log(e);
93103
}

0 commit comments

Comments
 (0)