Cloudinary client-side package for live video streaming
npm install @cloudinary/js-streamingCloudinary
==========
Cloudinary is a cloud service that offers a solution to a web application's entire image and video management pipeline.
Easily upload images and videos to the cloud. Automatically perform smart resizing, cropping and conversion
without installing any complex software.
Cloudinary offers comprehensive APIs and administration capabilities and is easy to integrate with any web application,
existing or new.
Video live-stream
=================
Cloudinary provides an end-to-end live video streaming solution, with on the fly video effects and transformations.
When using the library in your website this is what happens:
1. Video is streamed from the device's camera.
2. The video is up-streamed through Cloudinary, providing the streaming user with a Cloudinary public id and resource
url of the stream.
3. The stream is now publicly available through that url, and can be fed into any streaming-supported video player.
4. If any transformations and effects were added to the stream (during configuration, see below) all the viewers will
see the modified stream.
1. Sign up for a free account.
2. Create an upload preset here, and enable
the *live-streaming* setting. This is also the place to add any wanted effects and transformations under the
'Incoming transformations' section.
3. fetch the library from npm:
``npm install @cloudinary/js-streaming`
There are several optional parameters:
* stream: The MediaStream to use as the streaming source. Required only if you obtain a MediaStream object yourself with a getUserMedia request or the getStream helper function, rather than have the library get a stream from the default device by itself. debug
* : Log level (disabled by default), one of, or array of `['trace', 'debug', 'vdebug', 'log', 'warn', 'error']`. pass in `'all'` to print allbandwidth
messages.
: Bandwith, in bits. Default is 1Mbit/s (1024 1024).hlsTarget
* : [true/false], When true, will stream live using hls protocol.fileTarget
* : [true/false], When true, will save an mp4 file in your Cloudinary media library.facebookUri
* : A Facebook streaming URI used to direct the stream to facebook. youtubeUri
Supplied by facebook when configuring Facebook streaming.
* : A Youtube streaming URI used to direct the stream to Youtube. Supplied by youtube when configuringevents
Youtube streaming.
* : callback for events, supporting the following functions:start
* : Called when the streaming starts. Includes the recording Id. stop
* : Called when the streaming stops. Includes the recording Id.error
* : Called when the library encounters an error. The error message is included in the callback.local_stream
* : Called when the stream is available locally (stream is provided in the callback). This can be used `
to display to the user his own streaming as it up-streams.
javascript
import {initLiveStream} from '@cloudinary/js-streaming'
// ...
// configure your cloud name and the live-stream enabled upload-preset:
const cloudName = [your-cloud-name];
const uploadPreset = [your-upload-preset];
let liveStreamLibrary;
// ...
// call initLiveStream with the configuration parameters:
initLiveStream({
cloudName: cloudName,
uploadPreset: uploadPreset,
debug: "all",
hlsTarget: true,
fileTarget: true,
events: {
start: function (args) {
// user code
},
stop: function (args) {
// user code
},
error: function(error){
// user code
},
local_stream: function (stream) {
// user code, typically attaching the stream to a video view:
liveStreamLibrary.attach($("#thevideo").get(0), stream);
}
}
}).then((result) => {
// keep handle to instance to start/stop streaming
liveStreamLibrary = result;
// Extract public id and url from result (publish the url for people to watch the stream):
let publicId = result.response.public_id;
let url = result.response.secure_url;
// start the streaming:
liveStreamLibrary.start(publicId);
})
`
#### Select device to stream from ################################################################
`javascript
import {getStream, initLiveStream, FRONT_CAMERA, REAR_CAMERA} from '@cloudinary/js-streaming';
// Get front camera stream
getStream(FRONT_CAMERA).then((stream)=>{})
// Get rear camera stream
getStream(REAR_CAMERA).then((stream)=>{})
// Get custom device stream
getStream({audio: true, video: { facingMode: "user" } }).then((stream)=>{})
// Select device to stream from by passing the stream to initLiveStream()
getStream(FRONT_CAMERA).then((stream)=> {
initLiveStream({cloudName, uploadPreset, stream, ...});
});
`