search and replace ```\n< with ```\n\n< to ensure there's an empty line before closing tags
3.0 KiB
3.0 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
589fc832f9fc0f352b528e79 | Send and Display Chat Messages | 2 | 发送和显示聊天消息 |
Description
$('form').submit(function(){ /*logic*/ });
) 在您处理表单提交的代码中,您应该在定义“messageToSend”之后但在清除文本框
#m
之前发出事件。该事件应命名为“聊天消息”,数据应为“messageToSend”。 socket.emit('chat message', messageToSend);
现在,在您的服务器上,您应该收听事件“聊天消息”的套接字,并将数据命名为“message”。一旦接收到事件,应该然后发射所述事件“聊天消息”到所有插座io.emit
与数据为含“名称”和“报文”的对象。现在再次在您的客户端上,您现在应该监听事件“聊天消息”,并在收到时,将一个列表项追加到#messages
,其名称为冒号和消息!此时聊天功能齐全,并在所有客户端发送消息!当您认为自己已经做对时,请提交您的页面。如果您遇到错误,可以在此处检查项目到此时为服务器和客户端 。 Instructions
Tests
tests:
- text: 服务器侦听“聊天消息”,然后正确发出
testString: getUserInput => $.get(getUserInput('url')+ '/_api/server.js') .then(data => { assert.match(data, /socket.on.*('|")chat message('|")[^]*io.emit.*('|")chat message('|").*name.*message/gi, 'Your server should listen to the socket for "chat message" then emit to all users "chat message" with name and message in the data object'); }, xhr => { throw new Error(xhr.statusText); })
- text: 客户端正确处理和显示事件“聊天消息”中的新数据
testString: "getUserInput => $.get(getUserInput('url')+ '/public/client.js') .then(data => { assert.match(data, /socket.on.*('|\")chat message('|\")[^]*messages.*li/gi, 'You should append a list item to #messages on your client within the \"chat message\" event listener to display the new message'); }, xhr => { throw new Error(xhr.statusText); })"
Challenge Seed
Solution
// solution required
/section>