share.js 8.71 KB
Newer Older
Lee Munkyeong committed
1 2 3 4
/* --------------------------------------------------- */
/* Functions                                           */
/* --------------------------------------------------- */
let coview_api = new CoviewApi();
Kang Donghun committed
5
$(function() {
Lee Munkyeong committed
6
    var coviewApiActive = coview_api.Init(
Lee Munkyeong committed
7 8 9 10
            {
                testSTRParam : "param1",
                testNUMParam : 77,
                testBOOLParam : false,
11
                coview_api_srv_addr: "https://livetaskyell.abookcloud.com",
Lee Munkyeong committed
12 13
                coview_wrap_id : "coviewShare",
                coview_api_key: "8dda7092c5820d663"
Lee Munkyeong committed
14
            }
15
    );
Lee Munkyeong committed
16 17

         // special button IN Chat ui
18 19 20 21 22 23 24 25 26 27 28 29
        $("#coviewShareMainBtn").on("click", function(e) {
            e.stopPropagation();
            if ($(".coview_share_dropdown_bar").is(':visible') == true) {
                Coview_shareDropdownHide();

                if ($(".coview_share_photo_select_bubble").is(':visible') == true) {
                    $(".coview_share_photo_select_bubble").slideUp();
                }
            } else {
                $(".coview_share_dropdown_bar").slideDown();
            }
        });
Lee Munkyeong committed
30

31 32 33
        $("#coviewShareCloseButton").on("click", function(e) {
            coview_api.LeaveRoom();
            $(".coview_share_area").hide();
Lee Munkyeong committed
34

35
        });
Lee Munkyeong committed
36

37 38
        $("body").on("click", function(){
            Coview_shareDropdownHide();
Lee Munkyeong committed
39

40 41 42 43
            if ($(".coview_share_photo_select_bubble").is(':visible') == true) {
                $(".coview_share_photo_select_bubble").slideUp();
            } else {
                $(".coview_share_dropdown_bar").slideDown();
44
            }
Lee Munkyeong committed
45

46
        });
Lee Munkyeong committed
47

48 49 50 51
    $("#coviewShareCloseButton").on("click", function(e) {
        coview_api.LeaveRoom();
        $(".coview_share_area").hide();
    });
Kang Donghun committed
52

53 54 55
    $("body").on("click", function() {
        Coview_shareDropdownHide();
    });
Kang Donghun committed
56

57 58 59 60 61 62 63 64 65 66 67 68
    $(document).on("click", ".coview_share_request", function() {
        console.log("globalUserInfo", globalUserInfo);
        if ($(this).hasClass(collaborationTypeKey.VIDEO) == true) {
            globalUserInfo.coWorkType = collaborationTypeKey.VIDEO;
            $(".coview_share_title_name").text("LIVE");
        } else if ($(this).hasClass(collaborationTypeKey.CAMERA) == true) {
            globalUserInfo.coWorkType = collaborationTypeKey.CAMERA;
            $(".coview_share_title_name").text("ライブラリ");
        } else if ($(this).hasClass(collaborationTypeKey.AUDIO) == true) {
            globalUserInfo.coWorkType = collaborationTypeKey.AUDIO;
            $(".coview_share_title_name").text("音声通話");
        }
Kang Donghun committed
69

70 71 72
        coview_api.JoinRoom(globalUserInfo.roomId, globalUserInfo.coWorkType);
        Coview_moveToVideoShareArea();
    });
Kang Donghun committed
73 74


75 76 77 78 79 80 81 82 83 84
    /* --------------------------------------------------- */
    /* Video, photo, chat, doc                             */
    /* --------------------------------------------------- */
    $("#coviewShareChat").on("click", function() {
        console.log("ON click coviewShareChat");
    });

    $("#coviewSharePhoto").on("click", function(e) {
        e.stopPropagation();
        console.log("ON click coviewSharePhoto");
Kang Donghun committed
85

86 87 88 89 90 91
        if ($(".coview_share_photo_select_bubble").is(':visible') == true) {
            $(".coview_share_photo_select_bubble").slideUp();
        } else {
            $(".coview_share_photo_select_bubble").slideDown();
        }
    });
Kang Donghun committed
92 93 94 95




96 97 98 99 100
    $("#coviewSharePhotoCamera").on("click", function() {
        $(".coview_share_photo_select_bubble").hide();
        globalUserInfo.coWorkType = collaborationTypeKey.CAMERA;
        coview_api.CreateRoom(globalUserInfo.roomId, globalUserInfo.coWorkType);
        Coview_moveToVideoShareArea();
Kang Donghun committed
101

102 103 104 105 106 107 108
        $(".coview_share_title_name").text("カメラ");
    });
    $("#coviewSharePhotoGallery").on("click", function() {
        $(".coview_share_photo_select_bubble").hide();
        globalUserInfo.coWorkType = "gallery";
        coview_api.CreateRoom(globalUserInfo.roomId, globalUserInfo.coWorkType);
        Coview_moveToVideoShareArea();
Kang Donghun committed
109

110 111
        $(".coview_share_title_name").text("ライブラリ");
    });
Kang Donghun committed
112

113 114 115 116
    $("#coviewShareAudio").on("click", function() {
        globalUserInfo.coWorkType = collaborationTypeKey.AUDIO;
        coview_api.CreateRoom(globalUserInfo.roomId, globalUserInfo.coWorkType);
        Coview_moveToVideoShareArea();
Kang Donghun committed
117

118 119
        $(".coview_share_title_name").text("音声通話");
    })
Kang Donghun committed
120 121


122 123 124 125
    $("#coviewShareLive").on("click", function() {
        console.log("ON click coviewShareLive");
        globalUserInfo.coWorkType = "video";
        console.log("globalUserInfo", globalUserInfo);
Kang Donghun committed
126

127 128 129 130 131
        coview_api.CreateRoom(globalUserInfo.roomId, globalUserInfo.coWorkType);
        Coview_moveToVideoShareArea();

        $(".coview_share_title_name").text("LIVE");
    });
Kang Donghun committed
132 133 134 135 136 137 138

//     $("#coviewShareDoc").on("click", function(){
//         console.log("ON click coviewShareDoc");
//         alert("INTO a document share mode (only audio)");
//         globalUserInfo.coWorkType = "audio";
//     });

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
    coview_api.addEventListener ("ready", function () {
        console.log("=============> READY : ready for coview api");
        coview_api.Login(globalUserInfo.loginId);
    });

    coview_api.addEventListener ("start", function () {
        console.log("=============> START : share start");
        $("#loadingIndicator").removeClass("full_active");
    });

    coview_api.addEventListener ("destroy", function () {
        console.log("=============> START : share start");
        coview_api.LeaveRoom();
        $(".coview_share_area").hide();
        $("#loadingIndicator").removeClass("full_active");
    });

    coview_api.addEventListener ("message", async function (event, json) {
        console.log("+++ addEventListener", json);
        console.log("processMessage api = ", json.api);
        let loginIdList = new Array();
        switch (json.api){
            case "LoginResponse":
                console.log('------------------------------');
                console.log(globalUserInfo.coWorkType);
                console.log(collaborationJoinFlg);
                if (collaborationJoinFlg == '1') {
                    coview_api.JoinRoom(globalUserInfo.roomId, globalUserInfo.coWorkType);
                } else if (collaborationJoinFlg == '0') {
                    coview_api.CreateRoom(globalUserInfo.roomId, globalUserInfo.coWorkType);
                }
                Coview_moveToVideoShareArea();
Kang Donghun committed
171
                break;
172 173 174 175 176 177 178 179
            case "CreateRoomResponse":
                if (json.resultCode == 200) {
                    var coviewInviteMessage = "" + messageSeperator + messageType.COMMUNICATIONSTART + messageSeperator + CHAT_UTIL.getCollaborationType(globalUserInfo.coWorkType);
                    socket.emit('createMessage', {
                        text: coviewInviteMessage
                    }, 0);
                } else {
                }
Kang Donghun committed
180
                break;
181 182 183 184 185 186 187 188 189 190 191
            case "JoinRoomInfoResponse":
                if (json.resultCode == 200) {
                } else {
                    alert("Not exist sharing call (" + json.resultCode + ")\nPlease using share menu.");
                    coview_api.LeaveRoom();
                    $(".coview_share_area").hide();
                    $("#loadingIndicator").removeClass("full_active");
                }
                break;
            case "JoinRoomResponse":
                if (json.resultCode == 200) {
Kang Donghun committed
192 193 194 195 196 197
                    for (let key in g_participants) {
                        loginIdList.push(key);
                    }
                    CHAT_UI.refreshJoinedCollaboration(loginIdList);
                 } else {
                 }
Lee Munkyeong committed
198
                 break;
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
            case "RoomMemberJoinedEvent":
                for (let key in g_participants) {
                    loginIdList.push(key);
                }
                CHAT_UI.refreshJoinedCollaboration(loginIdList);
                break;
            case "RoomMemberLeavedEvent":
                for (let key in g_participants) {
                    loginIdList.push(key);
                }
                CHAT_UI.refreshJoinedCollaboration(loginIdList);
                break;
            default:
                console.log('Unrecognized api', json);
                break;
Kang Donghun committed
214
         }
215
    });
Lee Munkyeong committed
216 217
});

Kang Donghun committed
218
function Coview_shareDropdownHide() {
Lee Munkyeong committed
219 220 221 222
    $(".coview_share_dropdown_bar").slideUp();
    $(".coview_share_photo_select_bubble").slideUp();
}

Kang Donghun committed
223
function Coview_moveToVideoShareArea() {
Lee Munkyeong committed
224 225
    $("#loadingIndicator").addClass("full_active");
    $(".coview_share_area").show();
Lee Munkyeong committed
226
    $('#collabo_main').removeClass('none');
Lee Munkyeong committed
227
}
Lee Munkyeong committed
228

Kang Donghun committed
229
function Coview_exitCollaboration() {
Lee Munkyeong committed
230 231 232
    coview_api.LeaveRoom();
    CHAT_UI.joinRoom(CHAT.globalLoginParameter.roomId, CHAT.globalLoginParameter.name);
}
233 234 235 236 237

function Coview_changeHost(shopMemberId) {
    console.log("Change Host To " + shopMemberId);
    coview_api.HostChange(shopMemberId);
}