This is the main class of the SDK. Your journey always starts by initializing this class and then calling its methods to control your integration. There are also various events to subscribe to with callbacks.
There are two approaches to initializing:
Using the constructor which will load immediately the specified room based on the InitOptionsand the optionalInstanceProperties.
//instanceProperties is an optional paramconstsambaFrame=newDigitalSambaEmbedded(initOptions, instanceProperties);
Using the createControl factory method. Later you can load the room by calling the load method. That way creation of the DigitalSambaEmbedded class is decoupled from the actual loading of the room which gives you more control during initialization.
// notice `createControl` vs constructor callconstsambaFrame=DigitalSambaEmbedded.createControl(initOptions);// ...// when necessary, load the room in the frame// instanceProperties is optionalsambaFrame.load(instanceProperties);
root - HTMLElement. If specified, target frame will be created as a child tag of root. Otherwise the created iframe will be appended to the body tag of the page
frame - HTMLIFrameElement to be wrapped. This is useful if you want the room to be loaded in an iframe element which already exists. If frame is not specified, then an iframe element will be created automatically by the SDK
url - full room URL to be applied as the iframe src attribute. Must include https protocol.
https://[teamNameHere].digitalsamba.com/[roomNameHere]
team - team name (string) - used if you do not want to specify the url manually
room - room name (string) - used if you do not want to specify the url manually
token - optional JWT string token for authentication, mainly for private rooms
roomSettings - an optional JSON object configuring the initial room settings. Read also about the possible VirtualBackgroundOptions.
{//Configures if user's video device will be enabled on entering the room videoEnabled: boolean,//Configures if user's audio device will be enabled on entering the room audioEnabled: boolean,//Configures initial video and audio devices to use on entering the room mediaDevices: { videoinput:'id of camera', audioinput:'id of microphone', audiooutput:'id of speaker device' },//Language for the user. Use language code - e.g. en, de-DE, es-ES appLanguage: string,//Name of the user on entering the room username: string,//Custom initials (max 2 letters) for the user tile initials: string,//If 'auto' or 'tiled' layout mode will be used layoutMode: string,//If the toolbar will be visible or not showToolbar: boolean,//If the captions panel will be visible or not showCaptions: boolean,//The virtual background virtualBackground: VirtualBackgroundOptions,//If the frame will be muted on join for the local user muteFrame: boolean,//If a confirmation modal will be shown when you remove (kick) another user requireRemoveUserConfirmation: boolean}
The following combinations of fields are valid for initOptions (token and roomSettingscan be used with any of them):
url - will create a frame as a child of the body tag and load the room url
url + root - will create a frame as a child of root element and load the room url
url + frame - will load the room url in the provided existing frame
team + room - will create a frame as a child of the body tag and load the specified room
team + room + root - will create a frame inside root element and load the specified room
team + room + frame - will load the specified room in the provided existing frame
frame - will attach to the specified existing frame (assuming you've manually set correct room url as the iframe src)
frameAttributes - list of attributes to be applied to the target iframe
reportErrors - boolean, false by default. Whether to report misconfiguration or runtime errors to the browser console
Code examples of the possible initOptions combinations:
//SDK will create a frame as a child of the body tag and load the room urlimport DigitalSambaEmbedded from'@digitalsamba/embedded-sdk';constroomUrl='https://[TEAM_NAME_HERE].digitalsamba.com/[ROOM_NAME_HERE]';constsambaFrame=DigitalSambaEmbedded.createControl({ url: roomUrl,//Optional room settings/*roomSettings: { username: 'John Smith' layoutMode: 'auto', virtualBackground: { blur: 'balanced' }, ..................... },*///token: TOKEN_HERE_IF_YOU_ARE_USING_IT});sambaFrame.load();
//SDK will create a frame as a child of the parent element and load the room urlimport DigitalSambaEmbedded from'@digitalsamba/embedded-sdk';constparentElement=document.querySelector('USE_CSS_SELECTOR_HERE');constroomUrl='https://[TEAM_NAME_HERE].digitalsamba.com/[ROOM_NAME_HERE]';constsambaFrame=DigitalSambaEmbedded.createControl({ url: roomUrl, root: parentElement,//token: TOKEN_HERE_IF_YOU_ARE_USING_IT});sambaFrame.load();
//SDK will load the room url in the specified existing iframeimport DigitalSambaEmbedded from'@digitalsamba/embedded-sdk';constexistingIFrame=document.querySelector('USE_CSS_SELECTOR_HERE');constroomUrl='https://[TEAM_NAME_HERE].digitalsamba.com/[ROOM_NAME_HERE]';constsambaFrame=DigitalSambaEmbedded.createControl({ url: roomUrl, frame: existingIFrame,//token: TOKEN_HERE_IF_YOU_ARE_USING_IT});sambaFrame.load();
//SDK will create a frame as a child of the body tag and load the specified roomimport DigitalSambaEmbedded from'@digitalsamba/embedded-sdk';constteamName='TEAM_NAME_HERE';constroomName='ROOM_NAME_HERE';constsambaFrame=DigitalSambaEmbedded.createControl({ team: teamName, room: roomName,//token: TOKEN_HERE_IF_YOU_ARE_USING_IT});sambaFrame.load();
//SDK will create a frame as a child of the parent element and load the roomimport DigitalSambaEmbedded from'@digitalsamba/embedded-sdk';constparentElement=document.querySelector('USE_CSS_SELECTOR_HERE');constteamName='TEAM_NAME_HERE';constroomName='ROOM_NAME_HERE';constsambaFrame=DigitalSambaEmbedded.createControl({ team: teamName, room: roomName, root: parentElement,//token: TOKEN_HERE_IF_YOU_ARE_USING_IT});sambaFrame.load();
//SDK will load the room in the specified existing frameimport DigitalSambaEmbedded from'@digitalsamba/embedded-sdk';constexistingIFrame=document.querySelector('USE_CSS_SELECTOR_HERE');constteamName='TEAM_NAME_HERE';constroomName='ROOM_NAME_HERE';constsambaFrame=DigitalSambaEmbedded.createControl({ team: teamName, room: roomName, frame: existingIFrame,//token: TOKEN_HERE_IF_YOU_ARE_USING_IT});sambaFrame.load();
//SDK will attach to the specified existing frame//Assuming you've manually preset correct room url as the iframe srcimport DigitalSambaEmbedded from'@digitalsamba/embedded-sdk';constexistingIFrame=document.querySelector('USE_CSS_SELECTOR_HERE');constsambaFrame=DigitalSambaEmbedded.createControl({ frame: existingIFrame,//token: TOKEN_HERE_IF_YOU_ARE_USING_IT});sambaFrame.load();
Sample usage of the optional instanceProperties to set a red border and also report errors:
Note that you can use any initOptions combination from the previous examples.
import DigitalSambaEmbedded from'@digitalsamba/embedded-sdk';constroomUrl='https://[TEAM_NAME_HERE].digitalsamba.com/[ROOM_NAME_HERE]';constsambaFrame=DigitalSambaEmbedded.createControl({ url: roomUrl });//SDK will put a 5px solid red border around the iframeconstinstanceProps= { frameAttributes: {style:"border: 5px solid red"}, reportErrors:true};sambaFrame.load(instanceProps);