The user-defined data associated with this socket instance. This can be set when the socket is created via Bun.connect({ data: ... })
. It can be read or updated at any time.
property
Socket.data
data: Data
// In a socket handler
function open(socket: Socket<{ userId: string }>) {
console.log(`Socket opened for user: ${socket.data.userId}`);
socket.data.lastActivity = Date.now(); // Update data
}