Giter VIP home page Giter VIP logo

ovenlivekit-web's Introduction

OvenLiveKit for Web

What is OvenLiveKit for Web?

OvenLiveKit for Web is a JavaScript-based Live Streaming Encoder that supports WebRTC optimized for OvenMediaEngine, Sub-Second Latency Streaming Server. OvenLiveKit for Web relies on the browser's WebRTC API and wraps it to make it easy for you to broadcast WebRTC streams to OvenMediaEngine.

Demo

OvenSpace is a sub-second latency streaming demo service using OvenMediaEngine, OvenPlayer and OvenLiveKit. You can experience OvenLiveKit in the OvenSpace Demo and see examples of how it can be applied in the OvenSpace Repository.

Features

Quick Start

OvenLiveKit Demo

Installation

OveliveKit CDN

<script src="https://cdn.jsdelivr.net/npm/ovenlivekit@latest/dist/OvenLiveKit.min.js"></script>

Install via npm

$ npm install ovenlivekit
import OvenLiveKit from 'ovenlivekit'

Getting started

This is the simplest example of sending a device media stream such as a webcam to OvenMediaEngine's WebRTC Provider.

// Initialize OvenLiveKit
const ovenLivekit = OvenLiveKit.create();

// Get media stream from user device
ovenLivekit.getUserMedia().then(function () {

    // Got device stream and start streaming to OvenMediaEngine
    ovenLivekit.startStreaming('wss://your_oven_media_engine:3334/app/stream?direction=send');
});

// Or you can get media stream of your display. Choose either user device or display.
ovenLivekit.getDisplayMedia().then(function () {

    // Got device stream and start streaming to OvenMediaEngine
    ovenLivekit.startStreaming('wss://your_oven_media_engine:3334/app/stream?direction=send');
});

Quick demo

You can see a quick demo in action by cloning the repository.

  1. Clone repository
$ git clone https://github.com/AirenSoft/OvenLiveKit-Web.git
$ cd OvenLiveKit-Web
  1. Install development dependencies.
$ npm install
  1. Open the demo page using the WebPack's built-in web server.
$ npm run start

Configurations & APIs

Initialization and destroying instance

Configuration parameters could be provided to OvenLiveKit.js upon instantiation of the OvenLiveKit object.

// Configuration
var config = {
    callbacks: {
        error: function (error) {

        },
        connected: function (event) {

        },
        connectionClosed: function (type, event) {

        },
        iceStateChange: function (state) {

        }
    }
}

// Initialize ovenLivekit instance
const ovenLivekit = OvenLiveKit.create(config);

// Release all resources and destroy the instance
ovenLivekit.remove();

OvenLiveKit.create(config)

Configurations

To make the library lightweight and easy to use, only callback options are implemented now.

callbacks.error
  • type
    • Function
  • parameters
    • error: Various Type of Error
  • A callback that receives any errors that occur in an instance of OvenLiveKit.
  • Errors are could occur from getUserMedia, getDisplayMedia, webSocket, or peerConnection.
callbacks.connected
  • type
    • Function
  • parameters
    • event: event object of iceconnectionstatechange
  • This is a callback that occurs when the RTCPeerConnection.iceConnectionState becomes connected.
  • It means that the media stream is being transmitted normally to OvenMediaEngine's WebRTC Provider.
callbacks.connectionClosed
  • type
    • Function
  • parameters
    • type: (ice | websocket) Notes which connection is closed.
    • event: event object of iceconnectionstatechange or websocket
  • A callback that is fired when the websocket's onclose event occurs, or when RTCPeerConnection.iceConnectionState changes to failed, disconnected, or closed.
  • It may be that the media stream is not being sent normally to OvenMediaEngine.
callbacks.iceStateChange
  • type
    • Function
  • parameters
    • event: event object of iceconnectionstatechange
  • A callback that fires whenever RTCPeerConnection.iceConnectionState changes.
  • This is useful when checking the current streaming status.

instance.remove()

  • Release all resources(websocket, peerconnection, mediastream) and destroy the instance.

Input device listing

OvenLiveKit provides an API to get a list of user devices for convenience.

// Lists the available media input and output devices
OvenLiveKit.getDevices().then(function (devices) {

    // Got a list of user devices
    console.log(devices);

    /*
    console output is

    {
        "videoinput": [
            {
                "deviceId": "b1ab3a7041b1c9a91037b51d9c380f599f3914297b5c0ce2eb8d385dab3b8812",
                "label": "c922 Pro Stream Webcam (046d:085c)"
            }
        ],
        "audioinput": [
            {
                "deviceId": "default",
                "label": "default - Microphone(C922 Pro Stream Webcam) (046d:085c)"
            },
            {
                "deviceId": "communications",
                "label": "Communication - Microphone(C922 Pro Stream Webcam) (046d:085c)"
            },
            {
                "deviceId": "2feb7f29a130802404f47d8ad9adc9418b1a01e0a4d37e60335771aba21f328d",
                "label": "Microphone(C922 Pro Stream Webcam) (046d:085c)"
            }
        ],
        "audiooutput": [
            {
                "deviceId": "default",
                "label": "default - Headphone(2- Xbox Controller) (045e:02f6)"
            },
            {
                "deviceId": "communications",
                "label": "Communication - Headphone(2- Xbox Controller) (045e:02f6)"
            },
            {
                "deviceId": "c3d04828621712f9cc006c49486218aca0d89619ac9993809d5f082a2d13a6b0",
                "label": "Headphone(2- Xbox Controller) (045e:02f6)"
            },
        ],
        "other": []
    }
    */

}).catch(function (error) {

    // Failed to get a list of user devices
    console.log(error);
});

OvenLiveKit.getDevices()

  • This static method lists the available media input and output devices, such as microphones, cameras, headsets, and so forth.
  • videoinput, audioinput, audiooutput, other is available input/output devices. You can use deviceId to specify a device to streaming or label to make device selection UI.

Media APIs

OvenLiveKit also provides APIs to control a media stream from a user device.

<video id="myVideo"></video>
// Create instance
const ovenLivekit = OvenLiveKit.create();

// Attaching video element for playing device stream
ovenLivekit.attachMedia(document.getElementById('myVideo'));

const constraint = {
  audio: true,
  video: true
};

// Gets a device stream with a constraint that specifies the type of media to request.
ovenLivekit.getUserMedia(constraints).then(function (stream) {

    // Got device stream. Ready for streaming.
     ovenLivekit.startStreaming('wss://your_oven_media_engine:3334/app/stream?direction=send');
}).catch(function (error) {

    // Failed to get device stream.
    console.error("Error", error);
});

// Display media also works in the same way.
ovenLivekit.getDisplayMedia(constraints).then(function (stream) {

    // Got device stream. Ready for streaming.
     ovenLivekit.startStreaming('wss://your_oven_media_engine:3334/app/stream?direction=send');
}).catch(function (error) {

    // Failed to get device stream.
    console.error("Error", error);
});

instance.attachMedia(videoElement)

  • parameters
    • videoElement: HTML <video> element
  • If the video element is attached, when the media stream is received from the user device, it starts playing in the automatically set video element.
  • This can be useful when previewing the media stream you want to stream.

instance.getUserMedia(constraints)

  • parameters
    • constraints: MediaStreamConstraints dictionary. If not set the optimal input that the browser thinks is selected.
  • returns Promise
    • resolved
      • stream: MediaStream. You can use this stream for whatever you need.
    • rejected
      • error: Throws error while getting the stream from the user device.
  • This API is the most important API in OvenLiveKit. Make the OvenLiveKit streamable by getting the media stream from the user input device. You can get the media stream from any user input device you want using the constraints parameter. The device ID to be used in the constraints parameter can also be obtained from OvenLiveKit.getDevices().
  • For natural behavior, you can have the browser automatically select the device stream without passing a constraints parameter. However, if you want to control the device stream strictly (e.g., specify input devices, video resolution, video frame rates), you can control it by passing the constraints parameter.

instance.getDisplayMedia(constraints)

  • parameters
  • returns Promise
    • resolved
      • stream: MediaStream. You can use this stream for whatever you need.
    • rejected
      • error: Throws error while getting the stream from the display.
  • Captures the entire screen, application window, or browser tab.

instance.setMediaStream(stream)

  • parameters
    • stream: MediaStream - The valid MediaStream you want OvenLiveKit to utilize.
  • returns Promise
    • resolved
      • stream: MediaStream - Returns the same stream provided as an input, confirming its successful attachment.
    • rejected
      • error: Throws an error if an invalid MediaStream is provided.
  • The setMediaStream function is designed to let developers directly attach an external or pre-existing MediaStream. This can be particularly useful when you're sourcing the stream not directly from user input devices, but other origins.

Streaming APIs

Congrats on getting the media stream from the user device and then ready to stream into OvenMediaEngine.

// Create instance
const ovenLivekit = OvenLiveKit.create();

ovenLivekit.getUserMedia().then(function () {

    const connectionConfig = {
        iceServers : null ,
        iceTransportPolicy: null,
        maxBitrate: null
    }

    // Got media stream from user device and start to stream to OvenMedieEngeine
    ovenLivekit.startStreaming(connectionUrl, connectionConfig);
});

instance.startStreaming(connectionUrl, connectionConfig)

  • parameters
    • connectionUrl: The connection URL to OvenMediaEngine is explained here.
    • connectionConfig: See ConnectionConfig details next.
  • When this API is called, the media stream starts to be streamed according to OvenMediaEngine's signaling protocol.

ConnectionConfig

preferredVideoFormat
  • type
    • String: Video codec name (eq. H256, VP8)
  • If set the specified codec will be preferred if available.
iceServers
iceTransportPolicy
maxVideoBitrate
  • type
    • Number: Unit is Kbps.
  • If set limits max bitrates of streaming to OvenMediaEngine.
sdp.appendFmtp
  • type
    • String: String you want to append to a=fmtp of SDP.
  • If set video format is appended to the a=fmtp sections of SDP.

instance.stopStreaming()

  • Close peer connection and websocket associated with OvenMediaEngine.

For more information

License

OvenLiveKit for Web is licensed under the MIT license.

About AirenSoft

AirenSoft aims to make it easier for you to build a stable broadcasting/streaming service with Sub-Second Latency. Therefore, we will continue developing and providing the most optimized tools for smooth Sub-Second Latency Streaming.

Would you please click on each link below for details:

ovenlivekit-web's People

Contributors

getroot avatar lee-hammer99 avatar marcusotterstad avatar saggiyogesh avatar sangwonoh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ovenlivekit-web's Issues

Delay in Start the Streaming of Screen Share

Hi Oven Team,

When I tried start the Screen Share streaming, it takes some time to start the streaming.
I didn't find the reason of the delay in the start.

Hoping for fixed this issue soon.

Screen sharing?

Hi! Can you, please, test and add example to documentation for screen sharing using OvenLiveKit?

It's funny, but I made it work simply by replacing ovenLivekit.getUserMedia with ovenLivekit.getDisplayMedia. As a result captured screen stream gets displayed in my video element and stream is sent to media engine. In my test scenario constrains were set to video: { width: 1280, height: 720 } and I was sharing browser tab. I am not sure if I simply got lucky that it did work and if display media is supported and what constrains should I use?

Thanks!

PS I just noticed the previous question was exactly regarding same problem and checking

function getDisplayMedia(constraints) {

but still not sure what to do with constraints and video element as I am having problems trying to share app window or entire screen

Problem with getDevices function

hello

If width and height are set when retrieving audio and video sources. In some cases, the browser has a "NotFoundError" error, but sometimes it's fine, and I think it's a browser problem. However, I still recommend not setting width and height, or setting a smaller resolution

image

Webrtc push stream minimum bit rate

Webrtc dynamically calculates the bit rate of the push stream according to the bandwidth. At the beginning of the push stream, the picture will be blurred, and as the real-time bit rate increases, the picture will become clearer. But I still hope webrTC will have good video resolution in the first few seconds after the stream is pushed. Could you please set SDP to set the minimum bit rate?

Device: pc
OS: windows11
Browser:Google Chrome 96.0.4664.45
OvenMediaEngine Version: v0.12.7
push tool:OvenLiveKit-Web v1.0.2

Need to access audio streaming DOM to build a mute button

Hi,

I am working on adding a mute/unmute button to the kit that streams audio (no video).

I am trying to access with DOM the incoming stream from a user's microphone, but can't really accomplish this.

Here is a code snippet:

<script>
// Initialize OvenLiveKit
let ovenLivekit = OvenLiveKit.create();
// Get media stream from user device
ovenLivekit.getUserMedia({video: false, audio: true}).then(function () {
    // Got device stream and start streaming to OvenMediaEngine
    ovenLivekit.startStreaming('wss://your_oven_media_engine:3333/app/stream?direction=send');
});

document.getElementById("muteBtn").onclick = function(evt) {
const newState = !ovenLivekit.getAudioTracks[0].enabled;
document.getElementById("muteBtn").innerHTML = newState ? "&#x25B6;&#xFE0F;" : "&#x23F8;&#xFE0F;";
ovenLivekit.getAudioTracks[0].enabled = newState;
 }
</script>

=======
I am trying to access the microphone stream with ovenLivekit.getAudioTracks[0], but it does not work. Returns "Uncaught TypeError: Cannot read properties of undefined (reading '0')"

Any help with this is very much appreciated!

Critical issue on iOS 15.1

Apple released iOS 15.1 yesterday and now when sending a WebRTC stream in the browser, the page suddenly reloads 😢

I first observed this in my application, but checked on the OvenPlayer demo page and it is behaving the same way.

The problem is, there are no errors in the console even up to the moment the page reloads. The stream even appears to connect fine so this could be an issue with the WebKit browser itself. After a couple of attempts you will see a generic error of 'A problem repeatedly occurred on {URL}'.

@SangwonOh are you able to reproduce this issue? Any idea what is happening? 🙏

connectionClosed callback doesn't work if stream is stopped from client side

Testing WebRTC at https://ovenplayer.com/docs/demo_input.html

connectionClosed callback is never called when I stop stream on client side. It works when connection is closed from server side.

Obviously socket connections is not getting closed properly from client side as it should happen here

webSocket.onclose = function (e) {

So webSocket.onclose never happens and that's strange as instance.webSocket.close(); is called here

if (instance.webSocket) {

Can you please double check on your side? Thanks!

Can't get 720x1280 stream from webcam

Hi! I am trying to get 720x1280 stream, but it doesn't seem to work regardless of what settings I am passing as constraints on a client side. Inside OvenLiveKit-Web it's obvious that you set params in a way to get max possible resolution, but even when I set video: true to let the Kit take the resolution, oven media engine outputs 480x640 max. Maybe I am missing something obvious? I did try passing video: { deviceId: undefined, width: 1280, height: 720 } in constraints and a bunch of other settings without any luck. At some point I got 720 as oven media engine output while testing, but couldn't reproduce it.

// High resolution video constraints makes browser to get maximum resolution of video device.

  const constraints = {
      audio: { deviceId: undefined },
      video: { deviceId: undefined, width: 1920, height: 1080 }
  };

Help with WebRTC Steaming - Mirror Input Horizontally

Hi, I am trying to mirror the input steam from the user's mediaDevice horizontally but I don't know how.

ovenLivekit.getUserMedia().then(function () {

            // Got device stream and start streaming to OvenMediaEngine
            ovenLivekit.startStreaming('ws://my-local-ip:3333/app/stream?direction=send');
        });

Taking 30-40 sec to load input devices list in ionic android

I am implementing this on ionic for android, below code is taking too much time to get list of device(videoinput, audioinput).

await OvenLiveKit.getDevices().then((devices) => {
			this.deviceList = devices.videoinput;
		})

I have just started implementing this im new to this kit web

it is working on html & javascript issue is only for ionic android

Support for Attaching External MediaStreams

I've been utilizing OvenLiveKit-Web extensively and appreciate its robustness. However, I've come across a scenario where I need to attach an external or pre-existing MediaStream to OvenLiveKit. To my knowledge, it seems the current API primarily supports obtaining the media stream through getUserMedia.

Proposed Feature:
Introduce a method, say setMediaStream(stream), allowing developers to attach an external MediaStream.

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.