Code Monkey home page Code Monkey logo

badnintendo / 2030xwebrtc Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 29 KB

2030xwebRTC is a robust npm package by BadNintendo, designed for seamless WebRTC (Web Real-Time Communication) integration. It supports peer-to-peer connections, data channels, and media streaming, simplifying front-end to back-end communication. Ideal for real-time applications, it enhances ease of use and functionality for WebRTC implementation.

JavaScript 100.00%

2030xwebrtc's Introduction

2030xwebRTC

2030xwebRTC is a powerful and versatile npm package designed to handle WebRTC (Web Real-Time Communication) functionalities for front-end to back-end communication. This package provides an extensive set of features to enable peer-to-peer connections, data channels, media streaming, and more. Developed by BadNintendo, 2030xwebRTC aims to simplify the integration and usage of WebRTC in your projects.

Installation

To install the 2030xwebRTC package, use the following command:

npm i @badnintendo/webrtc2030

Usage

Basic Example

Here is a basic example demonstrating how to create a peer connection, generate an SDP offer, and handle ICE candidates:

const { RTCPeerConnection, RTCSessionDescription, RTCIceCandidate } = require('2030xwebRTC');

const pc = new RTCPeerConnection();

pc.on('icecandidate', ({ candidate }) => {
  if (candidate) {
    console.log('New ICE candidate: ', candidate);
  } else {
    console.log('All ICE candidates have been sent');
  }
});

const offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };

pc.createOffer(offerOptions)
  .then((offer) => pc.setLocalDescription(offer))
  .then(() => console.log('Local description set:', pc.localDescription))
  .catch((error) => console.error('Failed to create offer:', error));

Advanced Features

2030xwebRTC provides advanced functionalities, including handling media devices, nonstandard WebRTC interfaces, and custom error handling. Below are some examples:

Handling Media Devices

const { mediaDevices } = require('2030xwebRTC');

// Get user media with specified constraints
const constraints = { video: true, audio: true };

mediaDevices.getUserMedia(constraints)
  .then((stream) => {
    console.log('Got media stream:', stream);
  })
  .catch((error) => {
    console.error('Failed to get user media:', error);
  });

Using Nonstandard Interfaces

const { nonstandard } = require('2030xwebRTC');

const videoSource = new nonstandard.RTCVideoSource();
const videoSink = new nonstandard.RTCVideoSink(videoSource);

// Example: Convert I420 to RGBA
const i420Frame = getI420Frame(); // Assuming this function provides an I420 frame
const rgbaFrame = nonstandard.i420ToRgba(i420Frame);

console.log('Converted RGBA frame:', rgbaFrame);

Error Handling

2030xwebRTC includes custom error classes for handling RTC-related errors:

const { RTCError } = require('2030xwebRTC');

try {
  // Some operation that may throw an error
  throw new RTCError(1, 'Invalid constraints type');
} catch (error) {
  console.error('RTC Error:', error);
}

API Documentation

Exports

  • RTCDataChannel

    • Corresponds to the original RTCDataChannel.
    • Handles data channels for peer-to-peer communication.
  • RTCDataChannelEvent

    • Corresponds to the original RTCDataChannelEvent.
    • Handles events related to data channels.
  • RTCIceCandidate

    • Corresponds to the original RTCIceCandidate.
    • Represents ICE candidates used in the connection process.
  • RTCPeerConnection

    • Corresponds to the original RTCPeerConnection.
    • Manages the connection between peers.
  • RTCPeerConnectionIceEvent

    • Corresponds to the original RTCPeerConnectionIceEvent.
    • Handles ICE events during the connection process.
  • RTCRtpReceiver

    • Corresponds to the original RTCRtpReceiver.
    • Manages the receipt of RTP media.
  • RTCRtpSender

    • Corresponds to the original RTCRtpSender.
    • Manages the sending of RTP media.
  • RTCRtpTransceiver

    • Corresponds to the original RTCRtpTransceiver.
    • Manages both sending and receiving of RTP media.
  • RTCSctpTransport

    • Corresponds to the original RTCSctpTransport.
    • Manages SCTP transport for data channels.
  • RTCSessionDescription

    • Corresponds to the original RTCSessionDescription.
    • Represents the configuration of a connection.
  • getUserMedia

    • Corresponds to the original getUserMedia.
    • Allows access to media devices such as cameras and microphones.
  • mediaDevices

    • Corresponds to the original mediaDevices.
    • Provides access to media device functionalities.
  • nonstandard

    • Corresponds to the original nonstandard.
    • Includes nonstandard WebRTC functionalities like i420ToRgba, RTCAudioSink, RTCAudioSource, RTCVideoSink, RTCVideoSource, and rgbaToI420.
  • RTCDataChannelMessageEvent

    • New class for handling RTCDataChannel messages.
    • Represents a message event in an RTCDataChannel.
  • RTCError

    • New class for handling RTC-related errors.
    • Custom error class for RTC-related operations.
  • RTCPeerConnectionIceErrorEvent

    • New class for handling ICE candidate errors.
    • Represents an ICE candidate error event.

Testing

To test the functionality of 2030xwebRTC, you can use the provided example in the usage section. Here's a simple script to verify the installation and basic operations:

node test/2030xwebRTC.test.js

Example Test Script: test/2030xwebRTC.test.js

const { RTCPeerConnection } = require('2030xwebRTC');

const pc = new RTCPeerConnection();

pc.on('icecandidate', ({ candidate }) => {
  if (candidate) {
    console.log('New ICE candidate: ', candidate);
  } else {
    console.log('All ICE candidates have been sent');
  }
});

const offerOptions = { offerToReceiveAudio: true, offerToReceiveVideo: true };

pc.createOffer(offerOptions)
  .then((offer) => pc.setLocalDescription(offer))
  .then(() => console.log('Local description set:', pc.localDescription))
  .catch((error) => console.error('Failed to create offer:', error));

Conclusion

2030xwebRTC is a comprehensive WebRTC package designed to handle a wide range of WebRTC functionalities, from peer connections to media handling. With its robust API and extensive features, 2030xwebRTC simplifies the process of integrating WebRTC into your projects.

For more information, visit the 2030xwebRTC GitHub repository.

2030xwebrtc's People

Contributors

badnintendo avatar

Watchers

 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.