Apps Home
|
Create an App
Private Camera
Author:
braveg1rl
Description
Source Code
Launch App
Current Users
Created by:
Braveg1rl
var appName = "Private Camera" var aboutText = "Private Camera. An app made by braveg1rl." var helpText = "This room is running the Private Camera app, made by braveg1rl. \n\ \n\ By using this app in your room, anyone will be able to enter your room, \n\ read your profile, follow you and possibly chat with you, but they won't \n\ be able to see your camera, whether you are broadcasting or not.\n\ \n\ The only way a user can see your camera is if you explicitly grant them access.\n\ \n\ This app is perfect for you if you:\n\ - like to do cam2cam sessions with Chaturbate performers\n\ - don't want your camera to be visible to all other Chaturbate users\n\ - want to control exactly which performers can view your cam, without having to\n\ change the room password\n\ - want other people to always be able to view your profile\n\ - want other people to chat with you without seeing you\n\ - want other people to be able to follow you on Chaturbate\n\ \n\ Go to https://chaturbate.com/apps/private-camera"; createStringList = function(arr) { return { strings: (arr ? arr : []), getLength: function() { return this.strings.length }, contains: function (str) { return cbjs.arrayContains(this.strings, str) }, add: function (str) { this.strings.push(str) }, addIfUnique: function(str) { if(!this.contains(str)) this.add(str) }, removeIfContained: function(str) { if(this.contains(str)) this.remove(str) }, remove: function (str) { cbjs.arrayRemove(this.strings, str) }, toString: function() { return this.strings.join(', ') }, applyToAll: function(fn) { for(var i = 0; i < this.strings.length; i++) { fn(this.strings[i]) } } // applyToAll } } createIndexObject = function(index) { return { index: (index ? index : {}), getEntry: function(name) { return this.index[name] }, hasEntry: function(name) { return !!this.index[name]}, removeEntry: function(name) { delete this.index[name] }, applyToAll: function(fn) { for(var entryName in this.index) { if(this.index.hasOwnProperty(entryName)) { fn(entryName, this.index[entryName]) } } // loop } //.applyToAll() } } transformUser = function(user) { // takes CB user as input return { username: user.user, isMod: user.isMod, isBroadcaster: user.user == cb.room_slug, gender: user.gender, notify: function(msg) { notifyUser(this.username, msg) } } } // Some setup var log = cb.log var broadcasterName = cb.room_slug notifyAll = cb.sendNotice notifyUser = function(username, msg) { cb.sendNotice(msg, username) } notifyBroadcaster = function(msg) { cb.sendNotice(msg, cb.room_slug) } cb.settings_choices = []; // We're gonna start limitCam right away cb.limitCam_start() cb.onDrawPanel(function(user) { // raw cb user object var not = camera.hasViewer(user.user) ? "" : "not " var allowed = camera.allowedViewers.getLength() == 0 ? "[nobody]" : camera.allowedViewers.toString() var watchers = camera.watchers.getLength() == 0 ? "[nobody]" : camera.watchers.toString() return { 'template': '3_rows_11_21_31', 'row1_value': "You are " + not + "allowed to view the camera.", 'row2_value': 'Allowed to watch: ' + allowed, 'row3_value': 'Currently watching: ' + watchers }; }); cb.onEnter(function(cbUser) { user = transformUser(cbUser) user.notify("Welcome to my room, " + user.username + "!") user.notify(helpText) room.addUser(user.username) camera.updateWatchers() cb.drawPanel() }); // onEnter cb.onLeave(function(cbUser) { room.removeUser(cbUser.user) camera.updateWatchers() cb.drawPanel() }); // onLeave cb.onMessage(function (message) { // super noisy log(message); var commandName, argString, messageMatches; var messageText = message.m; if(!message.m) { log("Got a message without a message text (m)") log(message) log("Aborting") return } var command; commander = { username: message.user, isMod: message.is_mod, isBroadcaster: (message.user = broadcasterName), gender: message.gender, notify: function(msg) { notifyUser(this.username, msg) } } if(!room.hasUser(commander.username)) { log("User " + commander.username + " said something, but was not in the list of users. Adding now.") room.addUser(commander.username) } if(messageMatches = messageText.match(/^\/([A-z]+)(?: (.*))?$/)) handleCommand(commander, messageMatches[1], messageMatches[2]) else log("Got a non-command message: " + messageText) }); // onMessage function handleCommand(commander, commandName, argString) { argString = argString ? argString : "" log("HANDLING COMMAND " + commandName + " " + argString) if(!commands.hasEntry(commandName)) { commander.notify("Invalid command. '" + commandName + "' not found") return } command = commands.getEntry(commandName) if(!command.isAllowed(commander)) { notifyBroadcaster(commander.username + "attempted to use command " + commandName + "but wasn't allowed to.") commander.notify("Sorry, this command is not allowed") return } if(!command.validateArguments(argString)) { notifyBroadcaster(commander.username + " ran command " + commandName + " with invalid arguments: '" + argString + "'") commander.notify("You used invalid arguments for command " + commandName) return } command.run(commander, argString) if(command.needsPanelUpdate) { cb.drawPanel() } } camera = { allowedViewers: createStringList([]), watchers: createStringList([]), hasViewer: function(username) { return this.allowedViewers.contains(username) }, updateWatchers: function() { // Add any new allowedViewers to the watchers list, if they're in the room var watchers = this.watchers this.allowedViewers.applyToAll(function(username) { if(room.hasUser(username)) { watchers.addIfUnique(username) } else { log("room doesn't have user " + username) } }) // for all allowedViewers // For each watcher, check if they're still in the room and still allowed to watch this.watchers.applyToAll(function(username) { if(!camera.hasViewer(username)) watchers.remove(username) if(!room.hasUser(username)) watchers.remove(username) }); // for all allowedViewers }, // updateWatchers addViewer: function(commanderName, username) { camera.addViewers(commanderName, [username]) }, addViewers: function(commanderName, usernames) { camera = this usernames = createStringList(usernames) usernames.applyToAll(function(username) { if(camera.allowedViewers.contains(username)) { commander.notify(username + " is already allowed to view the camera") } else { cb.limitCam_addUsers([username]) camera.allowedViewers.add(username) notifyUser(username, commanderName + " has allowed you to view the camera.") } }); // for all usernames this.updateWatchers() }, // addViewers removeViewer: function(commanderName, username) { camera.removeViewers(commanderName, [username]) }, removeViewers: function(commanderName, usernames) { var camera = this usernames = createStringList(usernames) usernames.applyToAll(function(username) { if(!camera.allowedViewers.contains(username)) { commander.notify(username + " wasn't allowed to view the camera") } else { cb.limitCam_removeUsers([username]) camera.allowedViewers.remove(username) notifyUser(username, commanderName + " has removed your right to view the camera.") } }); // for all usernames this.updateWatchers() } // removeViewers } /// camera object commands = createIndexObject({ addViewer: { description: "Adds a camera viewer.", needsPanelUpdate: true, validateArguments: function (argString) { return (argString.match(/^[A-z0-9_]+$/)) ? true : false }, isAllowed: function(commander) { return commander.isMod || commander.isBroadcaster }, run: function(commander, argString) { camera.addViewer(commander.username, argString) }, }, showAllowed: { description: "Shows list of users that are currently allowed to see the camera", isAllowed: function(commander) { return commander.isMod || commander.isBroadcaster }, run: function(commander, args) { commander.notify("Currently allowed viewers: " + camera.allowedViewers) } }, // showAllowed removeViewer: { needsPanelUpdate: true, validateArguments: function (argString) { return (argString.match(/[A-z]+/)) ? true : false }, isAllowed: function(commander) { return commander.isMod || commander.isBroadcaster }, run: function(commander, argString) { camera.removeViewer(commander.username, argString) } }, // removeVIewer about: { run: function(commander) { commander.notify(aboutText) } }, help: { run: function(commander) { commander.notify(aboutText) commands.getEntry("showCommands").run(commander) } }, showCommands: { run: function(commander) { var lines = [] lines.push("AVAILABLE COMMANDS:") commands.applyToAll(function(commandName, command) { lines.push(" * " + commandName) }) commander.notify(lines.join("\n")) } // run } // showCommands }); // commands object commands.applyToAll(function (commandName, command) { if(!command.isAllowed) { command.isAllowed = function() { return true;} } if(!command.validateArguments) { command.validateArguments = function() { return true; } } }) room = { currentUsers: createStringList([]), pastUsers: createStringList([]), hasUser: function(username) { return this.currentUsers.contains(username) }, hasNewUser: function(username) { return this.currentUsers.contains(username) && !this.pastUsers.contains(username) }, hasPastUser: function(username) { return this.pastUsers.contains(username) }, removeUser: function(username) { if(this.hasUser(username)) { this.currentUsers.remove(username) } if(this.pastUsers.contains(username)) { log(username + "was in the past viewers list, while being removed") } }, addUser: function(username) { if(this.hasUser(username)) { log(username + "is already in the currentUsers list") } else { this.currentUsers.add(username) } if (this.hasPastUser(username)) { // the user has viewed the cam before, left, then has returned this.pastUsers.remove(username) } } } // room object
© Copyright Chaturbate 2011- 2025. All Rights Reserved.