Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 1 | import React from 'react'; |
| 2 | import Header from '../components/Header' |
| 3 | import ContactList from '../components/ContactList' |
| 4 | import MessageList from '../components/MessageList' |
| 5 | import SendMessageForm from '../components/SendMessageForm' |
| 6 | import NewContactForm from '../components/NewContactForm' |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 7 | //import Sound from 'react-sound'; |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 8 | import io from "socket.io-client"; |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 9 | //const socket = io.connect('http://localhost:3000'); |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 10 | |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 11 | class JamiMessenger extends React.Component { |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 12 | |
| 13 | constructor() { |
| 14 | super() |
| 15 | this.state = { |
| 16 | messages: [], |
| 17 | sound: false |
| 18 | } |
| 19 | |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 20 | /*socket.on('connect', () => { |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 21 | console.log("Success !") |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 22 | })*/ |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 23 | |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 24 | |
| 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éraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 35 | /*socket.on('receivedMessage', (data) => { |
| 36 | const message = { |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 37 | senderId: '65f6674b26e5af6ed0b4e92a13b80ff4bbfdf1e8', |
| 38 | text: data |
| 39 | } |
| 40 | this.setState({ |
| 41 | messages: [...this.state.messages, message], |
| 42 | sound: true |
| 43 | }) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 44 | });*/ |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | sendMessage(text) { |
| 48 | var data = { |
| 49 | senderId: 'Me', |
| 50 | destinationId: '65f6674b26e5af6ed0b4e92a13b80ff4bbfdf1e8', |
| 51 | text: text |
| 52 | } |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 53 | //socket.emit("SendMessage", data); |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 54 | 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éraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 81 | export default JamiMessenger; |