Usecase: splitAgent

splitAgent

SplitAgent usecase


new splitAgent(onEvents, domElements, options)

SplitAgent usecase

Parameters:
Name Type Description
onEvents object

Event handlers: onEvents

domElements object

DOM elements: domElements

options object

Available options: options

Returns:

SplitAgent actions

Type
Promise
Example
var onEvents = {
    onDestroyed: () => {
         // SPLIT session has been destroyed
    },
    onError: cause => {
         // An error has occurred
    },
    onJoined: () => {
         // You've joined the SPLIT session
    },
    onDataReceived: (type, data, filename) => {
        // Data received by the datachannel
        if (type === 'application/x-chat') { }
        else if (type === 'text/plain') { }
        else if (type === 'application/pdf') { }
        else if (type === 'application/zip') { }
        else if (type === 'application/x-rar') { }
        else if (type === 'image/jpeg') {}
        else if (type === 'image/png') {}
        else if (type === 'application/x-docx') {}
        else if (type === 'application/x-pptx') {}
        else if (type === 'application/x-xlsx') {}
        else if (type === 'application/vnd.oasis.opendocument.text') {}
    },
    onAcceptedVideo: stream => {
         // Accepted Video by remote peer
    },
    onAcceptedData: () => {
         // Accepted Data by remote peer
    },
    onReadyLocalStream: (isReady, stream) => {
         // The local video stream is or not ready
    },
    onRemoteVideoReady: (isReady, stream) => {
        // The remote video stream is or not ready
    },
    onScreensharingAccepted: () => {
         // ScreenSharing Accepted
    },
    onScreensharingClosed: () => {
         // ScreenSharing Closed
    },
    onFileTransferOk: fileId => {
         // File Transfer OK
    },
    onFileTransferKo: fileId => {
         // File Transfer KO
    },
    onNotified: (action, data) => {
         // Notification received from the remote peer
    },
    onVideoClosed: () => {
         // Remote video is closed
    }
};

var domElements = {
    client: document.getElementById('clientvideo'),
    agent: document.getElementById('agentvideo'),
    screenRemote: document.getElementById('screenRemote'),
    screenLocal: document.getElementById('localscreen')
};

var options = {
     dataChannel: {
         dataEnabled: true,
         allowedTypes: ['application/x-chat', 'image/jpeg', 'image/png', 'application/pdf'],
         maxSize: 5, // In MB
         fileTransmission: {
             timeout: 5, // Minutes
             retransmissionDelay: 15 // Seconds
         }
     },
     session: {
         agentName: 'Anna',
         sessionId: 6655
     },
     stream: {
         videoEnabled: true,
         aDeviceId: null,
         vDeviceId: null,
         resolution: 'vga' // 'qvga', 'vga', 'hd', 'full-hd', '4k', '8k'
         videoStream: null
     },
     account: "******" // Multiple mode
};

usecases.splitAgent(onEvents, domElements, options)
    .then(action => {
         // Use Case has been atacched succesfully
         ...
    })
    .catch(cause => {
        // Error attaching the Use Case
        Janus.error("Error Attach " + cause );
    })

Methods


closeUsecase()

Close the current UseCase. It's recommended combine with disconnect method

Returns:
Type
nothing
Example
action.closeUsecase();
myVideoApp.disconnect(); // Recommended

getLicense()

The VideoGateway is requested about the features of the contracted license

Returns:

License Information (Screensharing, Livechat and VideoRecording )

Type
Object
Example
var myLicense = action.getLicense();
console.log(myLicense);

notify(action, data)

Send a notification to the other peer via the VideoGateway

Parameters:
Name Type Description
action string

Identifies the notification type

data string

Useful for sending extra data (Optional)

Example
action.notify('open-map', 'data');

replaceVideo(type)

Replace the local Video track

Parameters:
Name Type Description
type string

('user', 'environment', 'left', 'right' or 'next')

Example
action.replaceVideo('environment');

sendData(type, data, cOk, cKo, (Optional))

Sends a message (Chat or File) through the DataChannel

Parameters:
Name Type Description
type string

MIME Type (e.g: 'application/x-chat', 'text/plain', 'application/pdf', 'application/zip', 'application/x-rar', 'image/jpeg', 'image/png', 'application/x-docx', 'application/x-pptx', 'application/x-xlsx', 'application/vnd.oasis.opendocument.text')

data string

Data Content

cOk function

Callback success function

cKo function

Callback failed function

(Optional) string

filename File Name (e.g: file.zip)

Returns:
Type
nothing
Example
action.sendData('application/x-chat', 'Hello Mike!',
 function(cOk) {
     // Success
 },
 function(error) {
     // Error
     console.log(error);
 }
)

setMode(video, data)

Modifies the audio/video mode of the local peer while the call is established.

Parameters:
Name Type Description
video boolean

Enable Video?

data boolean

Enable Data?

Example
action.setMode(true, true);

startRecording(prefix)

The Agent sends a request to start recording the session

Parameters:
Name Type Description
prefix string

Prefix of records: e.g: 'default'

Returns:
Type
nothing
Example
action.startRecording("__default__");

startScreensharing(screenId, cOk, cKo)

The Agent sends a request to start Screensharing

Parameters:
Name Type Description
screenId integer

Screen Id

cOk function

Callback Ok

cKo function

Callback Error

Returns:
Type
nothing
Example
action.startScreensharing(1234, function() {
     // Success
}, function(cause) {
     // Error
})

stopRecording()

The Agent sends a request to stop recording the session

Returns:
Type
nothing
Example
action.stopRecording();

stopScreensharing(cOk, cKo)

The Agent sends a request to stop Screensharing

Parameters:
Name Type Description
cOk function

Callback Ok

cKo function

Callback Error

Returns:
Type
nothing
Example
action.stopScreensharing(function() {
     // Success
}, function(cause) {
     // Error
})

toggleVideo()

Toggle local Video stream (Mute/Unmute)

Returns:

Is video muted?

Type
boolean
Example
action.toggleVideo(); // true or false