1
- // // DB
2
- // const admin = require('firebase-admin');
3
- // const serviceAccount = require('./serviceAccountKey.json');
4
- // // initialize admin SDK using serciceAcountKey
5
- // admin.initializeApp({
6
- // credential: admin.credential.cert(serviceAccount),
7
- // databaseURL: "https://stream-it-d368f.firebaseio.com"
1
+ // DB
2
+ const admin = require ( 'firebase-admin' ) ;
3
+ const serviceAccount = require ( './serviceAccountKey.json' ) ;
4
+ //initialize admin SDK using serciceAcountKey
5
+ admin . initializeApp ( {
6
+ credential : admin . credential . cert ( serviceAccount ) ,
7
+ databaseURL : "https://stream-it-d368f.firebaseio.com"
8
8
9
- // });
9
+ } ) ;
10
10
11
- // const db = admin.firestore();
12
- // const { v4: uuidv4 } = require('uuid');
13
- // const customGenerationFunction = () => (Math.random().toString(36) + '0000000000000000000').substr(2, 16);
11
+ const db = admin . firestore ( ) ;
12
+ const auth = admin . auth ( ) ;
13
+ const { v4 : uuidv4 } = require ( 'uuid' ) ;
14
+ const customGenerationFunction = ( ) => ( Math . random ( ) . toString ( 36 ) + '0000000000000000000' ) . substr ( 2 , 16 ) ;
14
15
15
- // // web app
16
- // const express = require('express');
17
- // const bodyParser = require('body-parser')
18
- // var cors = require('cors')
16
+ // web app
17
+ const express = require ( 'express' ) ;
18
+ const bodyParser = require ( 'body-parser' )
19
+ var cors = require ( 'cors' )
19
20
20
- // const { ExpressPeerServer } = require('peer');
21
+ const { ExpressPeerServer } = require ( 'peer' ) ;
21
22
22
- // const app = express();
23
- // const http = require('http');
24
- // const { firestore } = require('firebase-admin');
23
+ const app = express ( ) ;
24
+ const http = require ( 'http' ) ;
25
+ const { firestore } = require ( 'firebase-admin' ) ;
25
26
26
- // const server = http.createServer(app);
27
+ const server = http . createServer ( app ) ;
27
28
28
29
// const peerServer = ExpressPeerServer(server, {
29
30
// debug: true,
30
31
// path: '/myapp',
31
- // generateClientId:uuidv4()
32
+ // generateClientId:customGenerationFunction
32
33
// });
33
34
34
- // app.use('/peerjs', peerServer);
35
+
36
+
35
37
36
38
// peerServer.on('disconnect',async (client)=>{
37
39
// let clientID = client.getId();
55
57
56
58
// // let roomRef = await db.collection("indexing").doc(clientID)
57
59
// })
60
+ // app.use('/peerjs', peerServer);
61
+ app . use ( cors ( ) ) ;
62
+ app . use ( bodyParser . json ( ) )
63
+ app . get ( '/' , ( req , res , next ) => res . send ( 'Hello world!' ) ) ; // == OR ==
64
+
65
+ app . get ( "/test" , async ( req , res ) => {
66
+ let clientID = "rxg00ufwdvb00000" ;
67
+ let roomRef = db . collection ( "indexing" ) . doc ( clientID ) ;
68
+ let roomRefData = await roomRef . get ( ) ;
69
+ if ( roomRefData . exists ) {
70
+ console . log ( roomRefData . data ( ) ) ;
71
+ let removeClient = await db . doc ( roomRefData . get ( "roomRef" ) ) ;
72
+ let specificclient = `candidates.${ clientID } `
73
+ await removeClient . update ( {
74
+ [ specificclient ] :firestore . FieldValue . delete ( )
75
+ } )
76
+ await roomRef . delete ( ) ;
77
+ res . send ( "OK" ) ;
78
+ }
79
+ else {
80
+ res . send ( "@@" ) ;
81
+ }
58
82
59
- // app.use(cors());
60
- // app.use(bodyParser.json())
61
- // app.get('/', (req, res, next) => res.send('Hello world!'));// == OR ==
62
83
63
- // app.get("/test",async(req,res)=>{
64
- // let clientID = "rxg00ufwdvb00000";
65
- // let roomRef = db.collection("indexing").doc(clientID);
66
- // let roomRefData = await roomRef.get();
67
- // if (roomRefData.exists) {
68
- // console.log(roomRefData.data());
69
- // let removeClient = await db.doc(roomRefData.get("roomRef"));
70
- // let specificclient = `candidates.${clientID}`
71
- // await removeClient.update({
72
- // [specificclient]:firestore.FieldValue.delete()
73
- // })
74
- // await roomRef.delete();
75
- // res.send("OK");
76
- // }
77
- // else{
78
- // res.send("@@");
79
- // }
84
+ } )
80
85
86
+ app . post ( "/signup" , async ( res , resp ) => {
87
+ try {
88
+ if ( res . body != null ) {
89
+ console . log ( res . body ) ;
90
+ let user = await auth . createUser ( res . body )
91
+ if ( user . uid != null ) {
92
+ resp . status ( 200 ) . send ( res . body )
93
+ }
94
+ }
95
+ } catch ( error ) {
96
+ console . log ( error )
97
+ resp . status ( 500 ) . send ( { status :"fail" } )
98
+ }
99
+ } )
81
100
82
- // })
101
+ app . post ( '/removeRoom' , async ( req , res ) => {
102
+ try {
103
+ console . log ( req . body ) ;
104
+ if ( req . body != null ) {
105
+ let path = req . body . path . toString ( ) ;
106
+ let hostUUID = req . body . host ;
107
+ let roomRef = db . doc ( path ) ;
108
+ let roomData = await roomRef . get ( )
109
+ if ( roomData . exists ) {
110
+ console . log ( "valid Room" ) ;
111
+ if ( hostUUID == roomData . get ( "host" ) ) {
112
+ roomRef . delete ( ) ;
113
+ res . sendStatus ( 200 ) . send ( ) ;
114
+ } else {
115
+ res . sendStatus ( 401 ) . send ( ) ;
116
+ }
117
+ } else {
118
+ res . sendStatus ( 401 ) . send ( ) ;
119
+ }
120
+ }
121
+ } catch ( error ) {
122
+
123
+ }
124
+ } ) ;
125
+
126
+ app . post ( '/createRoom' , async ( req , res ) => {
127
+ try {
128
+ console . log ( req . body )
129
+ if ( req . body != null ) {
130
+ let roomConfig = req . body ;
131
+ console . log ( req . body )
132
+ let roomRef = await db . collection ( "rooms" ) . add (
133
+ roomConfig
134
+ )
135
+ if ( ( await db . doc ( roomRef . path ) . get ( ) ) . exists ) {
136
+ console . log ( "Room Exitetedsss" ) ;
137
+ }
138
+ res . send ( roomRef . path ) ;
139
+ } else {
140
+ res . send ( "fail" ) ;
141
+ }
142
+ } catch ( error ) {
143
+ console . log ( error ) ;
144
+ }
145
+ } )
83
146
84
- // app.post('/removeRoom', async (req, res) => {
85
- // try {
86
- // console.log(req.body);
87
- // if (req.body != null) {
88
- // let path = req.body.path.toString();
89
- // let hostUUID = req.body.host;
90
- // let roomRef = db.doc(path);
91
- // let roomData = await roomRef.get()
92
- // if (roomData.exists) {
93
- // console.log("valid Room");
94
- // if (hostUUID == roomData.get("host")) {
95
- // roomRef.delete();
96
- // res.sendStatus(200).send();
97
- // }else{
98
- // res.sendStatus(401).send();
99
- // }
100
- // }else{
101
- // res.sendStatus(401).send();
102
- // }
103
- // }
104
- // } catch (error) {
147
+ let PORT = 8080
148
+ server . listen ( PORT , ( ) => {
149
+ console . log ( `http://localhost:${ PORT } ` )
150
+ } ) ;
105
151
106
- // }
107
- // });
152
+ // const fs = require('fs')
153
+ // const express = require('express');
154
+ // const { ExpressPeerServer } = require('peer');
155
+ // const cors = require('cors')
156
+ // const app = express();
108
157
109
- // app.post('/createRoom', async (req, res) => {
110
- // try {
111
- // console.log(req.body)
112
- // if (req.body != null) {
113
- // let roomConfig = req.body;
114
- // console.log(req.body)
115
- // let roomRef = await db.collection("rooms").add(
116
- // roomConfig
117
- // )
118
- // if ((await db.doc(roomRef.path).get()).exists) {
119
- // console.log("Room Exitetedsss");
120
- // }
121
- // res.send(roomRef.path);
122
- // } else {
123
- // res.send("fail");
124
- // }
125
- // } catch (error) {
126
- // console.log(error);
158
+ // app.get('/', (req, res, next) => res.send('Hello world!'));
159
+ // app.post('/signup',async (res,resp)=>{
160
+ // if (res.body != null) {
161
+ // console.log(res.body);
127
162
// }
128
163
// })
164
+ // const customGenerationFunction = () => (Math.random().toString(36) + '0000000000000000000').substr(2, 16);
165
+ // const http = require('http');
129
166
130
- // server.listen(9000, () => {
131
- // console.log("http://localhost:9000")
132
- // });
133
-
134
- const fs = require ( 'fs' )
135
- const express = require ( 'express' ) ;
136
- const { ExpressPeerServer } = require ( 'peer' ) ;
137
- const cors = require ( 'cors' )
138
- const app = express ( ) ;
139
-
140
- app . get ( '/' , ( req , res , next ) => res . send ( 'Hello world!' ) ) ;
141
- const customGenerationFunction = ( ) => ( Math . random ( ) . toString ( 36 ) + '0000000000000000000' ) . substr ( 2 , 16 ) ;
142
- const http = require ( 'http' ) ;
167
+ // // const credentail =
168
+ // // {
169
+ // // key: fs.readFileSync('./domain.key'),
170
+ // // cert: fs.readFileSync('./domain.crt')
171
+ // // };
143
172
144
- // const credentail =
145
- // {
146
- // key: fs.readFileSync('./domain.key'),
147
- // cert: fs.readFileSync('./domain.crt')
148
- // };
149
-
150
- const server = http . createServer (
151
- app ) ;
152
- const peerServer = ExpressPeerServer ( server , {
153
- debug : true ,
154
- // ssl: {
155
- // key: fs.readFileSync('./domain.key'),
156
- // cert: fs.readFileSync('./domain.crt')
157
- // },
158
- // path: '/myapp',
159
- generateClientId : customGenerationFunction
160
- } ) ;
161
- peerServer . on ( 'disconnect' , ( client ) => {
162
- console . log ( `Discoonect : ${ client . getId ( ) } ` )
163
- } )
164
- app . use ( cors ( ) ) ;
165
- app . use ( '/peerjs' , peerServer ) ;
173
+ // const server = http.createServer(
174
+ // app);
175
+ // server.listen(9000);
176
+ // const peerServer = ExpressPeerServer(server, {
177
+ // debug: true,
178
+ // // ssl: {
179
+ // // key: fs.readFileSync('./domain.key'),
180
+ // // cert: fs.readFileSync('./domain.crt')
181
+ // // },
182
+ // path: '/myapp',
183
+ // generateClientId: customGenerationFunction
184
+ // });
185
+ // peerServer.on('disconnect', (client) => {
186
+ // console.log(`Discoonect : ${client.getId()}`)
187
+ // })
188
+ // peerServer.on('connection',(client)=>{
189
+ // console.log(client.getId);
190
+ // })
191
+ // app.use(cors());
192
+ // app.use('/peerjs', peerServer);
166
193
167
- server . listen ( 9000 , "0.0.0.0" ) ;
168
- // ipconfig getifaddr en0
0 commit comments