-
Notifications
You must be signed in to change notification settings - Fork 13.6k
feat(apps): introduce read accessor for media calls #40863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
d-gubert
wants to merge
3
commits into
feat/sip-metadata
Choose a base branch
from
feat/apps-media-calls
base: feat/sip-metadata
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@rocket.chat/apps-engine': minor | ||
| '@rocket.chat/apps': minor | ||
| '@rocket.chat/meteor': minor | ||
| --- | ||
|
|
||
| Added the new MediaCallRead accessor that allows apps to read information from the system's media calls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import type { IAppServerOrchestrator } from '@rocket.chat/apps'; | ||
| import { MediaCallBridge } from '@rocket.chat/apps/dist/server/bridges/MediaCallBridge'; | ||
| import type { IMediaCall } from '@rocket.chat/apps-engine/definition/mediaCalls'; | ||
| import { MediaCalls } from '@rocket.chat/models'; | ||
|
|
||
| export class AppMediaCallBridge extends MediaCallBridge { | ||
| constructor(private readonly orch: IAppServerOrchestrator) { | ||
| super(); | ||
| } | ||
|
|
||
| protected async getById(callId: string, appId: string): Promise<IMediaCall | undefined> { | ||
| this.orch.debugLog(`The App ${appId} is getting the media call byId: "${callId}"`); | ||
|
|
||
| return (await MediaCalls.findOneById(callId)) ?? undefined; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+3.72 KB
apps/meteor/tests/data/apps/app-packages/media-call-reader-test_0.0.1.zip
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
apps/meteor/tests/end-to-end/apps/app-media-call-reader.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import type { App } from '@rocket.chat/core-typings'; | ||
| import { expect } from 'chai'; | ||
| import { after, before, describe, it } from 'mocha'; | ||
| import type { Response } from 'supertest'; | ||
|
|
||
| import { getCredentials, request, credentials } from '../../data/api-data'; | ||
| import { mediaCallReaderTest } from '../../data/apps/app-packages'; | ||
| import { apps } from '../../data/apps/apps-data'; | ||
| import { cleanupApps, installLocalTestPackage } from '../../data/apps/helper'; | ||
| import { IS_EE } from '../../e2e/config/constants'; | ||
|
|
||
| // Test fixture call IDs seeded by callHistoryTestData.ts | ||
| const INTERNAL_CALL_ID = 'rocketchat.internal.call.test'; | ||
| const EXTERNAL_CALL_ID = 'rocketchat.external.call.test.outbound'; | ||
|
|
||
| (IS_EE ? describe : describe.skip)('Apps - MediaCallRead accessor', () => { | ||
| describe('[with media-call.read permission]', () => { | ||
| let app: App; | ||
|
|
||
| before((done) => getCredentials(done)); | ||
|
|
||
| before(async () => { | ||
| await cleanupApps(); | ||
| app = await installLocalTestPackage(mediaCallReaderTest); | ||
| }); | ||
|
|
||
| after(() => cleanupApps()); | ||
|
|
||
| it('should return an internal call by ID', async () => { | ||
| await request | ||
| .get(apps(`/public/${app.id}/read-call`)) | ||
| .set(credentials) | ||
| .query({ callId: INTERNAL_CALL_ID }) | ||
| .expect('Content-Type', /json/) | ||
| .expect(200) | ||
| .expect((res: Response) => { | ||
| expect(res.body).to.have.property('call').that.is.an('object'); | ||
|
|
||
| const { call } = res.body; | ||
| expect(call).to.have.property('_id', INTERNAL_CALL_ID); | ||
| expect(call).to.have.property('service', 'webrtc'); | ||
| expect(call).to.have.property('kind', 'direct'); | ||
| expect(call).to.have.property('state', 'hangup'); | ||
| expect(call).to.have.property('ended', true); | ||
| expect(call).to.have.property('createdBy').that.is.an('object'); | ||
| expect(call.createdBy).to.have.property('type', 'user'); | ||
| expect(call).to.have.property('caller').that.is.an('object'); | ||
| expect(call.caller).to.have.property('type', 'user'); | ||
| expect(call).to.have.property('callee').that.is.an('object'); | ||
| expect(call.callee).to.have.property('type', 'user'); | ||
| expect(call).to.have.property('uids').that.is.an('array').with.lengthOf(2); | ||
| expect(call).to.have.property('features').that.is.an('array'); | ||
| }); | ||
| }); | ||
|
|
||
| it('should return an external call by ID', async () => { | ||
| await request | ||
| .get(apps(`/public/${app.id}/read-call`)) | ||
| .set(credentials) | ||
| .query({ callId: EXTERNAL_CALL_ID }) | ||
| .expect('Content-Type', /json/) | ||
| .expect(200) | ||
| .expect((res: Response) => { | ||
| expect(res.body).to.have.property('call').that.is.an('object'); | ||
|
|
||
| const { call } = res.body; | ||
| expect(call).to.have.property('_id', EXTERNAL_CALL_ID); | ||
| expect(call).to.have.property('service', 'webrtc'); | ||
| expect(call).to.have.property('kind', 'direct'); | ||
| expect(call).to.have.property('state', 'hangup'); | ||
| expect(call).to.have.property('ended', true); | ||
| expect(call).to.have.property('sipCallId').that.is.a('string'); | ||
| expect(call).to.have.property('callee').that.is.an('object'); | ||
| expect(call.callee).to.have.property('type', 'sip'); | ||
| expect(call).to.have.property('uids').that.is.an('array').with.lengthOf(1); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('[without media-call.read permission]', () => { | ||
| let app: App; | ||
|
|
||
| before((done) => getCredentials(done)); | ||
|
|
||
| before(async () => { | ||
| await cleanupApps(); | ||
| app = await installLocalTestPackage(mediaCallReaderTest, { withPermissions: false }); | ||
| }); | ||
|
|
||
| after(() => cleanupApps()); | ||
|
|
||
| it('should return null when the app does not have the media-call.read permission', async () => { | ||
| await request | ||
| .get(apps(`/public/${app.id}/read-call`)) | ||
| .set(credentials) | ||
| .query({ callId: INTERNAL_CALL_ID }) | ||
| .expect('Content-Type', /json/) | ||
| .expect(200) | ||
| .expect((res: Response) => { | ||
| expect(res.body).to.have.property('call', null); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
15 changes: 15 additions & 0 deletions
15
packages/apps-engine/src/definition/accessors/IMediaCallRead.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type { IMediaCall } from '../mediaCalls/IMediaCall'; | ||
|
|
||
| /** | ||
| * This accessor provides methods for accessing | ||
| * media calls in a read-only-fashion. | ||
| */ | ||
| export interface IMediaCallRead { | ||
| /** | ||
| * Gets a media call by an id. | ||
| * | ||
| * @param id the id of the media call | ||
| * @returns the media call | ||
| */ | ||
| getById(id: string): Promise<IMediaCall | undefined>; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/apps-engine/src/definition/mediaCalls/IMediaCall.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| type MediaCallActorType = 'user' | 'sip'; | ||
|
|
||
| type MediaCallContact = { | ||
| type: MediaCallActorType; | ||
| id: string; | ||
| contractId?: string; | ||
| displayName?: string; | ||
| username?: string; | ||
| sipExtension?: string; | ||
| }; | ||
|
|
||
| type MediaCallSignedContact = MediaCallContact & { contractId: string }; | ||
|
|
||
| type MediaCallState = 'none' | 'ringing' | 'accepted' | 'active' | 'hangup'; | ||
|
|
||
| export interface IMediaCall { | ||
| _id: string; | ||
| _updatedAt: Date; | ||
| service: string; | ||
| kind: string; | ||
| state: MediaCallState; | ||
| createdBy: MediaCallContact; | ||
| createdAt: Date; | ||
| caller: MediaCallSignedContact; | ||
| callee: MediaCallContact; | ||
| ended: boolean; | ||
| endedBy?: { type: MediaCallActorType | 'server'; id: string; contractId?: string }; | ||
| endedAt?: Date; | ||
| hangupReason?: string; | ||
| expiresAt: Date; | ||
| acceptedAt?: Date; | ||
| activatedAt?: Date; | ||
| callerRequestedId?: string; | ||
| parentCallId?: string; | ||
| transferredBy?: MediaCallSignedContact; | ||
| transferredTo?: MediaCallContact; | ||
| transferredAt?: Date; | ||
| uids: string[]; | ||
| features: string[]; | ||
| sipCallId?: string; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export type * from './IMediaCall'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.