[Fix] Convert message from Buffer to String

Fixed the issue - https://github.com/javascript-tutorial/en.javascript.info/issues/2870
This commit is contained in:
Umakant Vashishtha 2022-02-10 19:48:31 +05:30 committed by GitHub
parent d7c8c7506e
commit d5cce94650
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,7 @@ function accept(req, res) {
function onConnect(ws) { function onConnect(ws) {
ws.on('message', function (message) { ws.on('message', function (message) {
message = message.toString();
let name = message.match(/([\p{Alpha}\p{M}\p{Nd}\p{Pc}\p{Join_C}]+)$/gu) || "Guest"; let name = message.match(/([\p{Alpha}\p{M}\p{Nd}\p{Pc}\p{Join_C}]+)$/gu) || "Guest";
ws.send(`Hello from server, ${name}!`); ws.send(`Hello from server, ${name}!`);