JanusVR Documentation
[BUILD] Javascript: Room Object
The room and all of its elements are easily accessible through a global object known as "room".
The room and all of its elements are easily accessible through a global object known as "room".
room.url - Read only. Contains the URL of the room.
room.objects - Contains the objects in the room. Basically a dictionary that maps the js_id attribute of each object to a script object that contains the object's attributes. Modifications to the attributes of this object will modify the attributes of the object in the room.
room.cookies - A dictionary that stores persistent states between sessions. To add a cookie, all you need to do is use the addCookie function.
room.walk_speed - Sets the user walk speed. The default value is 1.8 meters per second.
room.run_speed - Sets the user run speed. The default value is 5.4 meters per second.
room.jump_velocity - Sets the user's jump velocity. The default value is 5.0 meters per second.
room.gravity - Sets the room's gravity. The default value is -9.8 meters per second.
room.players - An object containing references to other players in the webspace, indexed by their userid.
room.playerCount - An integer referencing the number of other players in a room.
room.loadNewAsset(element, {attributes}) - Loads a new asset into memory that can be referenced in the room markup. "element" must be one of the elements that can be placed within a room, like Object, Sound, Video, Text, etc. "attributes" is a dictionary that specifies the initial attributes of the loaded object.
JanusVR allows one to programmatically generate triangular meshes using JavaScript by passing certain attributes into the room.loadNewAsset function.
room.createObject(element, {attributes}) -Creates/returns new object in the room. "element" must be one of the elements that can be placed within a room, like Object, Sound, Video, Text, etc. "attributes" is a dictionary that specifies the initial attributes of the spawned object.
room.removeObject(String js_id *or* node a,sync) - Removes the specified js_id or node, and all of its children immediately. Second parameter is an optional boolean specifying whether or not to synchronize object deletion, defaulting to "true".
room.addCookie(name,value) - Adds a cookie with a name and set value. The value will be converted into a string.
room.playSound(assetid) - Plays a sound with the given asset id.
room.pauseSound(assetid) - Pauses a sound with the given asset id.
room.seekSound(assetid, pos_in_seconds) - Seeks to position for a sound with given asset id.
room.stopSound(assetid) - Stops a sound with the given asset id.
room.playVideo(assetid) - Plays a video with the given asset id.
room.pauseVideo(assetid) - Pauses a video with the given asset id.
room.seekVideo(assetid, pos_in_seconds) - Seeks to position for a video with given asset id.
room.stopVideo(assetid) - Stops a video with the given asset id.
room.playRecording(assetid,loop) - Plays a recording with the given asset id. The second parameter is a boolean which determines whether or not the played recording will loop.
room.pauseRecording(assetid) - Pauses a recording with the given asset id.
room.seekRecording(assetid, pos_in_seconds) - Seeks to position for a recording with given asset id.
room.stopRecording(assetid) - Stops a recording with the given asset id.
room.getObjectById(js_id) - Returns the object associated with the js_id passed in as an argument.
room.closeLink(js_id) - Closes a link with the specified js_id.
room.openLink(js_id) - Opens a link with the specified js_id.
room.preventDefault() - When placed within an input related callback, native input functions will be ignored. For instance, the following code will prevent the click event from occuring.
Using the callback functions, you can create behaviour that is triggered when certain events happen.
room.onCollisionEnter(object1, object2) - Invoked when object1 collides with object2.
room.onCollisionExit(object1, object2) - Invoked when object1 exits object2's collision boundaries.
room.onLoad() - Invoked before the first update of the room. Note that this is not when the room is loaded, but when the user first steps into the room.
room.update([dt]) - Invoked on each frame before the world is drawn. dt, an optional parameter, is the amount of time in milliseconds that elapsed between this update and the previous update, useful for ensuring objects move at the same speed regardless of framerate.
room.onCollision(object, other) - Invoked twice when two objects in the room collide with each other: once with the first object as the first argument and the second object as the second agument, and once with the second object as the first argument and the first object as the second argument. Note that both elements need to have a collision radius in order to collide.
room.onClick()/room.onMouseUp() - Invoked when the user releases their mouse 1 button.
room.onMouseDown() - Invoked when the user press down the mouse 1 button.
room.onMouseMove() - Invoked when the mouse moves.
room.onMouseDrag() - Invoked when the mouse moves whilst LMB is held down.
room.onKeyDown(event) - Invoked when the user presses a key. "event" is an object with a property "keyCode" that indicates the key that was pressed (e.g. "W", "A"), and a function "preventDefault()" that when invoked prevents the default behavior for the key press from taking place. Certain buttons don't cause an event to occur (CTRL, SHIFT, TAB). Additionally using charCodeAt(0) can be useful for keys such as ENTER & BACKSPACE
room.onKeyUp(event) - The equivalent onKeyDown, but invoked when the user lets go of a key.