Skip to content

Instantly share code, notes, and snippets.

@ibrahimBanat
Created June 2, 2021 19:35
Show Gist options
  • Save ibrahimBanat/910226945bdfd2a2dc8aa493cd515fdd to your computer and use it in GitHub Desktop.
Save ibrahimBanat/910226945bdfd2a2dc8aa493cd515fdd to your computer and use it in GitHub Desktop.
asdfadsfer
'use strict';
const express = require('express');
const cors = require('cors');
const app = express();
const path = require('path');
const server = require('http').createServer(app);
const socket = require('socket.io');
const io = socket(server, {
cors: { origin: '*' },
});
const router = require('./Router');
app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, '../public')));
app.use('/', router);
io.on('connection', socket => {
console.log('finally i am connceted !!!');
let payload = 'ibrahim banat';
io.emit('front', payload);
socket.on('assign-me', payload => {
socket.join(payload);
io.to(payload).emit('hello-mf', { hi: 'hi', id: payload });
});
socket.on('play', roomId => {
io.to(roomId).emit('play-handled', { name: 'novmber rain' });
});
socket.on('stop', roomId => {
io.to(roomId).emit('stop-handled', { name: 'video is stopped' });
});
socket.on('pasue', roomId => {
io.to(roomId).emit('pause-handled', { name: 'video is paused' });
});
});
module.exports = port => {
server.listen(port, () => {
console.log('server is up . . . ');
console.log(`server is running at http://localhost:${port}`);
});
};
/**
* handling spotify
*
*/
/**
*
*
* chat room functionality
*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment