-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathanyRTCWaWaClient.js
1 lines (1 loc) · 3.63 KB
/
anyRTCWaWaClient.js
1
!function(t){function o(){this.events={}}function e(){this.open=!1,this.anyrtc_developerid="",this.anyrtc_appid="",this.anyrtc_appkey="",this.anyrtc_apptoken="",this.socket=null,this.anyrtcId="",this.canGet=!1,this.version="1.0.0"}o.prototype.on=function(t,o){this.events[t]=this.events[t]||[],this.events[t].push(o)},o.prototype.emit=function(t,o){var e,n,c=this.events[t],i=Array.prototype.slice.call(arguments,1);if(c)for(e=0,n=c.length;e<n;e++)c[e].apply(null,i)},(e.prototype=new o).getSdkVersion=function(){return this.version},e.prototype.initEngineWithAnyRTCInfo=function(t,o,e,n){this.anyrtc_developerid=t,this.anyrtc_appid=o,this.anyrtc_appkey=e,this.anyrtc_apptoken=n},e.prototype.openServer=function(){var t=this;try{if(null!==t.socket)return;t.socket=io("http://api.p2p.teameeting.cn:9889"),t.socket.on("connect",function(){t.emit("onConnectServerSuccess"),t.socket.emit("init_anyrtc",{anyrtc_developerid:t.anyrtc_developerid,anyrtc_appid:t.anyrtc_appid,anyrtc_appkey:t.anyrtc_appkey,anyrtc_apptoken:t.anyrtc_apptoken}),t.socket.on("init_anyrtc_success",function(o){0===o.code&&t.emit("onInitAnyRTCSuccess")}),t.socket.on("init_anyrtc_failed",function(o){t.emit("onInitAnyRTCFaild",o)}),t.socket.on("on_join_room",function(o){var e=o.data,n=o.code,c=e.url_list,i=e.room_member;t.emit("onJoinRoom",n,c,i)}),t.socket.on("on_get_room_list",function(o){if(0===o.code){var e=o.data.roomlist;t.emit("onGetRoomList",e)}}),t.socket.on("on_book_result",function(o){if(0===o.code){var e=o.data.data.data;"unbook"===e.cmd?t.on("onBookResult",o.code,o.data.book_member):"book"===e.cmd&&t.on("onUnBookResult",o.code,o.data.book_member)}else 202===o.code?t.emit("onBookResult",202):204===o.code&&t.emit("onBookResult",204)}),t.socket.on("on_book_member_update",function(o){0===o.code&&t.emit("onBookMemberUpdate",o.data.book_member)}),t.socket.on("on_send_ctrl_cmd",function(o){t.emit("onControlCmd",o.code,o.data.data.cmd)}),t.socket.on("on_wawa_ready",function(){t.canGet=!0,t.emit("onReadyStart")}),t.socket.on("on_wawa_result",function(o){0===o.code&&t.emit("onResult",o.data.result)}),t.socket.on("on_room_member",function(o){0===o.code&&t.emit("onRoomMemberUpdate",o.data.room_member)}),t.socket.on("on_wawa_action_timeout",function(o){t.emit("onPlayTimeout",o.code,o.data)}),t.socket.on("on_wawa_ready_timeout",function(){t.emit("onReadyTimeout")}),t.socket.on("on_update_room_url",function(o){t.emit("onRoomUrlUpdate",o.code,o.data)}),t.socket.on("on_wawa_leave_room",function(o){t.emit("onWaWaLeave",o.code)}),t.socket.on("disconnect",function(o){console.log("disconnect",o),t.emit("onDisconnect"),t.emit("onReconnect")})})}catch(t){console.log(t)}},e.prototype.getRoomList=function(){this.socket.emit("get_room_list",{appid:this.anyrtc_appid})},e.prototype.joinRoom=function(t,o,e,n){this.anyrtcId=t,this.socket.emit("join_room",{anyrtcid:t,userid:o,username:e,usericon:n,usertype:1})},e.prototype.leaveRoom=function(){this.socket.emit("leave_room")},e.prototype.book=function(){this.socket.emit("send_cmd",{anyrtcid:this.anyrtcId,data:{cmd:"book"}})},e.prototype.unbook=function(){this.socket.emit("send_cmd",{anyrtcid:this.anyrtcId,data:{cmd:"unbook"}})},e.prototype.play=function(){this.socket.emit("send_cmd",{anyrtcid:this.anyrtcId,data:{cmd:"go"}})},e.prototype.canclePlay=function(){this.socket.emit("send_cmd",{anyrtcid:this.anyrtcId,data:{cmd:"ungo"}})},e.prototype.sendControlCmd=function(t){var o="";if(this.canGet&&"number"==typeof t){switch(t){case 0:o="up";break;case 1:o="down";break;case 2:o="left";break;case 3:o="right";break;case 4:o="action",this.canGet=!1;break;case 5:o="transform"}this.socket.emit("send_ctrl_cmd",{anyrtcid:this.anyrtcId,data:{cmd:o}})}},t.AnyRTCWaWaClient=e}(window);