diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/App.js | 2 | ||||
-rw-r--r-- | src/Chat.js | 25 |
2 files changed, 19 insertions, 8 deletions
@@ -333,7 +333,7 @@ class App extends Component { </div> </Grid.Column> <Grid.Column width={10}> - <Chat /> + <Chat stream={currentStream} /> </Grid.Column> </Grid.Row> </Grid> diff --git a/src/Chat.js b/src/Chat.js index 54178f2..7f74a27 100644 --- a/src/Chat.js +++ b/src/Chat.js @@ -38,13 +38,20 @@ class Chat extends Component { return msg ? msg.replace(/%3A/g, ":") : ""; } - addMessage(message, color, own = false, sender = "") { + addMessage(message, stream, own = false, sender = "", color = "grey") { var ts = new Date(); this.setState( prevState => ({ chat: [ ...prevState.chat, - { content: message, color: color, own, timestamp: ts, author: sender } + { + content: message, + stream: stream, + own, + timestamp: ts, + author: sender, + color: color + } ] }), () => { @@ -74,11 +81,13 @@ class Chat extends Component { sendMessage() { const { chatMessage } = this.state; + const { stream } = this.props; + console.log(stream); if (chatMessage === "") { return; } - this.client.send("MSG:0:" + chatMessage); - this.addMessage(chatMessage, "black", true); + this.client.send(`MSG:${stream.server_name}:${chatMessage}`); + this.addMessage(chatMessage, stream.server_name, true, "black"); this.setState({ chatMessage: "" }); } @@ -86,7 +95,7 @@ class Chat extends Component { const args = line.split(":"); switch (args[0]) { case "MSG": - this.addMessage(this.translateColon(args[2]), this.chatColors[args[1]]); + this.addMessage(this.translateColon(args[2]), args[1]); break; case "FMSG": this.addMessage( @@ -97,7 +106,7 @@ class Chat extends Component { ); break; case "WELCOME": - this.addMessage("Conectado al chat, " + args[1], "green"); + this.addMessage("Conectado al chat, " + args[1], "", false, "green"); break; case "COUNT": this.setState({ chatUserCount: args[1] }); @@ -128,7 +137,9 @@ class Chat extends Component { <List.Item key={i}> [<Moment format="HH:mm:ss" date={message.timestamp} />]{" "} <span className={`ui text ${message.color}`}> - {message.content} + {`${message.stream && "[" + message.stream + "]"} ${ + message.content + }`} </span> </List.Item> ))} |