blob: 23f393546f9c3e1dfb606f0dd7280c706a11bab5 [file] [log] [blame]
Larbi Gharibe9af9732021-03-31 15:08:01 +01001import React from 'react';
2import Header from '../components/Header'
3import ContactList from '../components/ContactList'
4import MessageList from '../components/MessageList'
5import SendMessageForm from '../components/SendMessageForm'
6import NewContactForm from '../components/NewContactForm'
Adrien Béraud6ecaa402021-04-06 17:37:25 -04007//import Sound from 'react-sound';
Larbi Gharibe9af9732021-03-31 15:08:01 +01008import io from "socket.io-client";
Adrien Béraud6ecaa402021-04-06 17:37:25 -04009//const socket = io.connect('http://localhost:3000');
Larbi Gharibe9af9732021-03-31 15:08:01 +010010
Adrien Béraud6ecaa402021-04-06 17:37:25 -040011class JamiMessenger extends React.Component {
Larbi Gharibe9af9732021-03-31 15:08:01 +010012
13 constructor() {
14 super()
15 this.state = {
16 messages: [],
17 sound: false
18 }
19
Adrien Béraud6ecaa402021-04-06 17:37:25 -040020 /*socket.on('connect', () => {
Larbi Gharibe9af9732021-03-31 15:08:01 +010021 console.log("Success !")
Adrien Béraud6ecaa402021-04-06 17:37:25 -040022 })*/
Larbi Gharibe9af9732021-03-31 15:08:01 +010023
Larbi Gharibe9af9732021-03-31 15:08:01 +010024
25 //this.socket = socketIOClient(ENDPOINT);
26 //this.socket.on("FromAPI", data => {
27 // this.setState({
28 // messages: [...this.state.messages, data]
29 // })
30 //});
31 this.sendMessage = this.sendMessage.bind(this)
32 }
33
34 componentDidMount() {
Adrien Béraud6ecaa402021-04-06 17:37:25 -040035 /*socket.on('receivedMessage', (data) => {
36 const message = {
Larbi Gharibe9af9732021-03-31 15:08:01 +010037 senderId: '65f6674b26e5af6ed0b4e92a13b80ff4bbfdf1e8',
38 text: data
39 }
40 this.setState({
41 messages: [...this.state.messages, message],
42 sound: true
43 })
Adrien Béraud6ecaa402021-04-06 17:37:25 -040044 });*/
Larbi Gharibe9af9732021-03-31 15:08:01 +010045 }
46
47 sendMessage(text) {
48 var data = {
49 senderId: 'Me',
50 destinationId: '65f6674b26e5af6ed0b4e92a13b80ff4bbfdf1e8',
51 text: text
52 }
Adrien Béraud6ecaa402021-04-06 17:37:25 -040053 //socket.emit("SendMessage", data);
Larbi Gharibe9af9732021-03-31 15:08:01 +010054 console.log(data.text);
55 this.setState({
56 messages: [...this.state.messages, data],
57 sound: false
58 })
59 }
60 render() {
61 return (
62 <div className="app" >
63 <Header />
64 <ContactList />
65 <MessageList messages={this.state.messages} />
66 <SendMessageForm sendMessage={this.sendMessage} />
67 <NewContactForm />
68 {this.state.sound && <Sound
69 url="stairs.mp3" /*https://notificationsounds.com/message-tones/stairs-567*/
70 playStatus={Sound.status.PLAYING}
71 playFromPosition={0 /* in milliseconds */}
72 onLoading={this.handleSongLoading}
73 onPlaying={this.handleSongPlaying}
74 onFinishedPlaying={this.handleSongFinishedPlaying}
75 />}
76 </div>
77 )
78 }
79}
80
Adrien Béraud6ecaa402021-04-06 17:37:25 -040081export default JamiMessenger;