Skip to content

Instantly share code, notes, and snippets.

@jamalag
Last active July 6, 2019 21:42
Show Gist options
  • Save jamalag/d9096a1f378efab9577a1c44aa82966e to your computer and use it in GitHub Desktop.
Save jamalag/d9096a1f378efab9577a1c44aa82966e to your computer and use it in GitHub Desktop.
// taken from: https://pusher.com/tutorials/react-websockets
// npm install --save axios body-parser cors express pusher pusher-js
const Pusher = require('pusher');
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
app.use(cors());
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
const pusher = new Pusher({
appId: '818136',
key: 'dffbab583e3f0e41aea3',
secret: '9e37ae462d31e46a47b3',
cluster: 'us2',
encrypted: true
});
// pusher.trigger('reactWebRTC', 'chat', {
// "message": "hello world"
// })
app.set('PORT', process.env.PORT || 3000);
app.post('/offer', (req, res) => {
const payload = req.body;
pusher.trigger('reactWebRTC', 'offer', payload);
res.send(payload)
});
app.post('/answer', (req, res) => {
const payload = req.body;
pusher.trigger('reactWebRTC', 'answer', payload);
res.send(payload)
});
app.post('/candidate', (req, res) => {
const payload = req.body;
pusher.trigger('reactWebRTC', 'candidate', payload);
res.send(payload)
});
app.listen(app.get('PORT'), () =>
console.log('Listening at ' + app.get('PORT')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment