Giter Site home page Giter Site logo

metartc2's Introduction

MetaRTC

Metaverse party system.

Abstracts WebRTC into rooms of peers. Uses a presence server to negotiate P2P connections and presents an API to transmit P2P data and media streams.

The presence server is here.

API

To use the API, first import the script:

import {XRChannelConnection} from 'https://raw.githack.com/webaverse/metartc/master/xrrtc.js';

Alternatively, you can clone the repo and include the files in your project.

XRChannelConnection

Represents a WebSocket connection to the presence server. Create an XRChannelConnection to establish yourself as a peer in the room:

const roomId = 'meta'; // a string identifying the room
const channelConnection = new XRChannelConnection(`wss://presence.exokit.org/?c=${encodeURIComponent(roomId)}`);

close() : void

Closes the XRChannelConnection and any associated peers.

'peerconnection' event

Represents a peer joining the room.

channelConnection.addEventListener('peerconnection', e => {
  const peerConnection = e.data;
  // ...
});

'close' event

Emitted on the XRChannelConnection closing. Do not use the connection after this event.

XRPeerConnection

Represents a connection to a peer. Emitted from XRChannelConnection.

send(method : String, data : any) : void

Sends the given method and data to the peer, where it will be emitted. data must be JSON-serializable.

// local
peerConnection.send('pose', {
  position: [1, 2, 3],
});

// remote
peerConnection.addEventListener('pose', e => {
  console.log(e.data); // logs [1, 2, 3]
});

close() : void

Forcefully closes the XRPeerConnection. Both ends will get a close event.

'open' event

Emitted on the peer connection opening for data transfer.

'close' event

Emitted on the XRPeerConnection closing. Do not use the connection after this event.

Other events

Any method passed to send will become an event type on the other end of the XRPeerConnection.

TODO

  • Document microphone media streams
  • Document screenshare media streams

metartc2's People

Contributors

avaer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.