forked from YasminTeles/ClinicAll
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b32535f
commit f145e00
Showing
17 changed files
with
699 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
REACT_APP_AUTH0_DOMAIN=clinicall.us.auth0.com | ||
REACT_APP_AUTH0_CLIENT_ID=i7YJaB8vka2TJGyWKDJQtm0X07KNjFP4 | ||
SKIP_PREFLIGHT_CHECK=true | ||
TWILIO_ACCOUNT_SID= "AC7d0f4b2ab93382fa387732772e2fadf8" | ||
TWILIO_API_KEY= "SK2494b65a32e9e545b07ce0c8c0100474" | ||
TWILIO_API_SECRET= "RBNeyZn7rQRZLvqE3QT23yqMzlST0tdA" |
This file contains 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 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,10 @@ | ||
module.exports = { | ||
twilio: { | ||
accountSid: process.env.TWILIO_ACCOUNT_SID, | ||
apiKey: process.env.TWILIO_API_KEY, | ||
apiSecret: process.env.TWILIO_API_SECRET, | ||
chatService: process.env.TWILIO_CHAT_SERVICE_SID, | ||
outgoingApplicationSid: process.env.TWILIO_TWIML_APP_SID, | ||
incomingAllow: process.env.TWILIO_ALLOW_INCOMING_CALLS === "true" | ||
} | ||
}; |
This file contains 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,67 @@ | ||
const config = require('./config'); | ||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
const pino = require('express-pino-logger')(); | ||
const { chatToken, videoToken, voiceToken } = require('./tokens'); | ||
|
||
const app = express(); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(bodyParser.json()); | ||
app.use(pino); | ||
|
||
const sendTokenResponse = (token, res) => { | ||
res.set('Content-Type', 'application/json'); | ||
res.send( | ||
JSON.stringify({ | ||
token: token.toJwt() | ||
}) | ||
); | ||
}; | ||
|
||
app.get('/api/greeting', (req, res) => { | ||
const name = req.query.name || 'World'; | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.send(JSON.stringify({ greeting: `Hello ${name}!` })); | ||
}); | ||
|
||
app.get('/chat/token', (req, res) => { | ||
const identity = req.query.identity; | ||
const token = chatToken(identity, config); | ||
sendTokenResponse(token, res); | ||
}); | ||
|
||
app.post('/chat/token', (req, res) => { | ||
const identity = req.body.identity; | ||
const token = chatToken(identity, config); | ||
sendTokenResponse(token, res); | ||
}); | ||
|
||
app.get('/video/token', (req, res) => { | ||
const identity = req.query.identity; | ||
const room = req.query.room; | ||
const token = videoToken(identity, room, config); | ||
sendTokenResponse(token, res); | ||
}); | ||
|
||
app.post('/video/token', (req, res) => { | ||
const identity = req.body.identity; | ||
const room = req.body.room; | ||
const token = videoToken(identity, room, config); | ||
sendTokenResponse(token, res); | ||
}); | ||
|
||
app.get('/voice/token', (req, res) => { | ||
const identity = req.body.identity; | ||
const token = voiceToken(identity, config); | ||
sendTokenResponse(token, res); | ||
}); | ||
|
||
app.post('/voice/token', (req, res) => { | ||
const identity = req.body.identity; | ||
const token = voiceToken(identity, config); | ||
sendTokenResponse(token, res); | ||
}); | ||
|
||
app.listen(3001, () => | ||
console.log('Express server is running on localhost:3001') | ||
); |
This file contains 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,54 @@ | ||
const twilio = require("twilio"); | ||
const AccessToken = twilio.jwt.AccessToken; | ||
const { ChatGrant, VideoGrant, VoiceGrant } = AccessToken; | ||
|
||
const generateToken = config => { | ||
return new AccessToken( | ||
config.twilio.accountSid, | ||
config.twilio.apiKey, | ||
config.twilio.apiSecret | ||
); | ||
}; | ||
|
||
const chatToken = (identity, config) => { | ||
const chatGrant = new ChatGrant({ | ||
serviceSid: config.twilio.chatService | ||
}); | ||
const token = generateToken(config); | ||
token.addGrant(chatGrant); | ||
token.identity = identity; | ||
return token; | ||
}; | ||
|
||
const videoToken = (identity, room, config) => { | ||
let videoGrant; | ||
if (typeof room !== "undefined") { | ||
videoGrant = new VideoGrant({ room }); | ||
} else { | ||
videoGrant = new VideoGrant(); | ||
} | ||
const token = generateToken(config); | ||
token.addGrant(videoGrant); | ||
token.identity = identity; | ||
return token; | ||
}; | ||
|
||
const voiceToken = (identity, config) => { | ||
let voiceGrant; | ||
if (typeof config.twilio.outgoingApplicationSid !== "undefined") { | ||
voiceGrant = new VoiceGrant({ | ||
outgoingApplicationSid: config.twilio.outgoingApplicationSid, | ||
incomingAllow: config.twilio.incomingAllow | ||
}); | ||
} else { | ||
voiceGrant = new VoiceGrant({ | ||
incomingAllow: config.twilio.incomingAllow | ||
}); | ||
} | ||
const token = generateToken(config); | ||
token.addGrant(voiceGrant); | ||
token.identity = identity; | ||
return token; | ||
}; | ||
|
||
module.exports = { chatToken, videoToken, voiceToken }; |
This file contains 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 |
---|---|---|
@@ -1,30 +1,4 @@ | ||
.App { | ||
text-align: center; | ||
} | ||
|
||
.App-logo { | ||
height: 40vmin; | ||
pointer-events: none; | ||
} | ||
|
||
.App-header { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
font-size: calc(10px + 2vmin); | ||
color: white; | ||
} | ||
|
||
.App-link { | ||
color: #61dafb; | ||
} | ||
|
||
@keyframes App-logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './App'; | ||
|
||
test('renders learn react link', () => { | ||
const { getByText } = render(<App />); | ||
const linkElement = getByText(/learn react/i); | ||
expect(linkElement).toBeInTheDocument(); | ||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
ReactDOM.render(<App />, div); | ||
ReactDOM.unmountComponentAtNode(div); | ||
}); |
This file contains 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
Oops, something went wrong.