플레이어에 명령 전송하기

    플레이어에 명령 전송하기


    기사 요약

    플레이어에 명령을 전송할 때 사용합니다. 플레이어에서 특정 UI 구성 요소를 숨기거나 노출할 수 있고, 음소거를 하거나 해제할 수도 있습니다.

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

    sendMessage

    Action

    Function

    Payload

    showControls

    컨트롤 보이기

    N/A

    mute

    음소거

    N/A

    unmute

    음소거 해제

    N/A

    removeBanner

    배너 닫기

    N/A

    removeCoupon

    쿠폰 닫기

    N/A

    removeNotice

    공지 닫기

    N/A

    showToast

    메시지 토스트 띄우기

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

    SEND_COMMAND_MESSAGE

    Command message 전달

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

    SEND_COMMAND_MESSAGE

    SEND_COMMAND_MESSAGESET_BRAND_FAVORITE과 같은 특수 명령(command)을 전송하는 명령입니다.

    • Command: SET_BRAND_FAVORITE

    • Payload:

    Property name

    Type

    Example

    Description

    favorite

    boolean

    true | false

    좋아요 상태

    identifier

    string

    shoplive

    브랜드 식별자


    Sample code

    팝업(쿠폰) 클릭 시 alert창을 띄우고 쿠폰을 보이지 않게 처리하는 샘플

    // 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"); 
        }
      },
    };