npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wle-peerjs-networking

v1.0.3

Published

A small set of components for [Wonderland Engine](https://wonderlandengine.com/) for basic networking functionality using [peer.js](https://peerjs.com/).

Downloads

6

Readme

Wonderland Engine PeerJS Networking Components

A small set of components for Wonderland Engine for basic networking functionalities using peer.js.

This project uses host-client architecture, where the host can simply host by calling host() and a client can join by calling join(). It supports voice chat out of the box and also handles disconnects and kicking. It can be used as a started for a variety of multi user WebXR projects with Wonderland Engine.

This repository includes a basic scene that you can use as a template for your projects. Anything within the project not documented here is included as part of the polishing of the scene and has been imported from other repositories with permission. Setup instructions can also be found below.

Setup

You can reference the included Project/example-scene.wlp scene.

To install into an existing project, install the components via npm package and then follow the steps in Project Setup.

NPM Package

Install the components from npm as follows:

npm install --save wle-peerjs-networking

Project Setup

Using the default Wonderland Engine setup, after adding the hand objects, you should have the following scene structure for the user:

Player
├── NonVrCamera
├── EyeLeft
├── EyeRight
├── RightHand
└── LeftHand

This structure is useful for transmitting the positions and rotations of the camera and hands. These are used in the networking component.

Next, we need to create an object that contains all the networked objects and components.

This project uses a technique called object pooling for the connected players. This means that every object(s) for each joining player is already instantiated in the scene on startup.

Create an object on "root" and call it something like PeerNetworkedPlayerPool. This object will contain two components from this repository: peer-networked-player-pool and peer-manager. For the peer-manager, make sure your serverId is changed to a long and unique string. The placeholder text will work, but might cause issues if another instance of peer.js is using that id. The parameter networkSendFrequencyInS determines how often a client/the host sends packages over, this can be kept at the default. If you wish to have a higher frequency (means higher refresh rate), you could also lower it. A value of 0 would send packages every frame, for example. Set the player's head (eye for VR camera) and hands and also networkPlayerPool (this can be the same object).

After this has been done, You need to create the pool objects for each player. These need to be a child of the previously created object or the pooling will not work. Let's create a child object of PeerNetworkedPlayerPool called PeerNetworkedPlayer and a peer-networked-player component onto it. Additionally the following hierarchy (naming important here) needs to be recreated under the object:

PeerNetworkedPlayer
├── Head
├── RightHand
└── LeftHand

You can add meshes to each object for visualization, if you like. We can now copy the hierarchy of PeerNetworkedPlayer and the scene is done. Just call either the host() or join() functions to see your scene in action.

You might want to expose a reference in peer-manager's init such as window.peerManager = this for testing via console

Public members

peer-manager component

| Functions | Description | | ------------ | ------------ | | host() | Hosts a server with serverId as id | | join() | Joins a server with serverId as Id | | connect(id) | Joins a server with the supplied id | | disconnect() | Disconnects from the server (client) / Ends the server (host) | | kick(id) | (Host) Kicks the user with the id | | sendPackage(key, data) | Sends a package to all users (host & clients), that calls the correspondingly registered callback in addNetworkDataRecievedCallback | | toggleMute() | Toggles the user's audio input's mute setting. | | setOwnMute(mute) | Sets the user's audio input's mute setting | | setOtherMute(id, mute) | Sets another user's audio output's mute setting. | | addConnectionEstablishedCallback(f) / removeConnectionEstablishedCallback(f) | Adds/removes a function to/from a callback list, that gets called when a connection is established. (host & client) | | addDisconnectCallback(f) / removeDisconnectCallback(f) | Adds/removes a function to/from a callback list, that happens when a disconnection occurs. | | addNetworkDataRecievedCallback(key, f) / removeNetworkDataRecievedCallback(key) | Adds a function callback, that gets called if a package with the registered key is recieved. See sendPackage(key, data).|

| Variables | Description | | ------------ | ------------ | | activePlayers | Object containing currently connected active players. | | peer | Contains the peer.js object with the connection, id, etc.|

Possible future improvements:

  • Expanding pool: allow more users to join then the defined amount in the scene via dynamically expanding (and perhaps shrinking) the pool.

Credits

peer.js - Copyright (c) 2015 Michelle Bu and Eric Zhang, http://peerjs.com Tone.js - Copyright (c) 2014-2020 Yotam Mann https://github.com/Tonejs/Tone.js