1.20.1 • Published 22 days ago

@bandyer/web-core-av v1.20.1

Weekly downloads
44
License
ISC
Repository
github
Last release
22 days ago

Bandyer Web Core AV

This module provide the Core Audio Video utilities for Bandyer Video using WebRTC.

Stream

The stream object implements the stream (webcam or screen) acquired by the device of the web client.

Methods:

  • initialize(): initialize the Stream object
  • initStream(streamConfig, attributes): given a stream config and attributes it init the stream in the browser.
  • toggleAudioTrack()
  • toggleVideoTrack()
  • closeStream()

You will not directly interact with the Stream object. We encourage to use the publisher object.

API doc here: Stream

Publisher

The publisher object handles the Webcam o Screen Media Resources of the user.

Get local webcam

.initLocalWebcam(options: GetUserMediaOptions)

To request access to the client's webcam you should use the initLocalWebcam method with his relative options.

Example:

import {BaseUser, Publisher} from '@bandyer/web-core-av';
// Request client's local webcam access;
const baseUser = BaseUser.initialize({userAlias: 'your_user_alias'});
await Publisher.initialize(baseUser).initLocalWebCam({audio:true, video:true});

Get local screen

.initLocalScreen(audio, extensionId?)

To request access to the client's screen you should use the initLocalScreen function. You must specify if you want the audio track or not. The parameter extensionsId is requierd only for GoogleChrome browser.

Example:

import {Publisher} from '@bandyer/web-core-av';
// Request client's screen webcam access;
const baseUser = BaseUser.initialize({userAlias: 'your_user_alias'});
await Publisher.initialize(baseUser).initLocalScreen(true, 'extensiond_id');

API doc here: Publisher

Room

Before you can connect to a Room, you need a Token. In order to get a Token, you need to interact with the BandyerCommunicationCenter.

### Initialize

import { Room } from '@bandyer/web-core-av';
var myRoom = Room.initialize(token, recordOption)

You can specify if the room should be recorded or not. The initialize method returns a Room object. Note that calling the method does not connect to a Room; it creates a JS object which represents a Room.

Connect to a room

import { Room } from '@bandyer/web-core-av';
try {
	var myRoom = Room.initialize(token);
	await myRoom.connectRoom();
} catch (err) {
	console.log('Room err:', err);
}

The connectRoom method returns the Room object if the connection was successfull. Otherwise, it throws an error.

Disconnect from a room

myRoom.disconnectRoom();

To disconnect from a room, call the disconnectRoom method.

Publish stream

Once you have connect to a Room, you can publish the stream of a Publisher. First of all, you must initialize a webcam or screen Stream of the Publisher.

// first of all, connect to a room
var myRoom = Room.initialize(token);
await myRoom.connectRoom();

// init client's webcam

var myPub = await Publisher.initialize(baseUser)
await myPub.initLocalWebCam({audio:true, video:true});
// publish the Publisher localwebcam
myRoom.publishStream(myPub.localWebcam)

Unpublish stream

You can stop Publisher from streaming a specific Stream to the room by calling the unpublishStream() method of the Room object:

// unpublish the Publisher localwebcam
myRoom.unpublishStream(myPub.localWebcam)

Room events

room-connected

The room object emit the room-connected event when you successfully connect to a Room. A common use case is to subscribe to streams currently published in the room:

var myRoom = Room.initialize(token);
await myRoom.connectRoom();
myRoom.on('room-connected', function(room) {
	// room.streams contains the streams currently published in the room
	const { streams } = roomEvent.streams;
        for (const index in streams) {
            if ({}.hasOwnProperty.call(streams, index)) {
    			const stream = streams[index];
				myRoom.subscribeStream(stream, {audio: true, video: true} );
        	}
    	}
})
room-disconnected

Emitted when the user has been already disconnected.

var myRoom = Room.initialize(token);
await myRoom.connectRoom();
myRoom.on('room-disconnected', function(room) {
	
})
room-error

Emitted when it hasn't been possible a successfully connection to the room.

var myRoom = Room.initialize(token);
await myRoom.connectRoom();
myRoom.on('room-error', function(room) {
	
})

Full doc here: Room

1.20.1

22 days ago

1.20.0

10 months ago

1.19.0

2 years ago

1.18.0

2 years ago

1.17.1

3 years ago

1.17.0

3 years ago

1.16.1

3 years ago

1.16.0

3 years ago

1.15.1

3 years ago

1.15.0

3 years ago

1.14.0

3 years ago

1.13.1

3 years ago

1.13.0

3 years ago

1.12.0

4 years ago

1.11.1

4 years ago

1.10.2

4 years ago

1.10.1

4 years ago

1.10.0

4 years ago

1.9.0

4 years ago

1.8.0

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.0

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.0-rc.2

5 years ago

0.1.0-rc.1

5 years ago

0.1.0-rc.0

5 years ago