|
@ -20,6 +20,12 @@ var options = { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function add_chat_text(s) { |
|
|
|
|
|
$('#chat-box').append($('<p></p>').text(s)); |
|
|
|
|
|
$('#chat-box').animate({ |
|
|
|
|
|
scrollTop: $("#chat-box")[0].scrollHeight |
|
|
|
|
|
}, 300); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$('.leave-btn').hide(); |
|
|
$('.leave-btn').hide(); |
|
|
|
|
|
|
|
@ -36,7 +42,7 @@ $('.send-message').submit(async function (e) { |
|
|
} |
|
|
} |
|
|
var inp = $(this).find('input'); |
|
|
var inp = $(this).find('input'); |
|
|
rtm_channel.sendMessage({'text': inp.val()}).then(() => { |
|
|
rtm_channel.sendMessage({'text': inp.val()}).then(() => { |
|
|
$('#part2').append($('<p></p>').text(window._MY_NAME + ': ' + inp.val())); |
|
|
|
|
|
|
|
|
add_chat_text(window._MY_NAME + ': ' + inp.val()); |
|
|
inp.val(''); |
|
|
inp.val(''); |
|
|
}).catch(error => { |
|
|
}).catch(error => { |
|
|
alert('发送失败', error); |
|
|
alert('发送失败', error); |
|
@ -60,9 +66,15 @@ $('.join-form').submit(async function (e) { |
|
|
rtm_channel.on('ChannelMessage', (message, user) => { |
|
|
rtm_channel.on('ChannelMessage', (message, user) => { |
|
|
console.log(message, user); |
|
|
console.log(message, user); |
|
|
if (message.messageType === 'TEXT') { |
|
|
if (message.messageType === 'TEXT') { |
|
|
$('#part2').append($('<p></p>').text(user + ': ' + message.text)); |
|
|
|
|
|
|
|
|
add_chat_text(user + ': ' + message.text); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
rtm_channel.on('MemberJoined', memberId => { |
|
|
|
|
|
add_chat_text(`[${memberId} 加入了]`) |
|
|
|
|
|
}); |
|
|
|
|
|
rtm_channel.on('MemberLeft', memberId => { |
|
|
|
|
|
add_chat_text(`[${memberId} 离开了]`) |
|
|
|
|
|
}); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error(error); |
|
|
console.error(error); |
|
|
alert('出错啦\n' + error); |
|
|
alert('出错啦\n' + error); |
|
@ -74,6 +86,8 @@ $('.join-form').submit(async function (e) { |
|
|
$(".leave-btn").click(function (e) { |
|
|
$(".leave-btn").click(function (e) { |
|
|
leave(); |
|
|
leave(); |
|
|
rtm_channel.leave(); |
|
|
rtm_channel.leave(); |
|
|
|
|
|
rtm_channel = null; |
|
|
|
|
|
$('#chat-box').empty(); |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
function set_soundmeter(ele, at) { |
|
|
function set_soundmeter(ele, at) { |
|
|