feat: initial commit at project root
This commit is contained in:
37
internal/session/session.js
Normal file
37
internal/session/session.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import crypto from 'crypto';
|
||||
|
||||
/**
|
||||
* Generates a cryptographically secure UUID version 4.
|
||||
* @returns {string}
|
||||
*/
|
||||
export function generateUUIDv4() {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
|
||||
/**
|
||||
* Session models an active call coordination session.
|
||||
*/
|
||||
export class Session {
|
||||
/**
|
||||
* @param {string} rideID
|
||||
* @param {string} driverID
|
||||
* @param {string} passengerID
|
||||
* @param {number} durationMs
|
||||
* @param {string} [driverIP]
|
||||
* @param {string} [passengerIP]
|
||||
*/
|
||||
constructor(rideID, driverID, passengerID, durationMs, driverIP = null, passengerIP = null) {
|
||||
this.sessionID = generateUUIDv4();
|
||||
this.rideID = rideID;
|
||||
this.driverID = driverID;
|
||||
this.passengerID = passengerID;
|
||||
this.driverIP = driverIP;
|
||||
this.passengerIP = passengerIP;
|
||||
this.createdAt = new Date();
|
||||
this.expiresAt = new Date(this.createdAt.getTime() + durationMs);
|
||||
this.status = 'waiting'; // "waiting" | "active" | "ended"
|
||||
this.driverConn = null;
|
||||
this.passengerConn = null;
|
||||
this.timer = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user