i am trying use with enabled3d.io + geckos.io but Error: Parsing file ../server.js : Unexpected token Why am I getting this error
this is my code
import geckos from '@geckos.io/server'
import { createServer } from 'http'
import { promises } from "fs";
const { readFile, writeFile } = promises;
// import http from 'http'
const io = geckos()
const indexHtml = await readFile('src/index.html', { encoding: 'utf-8' })
const geckosJs = await readFile('src/js/geckos.io-client.2.1.2.min.js', {
encoding: 'utf-8',
})
const requestListener = async (req, res) => {
if (req.url === '/')
return res.writeHead(200, { 'Content-Type': 'text/html' }).end(indexHtml)
if (req.url === 'src/js/geckos.io-client.2.1.2.min.js')
return res
.writeHead(200, { 'Content-Type': 'application/javascript' })
.end(geckosJs)
return res.writeHead(404).end()
}
const server = createServer(requestListener)
io.addServer(server)
io.onConnection(channel => {
channel.onDisconnect(() => {
console.log('User ' + client.id + ' connected, there are ' + io.engine.clientsCount + ' clients connected')
//Add a new client indexed by his id
clients[client.id] = {
position: [0, 0, 0],
rotation: [0, 0, 0]
}
//Make sure to send the client it's ID
client.emit('introduction', client.id, io.engine.clientsCount, Object.keys(clients))
//Update everyone that the number of users has changed
io.sockets.emit('newUserConnected', io.engine.clientsCount, client.id, Object.keys(clients))
console.log(`${channel.id} got disconnected`)
})
//Handle the disconnection
client.on('disconnect', ()=>{
//Delete this client from the object
delete clients[client.id]
io.sockets.emit('userDisconnected', io.engine.clientsCount, client.id, Object.keys(clients))
console.log('User ' + client.id + ' dissconeted, there are ' + io.engine.clientsCount + ' clients connected')
})
channel.on('chat message', data => {
console.log(`got ${data} from "chat message"`)
// emit the "chat message" data to all channels in the same room
io.room(channel.roomId).emit('chat message', data)
})
})
io.listen(3000) // default port is 9208
i'm making WebGL multiplay service As a novice developer, I'm looking at examples, but I have a question I don't know. and Error screenshot is here