@@ -2,94 +2,93 @@ require('dotenv').config();
2
2
const express = require ( 'express' ) ;
3
3
const path = require ( 'path' ) ;
4
4
const OpenTok = require ( 'opentok' ) ;
5
+
5
6
const port = process . env . port || 3000 ;
6
7
7
8
const app = express ( ) ;
8
9
const opentok = new OpenTok ( process . env . API_KEY , process . env . API_SECRET ) ;
9
10
10
11
app . use ( express . urlencoded ( { extended : true } ) ) ;
11
12
app . use ( express . json ( ) ) ;
12
- app . use ( express . static ( __dirname + ' /public' ) ) ;
13
+ app . use ( express . static ( ` ${ __dirname } /public` ) ) ;
13
14
14
15
app . get ( '/' , ( req , res ) => {
15
- res . sendFile ( path . join ( __dirname + ' /public/index.html' ) ) ;
16
- } )
16
+ res . sendFile ( path . join ( ` ${ __dirname } /public/index.html` ) ) ;
17
+ } ) ;
17
18
18
19
app . get ( '/session/:sessionId' , ( req , res ) => {
19
- const sessionId = req . params . sessionId ;
20
- res . sendFile ( path . join ( __dirname + '/public/call.html' ) ) ;
21
- } )
20
+ res . sendFile ( path . join ( `${ __dirname } /public/call.html` ) ) ;
21
+ } ) ;
22
22
23
23
app . post ( '/api/create' , ( req , res ) => {
24
24
opentok . createSession (
25
25
{
26
- mediaMode : " routed"
26
+ mediaMode : ' routed' ,
27
27
} ,
28
- function ( err , session ) {
28
+ ( err , session ) => {
29
29
if ( err ) {
30
- res . status ( 500 ) . send ( { error : 'createSession error' } ) ;
30
+ res . status ( 500 ) . send ( { error : 'createSession error' } ) ;
31
31
return ;
32
32
}
33
- token = opentok . generateToken ( session . sessionId ) ;
34
33
res . setHeader ( 'Content-Type' , 'application/json' ) ;
35
34
res . send ( {
36
35
sessionId : session . sessionId ,
37
36
} ) ;
38
- }
37
+ } ,
39
38
) ;
40
39
} ) ;
41
40
42
41
app . post ( '/api/credentials' , ( req , res ) => {
43
- const sessionId = req . body . sessionId ;
42
+ const { sessionId } = req . body ;
44
43
const token = opentok . generateToken ( sessionId ) ;
45
44
res . send ( {
46
- sessionId : sessionId ,
45
+ sessionId,
47
46
apiKey : process . env . API_KEY ,
48
- token : token
47
+ token,
49
48
} ) ;
50
- } )
49
+ } ) ;
51
50
52
51
app . post ( '/api/archive/start/:sessionId' , ( req , res ) => {
53
- const sessionId = req . params . sessionId ;
52
+ const { sessionId } = req . params ;
54
53
const time = new Date ( ) . toLocaleString ( ) ;
55
- let archiveOptions = {
54
+ const archiveOptions = {
56
55
name : `archive-${ time } ` ,
57
56
outputMode : 'composed' ,
58
57
layout : {
59
- type : " bestFit" ,
60
- screenshareType : " pip"
61
- }
62
- }
58
+ type : ' bestFit' ,
59
+ screenshareType : ' pip' ,
60
+ } ,
61
+ } ;
63
62
64
- opentok . startArchive ( sessionId , archiveOptions , function ( err , archive ) {
65
- if ( err ) {
63
+ opentok . startArchive ( sessionId , archiveOptions , ( err , archive ) => {
64
+ if ( err ) {
66
65
return res . status ( 500 ) . send ( err ) ;
67
66
}
68
67
return res . json ( archive ) ;
69
68
} ) ;
70
- } )
69
+ } ) ;
71
70
72
71
app . post ( '/api/archive/:archiveId/stop' , ( req , res ) => {
73
- const archiveId = req . params . archiveId ;
74
- opentok . stopArchive ( archiveId , function ( err , archive ) {
75
- if ( err ) {
72
+ const { archiveId } = req . params ;
73
+ opentok . stopArchive ( archiveId , ( err , archive ) => {
74
+ if ( err ) {
76
75
return res . status ( 500 ) . send ( {
77
- archiveId : archiveId ,
78
- error : err
76
+ archiveId,
77
+ error : err ,
79
78
} ) ;
80
79
}
81
80
return res . json ( archive ) ;
82
81
} ) ;
83
- } )
82
+ } ) ;
84
83
85
84
app . get ( '/api/archive/list' , ( req , res ) => {
86
- opentok . listArchives ( { count : 10 } , function ( err , archive , count ) {
87
- if ( err ) {
85
+ opentok . listArchives ( { count : 10 } , ( err , archive ) => {
86
+ if ( err ) {
88
87
return res . status ( 500 ) . send ( err ) ;
89
88
}
90
89
return res . json ( archive ) ;
91
- } )
92
- } )
90
+ } ) ;
91
+ } ) ;
93
92
94
93
app . listen ( port , ( ) => {
95
94
console . log ( `App running on port: ${ port } ` ) ;
0 commit comments