API Reference

The only class you need to interact with is JCClient.

JCClient

JCClient constructor

class JCClient([options])

Constructor for JCClient. A dictionary can be passed in to override default options.

Example

var options = {};
var jc = new JCClient(options);
Arguments:
  • options (object) –

    override default options

    • apiKey - Required Set the API Key. Get it here.
    • userid - Required A string tha represents the user.
    • serverName - Set the server URL. Defaults to https://jumpch.at
    • audioBandwidth - Sets audio bandwidth. Defaults to 50 kbps
    • videoBandwidth - Sets video bandwidth. Defaults to 300 kbps

JCClient.join

JCClient.join(roomName, roomType, password, callback)

Join a JumpChat room to start a video chat.

Example

jc.join('jumpchat00', 'random', '', function(users) {
  console.log('joined room jumpchat00');
});
Arguments:
  • roomName (string) – Room name to join. If random, the string must be of length 10.
  • roomType (string) – Room type. Must be random or custom.
  • password (string) – Password for the room.
  • callback (function) – Callback will return a users array.

JCClient.leave

JCClient.leave()

Leave the room.

Example

jc.join('jumpchat00', 'random', '', function(users) {
  console.log('joined room jumpchat00');
  jc.leave();
  console.log('left room jumpchat00');
});

JCClient.localVideo

JCClient.localVideo(callback)

Get the local video.

Example

jc.localVideo(function(video) {

});
Arguments:
  • callback (function) – Callback to receive the local video.

JCClient.sendChatMessage

JCClient.sendChatMessage(msg, userid)

Send text message to everyone in the room or a single person. If userid is not specified or is null, the chat message is sent to everyone.

Example

jc.sendChatMessage("hello");
Arguments:
  • msg (string) – Text message
  • userid (string) – Userid is optional

JCClient.sendDataMessage

JCClient.sendDataMessage(msg, userid)

Send data message to everyone in the room. If userid is not specified or is null, the chat message is sent to everyone.

Example

jc.sendDataMessage({'hello': 'world'});
Arguments:
  • msg (string) – Message. This could be any serializable javascript object.
  • userid (string) – Userid is optional

JCClient.avatar

JCClient.avatar([avatar])

Get or set avatar

Example

// get avatar
var avatar = jc.avatar();
img.src = avatar;

// set avatar
jc.avatar(newAvatar);
Arguments:
  • avatar (string) – Avatar url
Returns:

String avatar url

JCClient.username

JCClient.avatar([avatar])

Get or set username

Example

// get username
var username = jc.username();

// set username
jc.username(username);
Arguments:
  • avatar (string) – Username
Returns:

String username

JCClient.users

JCClient.users()

Get all the users in the room

Example

// get avatar
var users = jc.users();
Returns:Array of users objects
  • name - Username
  • avatar - Avatar url
  • admin - Boolean if user is admin

JCClient.user

JCClient.user(userid)

Get a specific user

Example

// get avatar
var user = jc.user("me");
Arguments:
  • userid (string) – Userid or me for current user’s info
Returns:

User object or null

  • name - Username
  • avatar - Avatar url
  • admin - Boolean if user is admin

JCClient.broadcastAudio

JCClient.broadcastAudio([broadcast])

Get or set broadcast audio setting

Example

// mute audio
jc.broadcastAudio(false);
var broadcast = jc.broadcastAudio();
Arguments:
  • avatar (boolean) – Broadcast audio
Returns:

Boolean broadcast audio state

JCClient.broadcastVideo

JCClient.broadcastVideo([broadcast])

Get or set broadcast video setting

Example

// disable video
jc.broadcastVideo(false);
var broadcast = jc.broadcastVideo();
Arguments:
  • avatar (boolean) – Broadcast video
Returns:

Boolean broadcast video state

JCClient.getSources

JCClient.getSources(callback)

Get the available audio or video sources.

Example

jc.getSources(function(sources) {
    for (var i=0; i<sources.length; i++) {
        var source = sources[i];
        console.log('source: ' + source.id + ' kind: ' + source.kind + ' label: ' + source.label);
    }
});
Arguments:
  • callback (function) – Callback function

JCClient.setAudioSourceId

JCClient.setAudioSourceId(sourceId)

Set the audio source id. If set to null or empty string, the default will be selected. Must call resetLocalVideo() in order to see the new source being used.

Example

jc.setAudioSourceId(sourceId);
Arguments:
  • sourceId (String) – sourceId of kind ‘audio’ retrieved from getSources()

JCClient.setVideoSourceId

JCClient.setVideoSourceId(sourceId)

Set the video source id. If set to null or empty string, the default will be selected. Must call resetLocalVideo() in order to see the new source being used.

Example

jc.setVideoSourceId(sourceId);
Arguments:
  • sourceId (String) – sourceId of kind ‘video’ retrieved from getSources()

JCClient.on

JCClient.on(eventName, callback)

Register an event handler.

Example

jc.on('joined', function(e, userid) {
  ...
});

jc.on('left', function(e, userid) {
  ...
});
Arguments:
  • eventName (string) – Name of the event to register callback.
  • callback (function) – Callback function
  • joined - User has joined.

    function(e, userid) { ... }()
  • userLeft - User has left.

    function(e, userid) { ... }()
  • remoteVideoAdded - Remote video added.

    function(e, userid, video) { ... }()
  • remoteVideoRemoved - Remote video removed.

    function(e, userid) { ... }()
  • localVideoUpdated - Local video stream has been updated.

    function(e, stream) { ... }()
  • broadcastState - Update broadcast state. If video or audio is enabled.

    function(e, userid, state) { ... }()
  • updateName - User name updated.

    function(e, userid, name) { ... }()
  • updateAvatar - User avatar updated.

    function(e, userid, avatar) { ... }()
  • chatMessage - Text message received.

    function(e, userid, msg) { ... }()
  • dataMessage - Data message received.

    function(e, userid, msg) { ... }()