Skip to content

Composition Object

Properties

Name Type Description Example
id String id of the composition "303798-latest-1589207585405"
name String name of the composition "Default"

Methods

The composition object has following methods:

Method Return type Brief description
getControlNode() object Returns control nodes of the composition
getLogicLayer() object Returns logic layers of the composition
getModel() object Returns the model description of the composition
getPayload() object Returns the payload of the composition
getRefId() object Returns the reference id of the composition
getState() object Returns the state of the composition
getSubcompositionById( id ) object Returns the composition object of the subcomposition with the specified id
getSubcompositionByName( name ) object Returns the composition object of the subcomposition with the specified name
jumpTo( to ) object Jump to the animation state specified by to
listSubcompositions() object Returns an array of subcompositions of the composition
playTo( to ) object Play to the animation state specified by to
remove( callback ) object Add description here ...
resetAllPayloads() object Resets all payloads to default values.
resetPayload() object Resets payload to default values.
setPayload( payload ) object Set payload of the composition

getControlNode()

Returns control node model and payload of the composition

1
2
3
// The code below prints the list of controlnode description to the console
var controlnode = compositionObject.getControlNode();
console.log("controlnode =", controlnode);

Return

object - JSON description, if the composition has control nodes

undefined - if the composition has no control nodes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{
  "id": "controlNode",
  "model": {
    "fields": {
      "3c686562-1cf3-7493-7fae-803009afa22e": {
        "defaultValue": "Default Text",
        "id": "Top Title",
        "index": 2,
        "title": "Top Title",
        "type": "text"
      },
      "502a7d0e-e0f8-a895-1b80-43cdb81a1ca9": {
        "defaultValue": "Default Text",
        "id": "Bottom Title",
        "index": 3,
        "title": "Bottom Title",
        "type": "text"
      }
    }
  },
  "name": "Control Node",
  "payload": {
    "Bottom Title": "Extra Information",
    "Top Title": "SINGULAR.LIVE"
  },
  "thumbnail": "/images/noimage.png"
}

getLogicLayer()

Returns logic layer details of the composition

1
2
3
// The code below prints the logic layer description to the console
var logicLayer = compositionObject.getLogicLayer();
console.log("logicLayer =", logicLayer);

Return

object - JSON description, if a logic layer is defined for the composition

undefined - if no logic layer is defined for the composition

1
2
3
4
{
  "name": "Lower",
  "tag": "#B0C8CD"
}

getModel()

Returns the model description of control node fields of the composition

1
2
3
// The code below prints the list of controlnode description to the console
var cnModel = compositionObject.getModel();
console.log("cnModel =", cnModel);

Return

object - Array of JSON objects, if the composition has control nodes

undefined - if the composition has no control nodes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
[
  {
    "0": {
      "defaultValue": "Default Text",
      "id": "Top Title",
      "index": 2,
      "title": "Top Title",
      "type": "text"
    }
  },
  {
    "1": {
      "defaultValue": "Default Text",
      "id": "Bottom Title",
      "index": 3,
      "title": "Bottom Title",
      "type": "text"
    }
  }
]

getPayload()

Returns the payload of to control node of the composition

1
2
3
// The code below prints the list of controlnode payload to the console
var cnPayload = compositionObject.getPayload();
console.log("cnPayload =", cnPayload);

Return

object - Array of JSON objects, if the composition has control nodes

undefined - if the composition has no control nodes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
[
  {
    "0": {
      "key": "Bottom Title",
      "value": "Extra Information"
    }
  },
  {
    "1": {
      "key": "Top Title",
      "value": "SINGULAR.LIVE"
    }
  }
]

getRefId()

Returns the reference id of the composition. The reference id is the unique id that identifies the composition in the Singular dashboard.

1
2
3
// The code below prints the refid to the console
var refid = compositionObject.getRefId();
console.log("refid =", refid);

Return

number - reference id of the composition

1
refid = 303798

getState()

Returns the animation state of the composition

1
2
3
// The code below prints the animation to the console
var animState = compositionObject.getState();
console.log("animState =", animState);

Return

String - animation state

1
getState = Out

getSubcompositionById( id )

Returns the composition object of the subcomposition with the specified id

Parameters

Name Type Description
id String Id of the subcomposition
1
2
3
4
// The code below prints the composition object to the console
var subCompId = "a4db02c8-df43-4737-a43d-ba9a4430cd86";
var subCompObject = singularApp.getSubcompositionById(subCompId);
console.log("subCompObject =", subCompObject);

Return

object - Subcomposition object

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
subcompositionObject:
> getControlNode: ƒ subcomp_getControlNode()
> getLogicLayer: ƒ subcomp_getLogicLayer()
> getModel: ƒ subcomp_getModel()
> getPayload: ƒ subcomp_getPayload()
> getState: ƒ subcomp_getState()
> getSubcompositionById: ƒ subcomp_getSubcompositionById(id)
> getSubcompositionByName: ƒ subcomp_getSubcompositionByName(name)
> id: "a4db02c8-df43-4737-a43d-ba9a4430cd86"
> jumpTo: ƒ jumpTo(to)
> listSubcompositions: ƒ subcomp_listSubcompositions()
> name: "Lower Title"
> playTo: ƒ playTo(to)
> resetPayload: ƒ subcomp_resetPayload()
> setPayload: ƒ subcomp_setPayload(payload)

See also

subcomposition object

getSubcompositionByName( name )

Returns the composition object of the subcomposition with the specified name

Parameters

Name Type Description
id String Id of the subcomposition
1
2
3
4
// The code below prints the composition object to the console
var subCompName = "Lower Title";
var subCompObject = singularApp.getSubcompositionByName(subCompName);
console.log("subCompObject =", subCompObject);

Return

object - Subcomposition object

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
subcompositionObject:
> getControlNode: ƒ subcomp_getControlNode()
> getLogicLayer: ƒ subcomp_getLogicLayer()
> getModel: ƒ subcomp_getModel()
> getPayload: ƒ subcomp_getPayload()
> getState: ƒ subcomp_getState()
> getSubcompositionById: ƒ subcomp_getSubcompositionById(id)
> getSubcompositionByName: ƒ subcomp_getSubcompositionByName(name)
> id: "a4db02c8-df43-4737-a43d-ba9a4430cd86"
> jumpTo: ƒ jumpTo(to)
> listSubcompositions: ƒ subcomp_listSubcompositions()
> name: "Lower Title"
> playTo: ƒ playTo(to)
> resetPayload: ƒ subcomp_resetPayload()
> setPayload: ƒ subcomp_setPayload(payload)

See also

subcomposition object

jumpTo( to )

Jump to the animation state specified by to

1
2
// The code below sets the animation state to "In"
compositionObject.jumpTo("In");

Return

none

listSubcompositions()

Returns an array of subcompositions of the composition

1
2
3
// The code below prints the list of subcompositions to the console
var subcompositionList = compositionObject.listSubcompositions();
console.log("subcompositionList =", subcompositionList);

Return

object - Array of JSON objects

1
[ "0" { "id": "a4db02c8-df43-4737-a43d-ba9a4430cd86", "name": "Lower 1 Line - Large" } ]

playTo( to )

Play to the animation state specified by to

1
2
// The code below plays the animation state to "In"
compositionObject.playTo("In");

Return

none

remove( callback )

The register callback function. The function callback is called when the composition gets removed from the output.

Parameters

Name Type bb Description
callback function callback function triggered when composition was removed
1
2
3
4
5
6
7
8
9
// The code below removes the composition
var compositionId = "303798-latest-1588928586739";
var compositionObject = singularApp.getComposition(compositionId);
compositionObject.remove( function () =>
  {
    // clear composition object
    compositionObject = undefined;
    console.log("composition removed successfully.");
  });

Return

none

resetAllPayloads()

Reset all payloads in the composition and subcompositions to default values.

1
2
// The code below reset all payloads of the composition
compositionObject.resetAllPayloads();

Return

none

resetPayload()

Reset payload of the composition to default values.

1
2
// The code below reset payloads of the composition
compositionObject.resetPayload();

Return

none

setPayload( payload )

Set payload of the control nodes of a composition

1
2
3
4
5
6
// The code below sets payloads of the composition
var payload = {
  "Bottom Title": "Extra Information",
  "Top Title": "SINGULAR.LIVE",
};
compositionObject.setPayload(payload);

Return

none