CoolFace
Apppublic

sanket3280/code-execution

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
SpectatorSession.js66 linesDownload Raw Back to models
1const mongoose = require('mongoose');2const Schema = mongoose.Schema;3 4const SpectatorSessionSchema = new Schema({5  challengeId: {6    type: Schema.Types.ObjectId,7    ref: 'Challenge',8    required: true,9    index: true10  },11  spectatorId: {12    type: Schema.Types.ObjectId,13    ref: 'User',14    required: true,15    index: true16  },17  role: {18    type: String,19    enum: ['creator', 'participant', 'public'],20    required: true21  },22  watchingParticipants: [{23    participantId: {24      type: Schema.Types.ObjectId,25      ref: 'User'26    },27    startedAt: {28      type: Date,29      default: Date.now30    }31  }],32  socketId: {33    type: String,34    required: true35  },36  ipAddress: {37    type: String,38    required: true39  },40  userAgent: {41    type: String42  },43  deviceFingerprint: {44    type: String45  },46  connectedAt: {47    type: Date,48    default: Date.now49  },50  lastActivity: {51    type: Date,52    default: Date.now53  },54  isActive: {55    type: Boolean,56    default: true,57    index: true58  }59});60 61// Compound indexes for efficient queries62SpectatorSessionSchema.index({ challengeId: 1, spectatorId: 1, isActive: 1 });63SpectatorSessionSchema.index({ socketId: 1 });64 65module.exports = mongoose.model('SpectatorSession', SpectatorSessionSchema);66