Files
linux-odyssey/server/src/client.js
T
wancat 95fc25d0ad feat: connect to different container by sessions
Based on the file summaries provided, the best label for this commit would be "feat". This is because the commit introduces several new features to the codebase, such as adding a new ESLint rule, adding a new property to a function, adding authentication middleware, adding a query parameter, and adding a new function to handle user authentication.: update authentication and session handling

- Add `"camelcase"` rule to ESLint configuration
- Add `containerId` property to the `newSession` object in the `createSession` function
- Add authentication middleware to the socket.io connection
- Add a query parameter `session_id` to the socket.io connection in `client.js`
- Add `defaultUser` function to handle user authentication
- Update the `authMiddleware` function to use the `defaultUser` function
- Add `defaultUser` function to handle user authentication in `auth.js`
- Update `getOrCreateContainer` function to use the `id` parameter instead of `name` parameter
2023-07-24 12:21:05 +08:00

38 lines
690 B
JavaScript

import { stdin, stdout, exit } from 'process'
import { io } from 'socket.io-client'
stdin.setRawMode(true)
stdin.resume()
stdin.setEncoding('utf8')
const sessionId = process.argv[2]
console.log(`Session ID: ${sessionId}`)
const socket = io('ws://localhost:3000', {
query: {
session_id: sessionId,
},
})
socket.on('open', function open() {
console.log('Connected to the server.')
})
socket.on('message', function incoming(data) {
stdout.write(data)
})
socket.on('close', function close() {
console.log('Disconnected from the server.')
exit()
})
stdin.on('data', (key) => {
if (key === '\u0003') {
socket.close()
exit()
} else {
socket.send(key)
}
})