Skip to content

Commit 7270b94

Browse files
committed
notification
1 parent d9ae39d commit 7270b94

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

package.json

100644100755
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
},
1212
"author": "@Manuel_Galindez",
1313
"license": "MIT",
14-
"devDependencies": {
15-
"babel": "^6.5.2",
14+
"dependencies": {
1615
"babel-cli": "^6.16.0",
1716
"babel-preset-es2015": "^6.16.0",
1817
"babel-preset-react": "^6.16.0",
@@ -21,9 +20,7 @@
2120
"express": "^4.14.0",
2221
"nib": "^1.1.2",
2322
"react-engine": "^4.1.0",
24-
"stylus": "^0.54.5"
25-
},
26-
"dependencies": {
23+
"stylus": "^0.54.5",
2724
"react": "^15.3.2",
2825
"react-addons-css-transition-group": "^15.3.2",
2926
"react-dom": "^15.3.2",

src/client/Components/ConversationUser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export default class ConversationUser extends React.Component {
1919
}
2020

2121
componentDidMount(){
22+
Notification.requestPermission();
23+
2224
setTimeout(() => {
2325
this.setState({
2426
active : true

src/client/Components/Discussions.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,43 @@ import React from 'react';
22
import io from 'socket.io-client';
33
import uid from 'uid';
44
import MessageList from './MessageList';
5-
5+
import Notification from './Notification';
66

77
export default class Discussions extends React.Component {
88

99
constructor(props){
1010
super(props)
11-
this.state = { messages: [], connectUser: [] };
11+
this.state = { messages: [] };
1212
this._dataValue = this._dataValue.bind(this);
1313
this._MessageSend = this._MessageSend.bind(this);
1414
this.user = uid(10);
1515
}
1616

1717
componentDidMount(){
18+
1819
this.socket = io('localhost:3000');
1920

2021
this.socket.on('message', (message) => {
2122
if (message.user !== this.user) {
2223
this._MessageSend(message);
2324
}
2425
})
25-
26-
this.socket.on('loggin', (onUser) => {
27-
this.state.connectUser.push(onUser);
28-
console.log(this.state.connectUser);
29-
})
30-
3126
}
3227

28+
3329
_dataValue(ev) {
3430

3531
ev.preventDefault();
3632

3733
let textValue = document.getElementById('textarea').value;
34+
3835
const avatar = this.props.avatar;
3936
const username = this.props.username;
4037
let message = { avatar: avatar, username: username, message: textValue };
4138

4239
if ( textValue !== '' ) {
43-
4440
this.socket.emit('new-message', message);
41+
Notification(message);
4542
document.getElementById('textarea').value = '';
4643
}
4744
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default function Notification (obj) {
2+
3+
let titulo = `Tienes un nuevo mensaje de ${obj.username}`;
4+
let options = {
5+
icon: `${obj.avatar}`,
6+
body: obj.message
7+
}
8+
9+
if(Notification) {
10+
console.log('excelente');
11+
if (Notification.permission == "granted"){
12+
var newNoti = new Notification(titulo, options);
13+
setTimeout(newNoti.close.bind(newNoti), 6000);
14+
}
15+
16+
}
17+
}

0 commit comments

Comments
 (0)