-
Notifications
You must be signed in to change notification settings - Fork 70
/
component.ts
169 lines (153 loc) · 4.98 KB
/
component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright (c) 2023 Sourcefuse Technologies
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
import {
Binding,
Component,
ControllerClass,
CoreBindings,
inject,
ProviderMap,
} from '@loopback/core';
import {Class, Model, Repository} from '@loopback/repository';
import {RestApplication} from '@loopback/rest';
import {
BearerVerifierBindings,
BearerVerifierComponent,
BearerVerifierConfig,
BearerVerifierType,
CoreComponent,
IServiceConfig,
SECURITY_SCHEME_SPEC,
ServiceSequence,
} from '@sourceloop/core';
import {AuthenticationComponent} from 'loopback4-authentication';
import {
AuthorizationBindings,
AuthorizationComponent,
} from 'loopback4-authorization';
import {VideoChatArchiveController} from './controllers/video-chat-archive.controller';
import {VideoChatSessionController} from './controllers/video-chat-session.controller';
import {
MeetLinkGeneratorProvider,
ServiceBindings,
VideoChatBindings,
} from './keys';
import {AuditLog} from './models';
import {VideoChatSession} from './models/video-chat-session.model';
import {TwilioProvider} from './providers/twilio/twilio.provider';
import {TwilioService} from './providers/twilio/twilio.service';
import {VonageProvider} from './providers/vonage/vonage.provider';
import {VonageService} from './providers/vonage/vonage.service';
import {
AuditLogRepository,
SessionAttendeesRepository,
VideoChatSessionRepository,
} from './repositories';
import {
AuditLogRepository as AuditLogSequelizeRepository,
SessionAttendeesRepository as VideoChatSequelizeSessionRepository,
VideoChatSessionRepository as SessionAttendeesSequelizeRepository,
} from './repositories/sequelize';
import {
ChatArchiveService,
ChatSessionService,
MeetingLinkIdGeneratorProvider,
} from './services';
export class VideoConfServiceComponent implements Component {
constructor(
@inject(CoreBindings.APPLICATION_INSTANCE)
private readonly application: RestApplication,
@inject(VideoChatBindings.Config, {optional: true})
private readonly videoChatConfig?: IServiceConfig,
) {
this.bindings = [];
this.providers = {};
// Mount core component
this.application.component(CoreComponent);
this.application.api({
openapi: '3.0.0',
info: {
title: 'Video Conferencing Service',
version: '1.0.0',
},
paths: {},
components: {
securitySchemes: SECURITY_SCHEME_SPEC,
},
servers: [{url: '/'}],
});
this.bindings.push(
Binding.bind(ServiceBindings.SessionChatService).toClass(
ChatSessionService,
),
Binding.bind(ServiceBindings.ArchiveChatService).toClass(
ChatArchiveService,
),
);
this.application.service(VonageService);
this.application.service(TwilioService);
if (!this.videoChatConfig?.useCustomSequence) {
// Mount default sequence if needed
this.setupSequence(this.bindings);
}
if (this.videoChatConfig?.useSequelize) {
this.repositories = [
AuditLogSequelizeRepository, // this is the new audit repository needed for `@sourceloop/audit-logs`.
VideoChatSequelizeSessionRepository,
SessionAttendeesSequelizeRepository,
];
} else {
this.repositories = [
AuditLogRepository, // this is the new audit repository needed for `@sourceloop/audit-logs`.
VideoChatSessionRepository,
SessionAttendeesRepository,
];
}
this.models = [AuditLog, VideoChatSession];
this.providers = {
[VideoChatBindings.VideoChatProvider.key]: VonageProvider,
[MeetLinkGeneratorProvider.key]: MeetingLinkIdGeneratorProvider,
TwilioProvider,
};
this.controllers = [VideoChatArchiveController, VideoChatSessionController];
}
providers?: ProviderMap = {};
bindings?: Binding[] = [];
/**
* An optional list of Repository classes to bind for dependency injection
* via `app.repository()` API.
*/
repositories?: Class<Repository<Model>>[];
/**
* An optional list of Model classes to bind for dependency injection
* via `app.model()` API.
*/
models?: Class<Model>[];
/**
* An array of controller classes
*/
controllers?: ControllerClass[];
/**
* Setup ServiceSequence by default if no other sequnce provided
*
* @param bindings Binding array
*/
setupSequence(bindings: Binding[]) {
this.application.sequence(ServiceSequence);
// Mount authentication component for default sequence
this.application.component(AuthenticationComponent);
// Mount bearer verifier component
this.application.bind(BearerVerifierBindings.Config).to({
authServiceUrl: '',
type: BearerVerifierType.service,
} as BearerVerifierConfig);
this.application.component(BearerVerifierComponent);
// Mount authorization component for default sequence
this.application.bind(AuthorizationBindings.CONFIG).to({
allowAlwaysPaths: ['/explorer'],
});
this.application.component(AuthorizationComponent);
}
}