diff options
author | Renard | 2020-03-11 22:21:29 -0300 |
---|---|---|
committer | Renard | 2020-03-11 22:21:29 -0300 |
commit | 524a30b69d5853878200fa41af55020f76b65f1b (patch) | |
tree | 4388dc0fe17847059e73f82649a146d56e725a87 | |
parent | 0530339dd1b45cf187e183b22cf1cbcb90503a08 (diff) | |
download | bairadio-app-524a30b69d5853878200fa41af55020f76b65f1b.tar.gz bairadio-app-524a30b69d5853878200fa41af55020f76b65f1b.tar.xz bairadio-app-524a30b69d5853878200fa41af55020f76b65f1b.zip |
Cambio de protocolo MSG
-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> ))} |