Skip to content
This repository has been archived by the owner on Oct 16, 2021. It is now read-only.

Feature/chatpratice with express #2

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ test/

# End of https://www.toptal.com/developers/gitignore/api/django,vue

<<<<<<< HEAD
feature/idea_conference
node_modules/
=======
node_modules/

.config_secret
>>>>>>> feature/modeling
1,668 changes: 1,668 additions & 0 deletions websocket/backend/package-lock.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions websocket/backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"server": "^1.0.31",
"socket.io": "^2.3.0"
}
}
48 changes: 48 additions & 0 deletions websocket/backend/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var app = require('express')();
var server = require('http').createServer(app);
var io = require('socket.io')(server,{
pingTimeout: 1000,
});


app.all('/*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});

// localhost:3000서버에 접속하면 클라이언트로 메세지을 전송한다
app.get('/', function(req, res) {
res.sendFile('Hellow Chating App Server');
});

//connection event handler
io.on('connection' , function(socket) {
console.log('Connect from Client: '+socket)
console.log(Object.keys(socket))

socket.on('hello', function(data){
console.log('hello from Client: '+data)
});
socket.on('join',(roomId,username)=>{
socket.join(roomId,()=>{
io.to(roomId).emit('join')
})
})
socket.on('chat', (roomId,username,message,time)=>{
console.log(roomId,username,message)
console.log(socket.rooms)
socket.broadcast.to(roomId).emit('chat',{
username: username,
message : message,
time : time
})

});


})

server.listen(3000, function() {
console.log('socket io server listening on port 3000')
})
23 changes: 23 additions & 0 deletions websocket/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.DS_Store
node_modules
/dist


# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
24 changes: 24 additions & 0 deletions websocket/frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frontend

## Project setup
```
npm install
```

### Compiles and hot-reloads for development
```
npm run serve
```

### Compiles and minifies for production
```
npm run build
```

### Lints and fixes files
```
npm run lint
```

### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).
5 changes: 5 additions & 0 deletions websocket/frontend/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
Loading