-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
72 lines (55 loc) · 1.81 KB
/
index.js
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
'use strict';
require('dotenv').config();
const Koa = require('koa');
const Router = require('@koa/router');
const render = require('koa-ejs');
const path = require('path');
const serve = require('koa-static');
const websockify = require('koa-websocket');
const bodyParser = require('koa-bodyparser');
const OpenTok = require("opentok");
const app = new Koa();
const socket = websockify(app);
const ws = new Router();
app.use(bodyParser());
app.context.ws = ws;
const basicHttp = require('./routes/basic');
const symblTranscriptionHttp = require('./routes/symbl');
const opentok = new OpenTok(process.env.VONAGE_API_KEY, process.env.VONAGE_API_SECRET);
app.context.opentok = opentok;
const symblSdk = require('@symblai/symbl-js').sdk;
app.context.symblSdk = symblSdk;
const SymblProcessor = require('./symbl-processor');
app.context.symblProcessor = new SymblProcessor();
symblSdk.init({
appId: process.env.SYMBL_APP_ID,
appSecret: process.env.SYMBL_APP_SECRET,
basePath: 'https://api.symbl.ai'
})
.then(() => console.log('Symbl.ai SDK Initialized.'))
.catch(err => console.error('Error in initialization.', err));
opentok.createSession({ mediaMode: "routed" }, function (err, session) {
if (err) throw err;
app.context.openTokSession = session;
});
app.use(serve('./public'));
app.use(async (ctx, next) => {
try {
await next()
} catch(err) {
console.log(err.status)
ctx.status = err.status || 500;
ctx.body = err.message;
}
});
render(app, {
root: path.join(__dirname, 'views'),
layout: false,
viewExt: 'html',
cache: false,
debug: true
});
app.use(basicHttp.routes()).use(basicHttp.allowedMethods());
app.ws.use(ws.routes()).use(ws.allowedMethods());
app.use(symblTranscriptionHttp.routes()).use(symblTranscriptionHttp.allowedMethods());
app.listen(3000, console.log('Listening on port 3000'));