38 lines
1022 B
JavaScript
38 lines
1022 B
JavaScript
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;
|
|
}
|
|
}
|