###困っていること:
標題のメッセージが明らかに必要以上にconsoleに出力されています
結果として、ページの動きが重くなっています
###試してみたこと:
- APIキーを新たに取得 → 効果なし
###追記:
時間をおいて(1hほど)アクセスしたところ、同じ現象は起きませんでした
原因は不明なままなので引き続き回答を募集します
###コード:
javascript
1const peer = new Peer({ 2 key: 'b018ba57-5ff0-4bc3-a8c0-727c5998e71d', 3 debug: 3 4}); 5 6let room = null; 7let roomCount = 1; 8let memberCount = 0; 9 10const MAX_ROOM_COUNT = 2; 11const MAX_MEMBER_COUNT = 2; 12 13peer.on('open', function(id){ 14 $('#myId').text(id); 15}); 16 17peer.on('close', function(){ // close Peer 18 // reset HTML: myId 19 $('#myId').text('--'); 20 // reset roomCount 21 roomCount = 0; 22}) 23 24$('#autoJoin').click(function(){ 25 autoJoinRoom(roomCount); 26}) 27 28$('#leave').click(function(){ 29 leaveRoom(); 30}) 31 32$('#send').click(function(){ 33 chat = $('#chat').val(); 34 // send chat 35 room.send(chat); 36 // show chat in own log 37 toLog(chat, 'me'); 38 // clear input 39 $('#chat').val(''); 40}) 41 42/** FUNCTION DEFINITIONS **/ 43function autoJoinRoom(roomCount){ 44 leaveRoom(); 45 joinRoom('room' + roomCount); 46} 47 48function joinRoom(roomName){ 49 room = peer.joinRoom(roomName); 50 51 room.on('open', function(){ 52 // set HTML: roomName, maxMemberCount 53 $('#roomName').text(roomName); 54 $('#maxMemberCount').text(MAX_MEMBER_COUNT); 55 // increment memberCount 56 memberCount++; 57 // set memberCount 58 setCount(memberCount); 59 // log 60 toLog('joined: ' + roomName); 61 }); 62 63 room.on('peerJoin', function(id){ 64 // increment memberCount 65 memberCount++; 66 // send memberCount to new user 67 room.send({to: id, count: memberCount}); 68 // send 'abort' to new user if memberCount > MAX_MEMBER_COUNT 69 if(memberCount > MAX_MEMBER_COUNT) { 70 room.send({abort: id}); 71 } 72 // set memberCount 73 setCount(memberCount); 74 }); 75 76 room.on('peerLeave', function(){ 77 // decrement memberCount 78 memberCount--; 79 // set memberCount 80 setCount(memberCount); 81 }) 82 83 room.on('close', function(){ 84 // reset memberCount 85 memberCount = 0; 86 // reset HTML: roomName, memberCount, maxMemberCount 87 $('#roomName').text('--'); 88 $('#memberCount').text('--'); 89 $('#maxMemberCount').text('--'); 90 // log 91 toLog('left: ' + roomName); 92 }) 93 94 room.on('data', function(msg){ // types of msg: textchat, {abort: id}, {to: id, count:memberCount} 95 if(msg.data.abort == peer.id) { // receive 'abort' 96 // increment roomCount 97 roomCount++; 98 if(roomCount <= MAX_ROOM_COUNT) { 99 // if roomCount <= MAX_ROOM_COUNT then autoJoinRoom 100 autoJoinRoom(roomCount); 101 } else { 102 // leaveRoom 103 leaveRoom(); 104 // else 'failed to autojoin' 105 toLog('failed autoJoin'); 106 } 107 // else 'failed to autojoin' 108 } else if(msg.data.to == peer.id){ // receive memberCount 109 // copy msg to memberCount 110 memberCount = msg.data.count; 111 // set memberCount 112 setCount(memberCount); 113 } else if(!msg.data.abort && !msg.data.to){ // receive textchat 114 toLog(msg.data, 'ID:' + msg.src); 115 116 } 117 118 }) 119} 120 121function leaveRoom(){ 122 if(!room){ 123 // no joined room 124 return; 125 } 126 room.close(); 127} 128 129function setCount(c){ 130 $('#memberCount').text(c); 131} 132 133function toLog(msg, frm = 'system'){ 134 $('#log').append(frm + '> ' + msg + '<br>'); 135}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。