functionsendMessageToPeer(localMessage,id){//メッセージの送信rtm.clientRtm.sendMessageToPeer({text:localMessage},id).then(function(){}).catch(function(err){console.log("AgoraRTM client failed to sending role"+err);});}
メッセージの受信
functionreceiveFromPeerMessage(){//メッセージの受信(MessageFromPeer)rtm.clientRtm.on('MessageFromPeer',function(sentMessage,senderId){//ノック(入室確認)の場合if((sentMessage.text==senderId+":requested")&&(options.uid==host)){varres=confirm("Are you sure "+senderId+" to be joined?");(res==true)?permit(senderId):deny(senderId);return;}//許可の場合if(sentMessage.text==options.uid+":permitted"){join();return;}//不許可の場合if(sentMessage.text==options.uid+":denied"){alert("Please wait for a while as we will invite you from the host.");return;}});}
functionreceiveFromPeerMessage(){//招待の受信rtm.clientRtm.on('RemoteInvitationReceived',function(remoteInvitation){varres=confirm("You got an invitation from the host. Do you want to enter the room?");if(res==true){remoteInvitation.accept();//受領join();}else{remoteInvitation.refuse();//拒否}});}