Sending commands to the player

    Sending commands to the player


    Article summary

    This is used to send commands to the player. It allows for hiding or revealing specific UI components in the player and can also mute or unmute the audio.

    const player = cloud.shoplive.getPlayer();
    player.sendMessage(action,payload); 


    sendMessage

    Action

    Function

    Payload

    showControls

    Show Controls UI

    N/A

    mute

    Mute the sound

    N/A

    unmute

    Unmute the sound

    N/A

    removeBanner

    Remove banner

    N/A

    removeCoupon

    Remove coupon

    N/A

    removeNotice

    Remove Notice

    N/A

    showToast

    Show toast message

    {
        "message": "{message}",
        "duration": {milliseconds},
        "position": "BOTTOM|CENTER|TOP"
    }

    SEND_COMMAND_MESSAGE

    Sending Command message

    {
        "command": "SET_BRAND_FAVORITE",
        "payload": { identifier: identifier, favorite: true  }
    }

    SEND_COMMAND_MESSAGE

    SEND_COMMAND_MESSAGE is a command to send special command such as SET_BRAND_FAVORITE.

    • command: SET_BRAND_FAVORITE

    • payload:

    Name

    Type

    Example

    Description

    favorite

    boolean

    true | false

    like status

    identifier

    string

    shoplive

    brand identifier


    Sample code

    For clicking the coupon - display an alert window and remove the coupon.

    // Downloaded coupon and send tracking event manually
    var messageCallback = {
      DOWNLOAD_COUPON: function(payload, parent) {
        const player = cloud.shoplive.getPlayer();
        var type = payload.type;
        var coupon = payload.coupon;
        alert(payload.coupon + " Coupon download complete.");
        if (type === "BANNER") {
          player.sendMessage("removeBanner"); 
        } else if (type === "COUPON") {
          player.sendMessage("removeCoupon"); 
        } else if (type === "NOTICE") {
          player.sendMessage("removeNotice"); 
        }
      },
    };