autoscroll and error update
This commit is contained in:
parent
ce860230e8
commit
d7d1340245
2
api.js
2
api.js
@ -56,6 +56,8 @@ wss.on('connection', (ws, req) => {
|
|||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
user.splice(user.indexOf(thisuser), 1);
|
user.splice(user.indexOf(thisuser), 1);
|
||||||
console.log(`${req.socket.remoteAddress} (${thisuser}) closed`)
|
console.log(`${req.socket.remoteAddress} (${thisuser}) closed`)
|
||||||
|
wss.clients.forEach(client =>
|
||||||
|
client.send(JSON.stringify({type: "room", name: "open chat", user: user})))
|
||||||
})
|
})
|
||||||
|
|
||||||
ws.send(JSON.stringify({type: "info", time: Date.now(), content: "connected"}))
|
ws.send(JSON.stringify({type: "info", time: Date.now(), content: "connected"}))
|
||||||
|
1
public/sym/expand_more-black-24dp.svg
Normal file
1
public/sym/expand_more-black-24dp.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="black" width="24px" height="24px"><path d="M0 0h24v24H0z" fill="none"/><path d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"/></svg>
|
After Width: | Height: | Size: 199 B |
@ -31,6 +31,7 @@ name: "error",
|
|||||||
background-color: #E53935;
|
background-color: #E53935;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
box-shadow: 3px 3px 10px #111;
|
box-shadow: 3px 3px 10px #111;
|
||||||
|
animation: slide-from-left alternate 0.2s;
|
||||||
}
|
}
|
||||||
#errorBox{
|
#errorBox{
|
||||||
display: none;
|
display: none;
|
||||||
|
@ -25,8 +25,8 @@ export default {
|
|||||||
this.msg.content.text = ""
|
this.msg.content.text = ""
|
||||||
document.getElementById("messagesContainer").style.height = "calc(100% - 7rem)"
|
document.getElementById("messagesContainer").style.height = "calc(100% - 7rem)"
|
||||||
document.getElementById("newMessageInput").style.height = "1.25rem"
|
document.getElementById("newMessageInput").style.height = "1.25rem"
|
||||||
let msgContainer = document.getElementById("messagesContainer")
|
//let msgContainer = document.getElementById("messagesContainer")
|
||||||
msgContainer.scrollTo(0, msgContainer.scrollHeight)
|
//msgContainer.scrollTo(0, msgContainer.scrollHeight)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resizeMessageBanner(){
|
resizeMessageBanner(){
|
||||||
|
@ -72,8 +72,8 @@ new Vue({
|
|||||||
}
|
}
|
||||||
}).$mount('#app')
|
}).$mount('#app')
|
||||||
|
|
||||||
const wsurl = 'ws://127.0.0.1:8090'
|
//const wsurl = 'ws://127.0.0.1:8090'
|
||||||
//const wsurl = 'wss://chat.adb.sh:8080'
|
const wsurl = 'wss://chat.adb.sh:8080'
|
||||||
|
|
||||||
const socket = new WebSocket(wsurl)
|
const socket = new WebSocket(wsurl)
|
||||||
function element(id){ return document.getElementById(id)}
|
function element(id){ return document.getElementById(id)}
|
||||||
@ -102,7 +102,9 @@ socket.onmessage = (e) => {
|
|||||||
else if (msg.type === 'message'){
|
else if (msg.type === 'message'){
|
||||||
chatroom.messages.push(msg)
|
chatroom.messages.push(msg)
|
||||||
let msgContainer = document.getElementById("messagesContainer")
|
let msgContainer = document.getElementById("messagesContainer")
|
||||||
if (msgContainer.scrollHeight < msgContainer.scrollTop + 1000) msgContainer.scrollTo(0, msgContainer.scrollHeight)
|
if (msg.content.user === chatroom.username || msgContainer.scrollHeight < msgContainer.scrollTop + 1000)
|
||||||
|
setTimeout(() => {msgContainer.scrollTo(0, msgContainer.scrollHeight)}, 50)
|
||||||
|
else document.getElementById("scrollDown").style.display = "block"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<newMessage />
|
<newMessage />
|
||||||
|
<icon v-on:click.native="scrollToBottom()" id="scrollDown" ic="./sym/expand_more-black-24dp.svg" />
|
||||||
<topBanner />
|
<topBanner />
|
||||||
<chatInformation />
|
<chatInformation />
|
||||||
</div>
|
</div>
|
||||||
@ -26,16 +27,25 @@ import newMessage from '@/components/newMessage.vue';
|
|||||||
import topBanner from '@/components/topBanner.vue';
|
import topBanner from '@/components/topBanner.vue';
|
||||||
import main from '@/main.js';
|
import main from '@/main.js';
|
||||||
import ChatInformation from "@/components/chatInformation";
|
import ChatInformation from "@/components/chatInformation";
|
||||||
|
import Icon from "@/components/icon";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'chat',
|
name: 'chat',
|
||||||
components: {
|
components: {
|
||||||
|
Icon,
|
||||||
ChatInformation,
|
ChatInformation,
|
||||||
message,
|
message,
|
||||||
messageReceive,
|
messageReceive,
|
||||||
newMessage,
|
newMessage,
|
||||||
topBanner
|
topBanner
|
||||||
},
|
},
|
||||||
|
methods:{
|
||||||
|
scrollToBottom(){
|
||||||
|
let msgContainer = document.getElementById("messagesContainer")
|
||||||
|
msgContainer.scrollTo(0, msgContainer.scrollHeight)
|
||||||
|
document.getElementById("scrollDown").style.display = "none"
|
||||||
|
}
|
||||||
|
},
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
chatroom: main.data().chatroom
|
chatroom: main.data().chatroom
|
||||||
@ -59,4 +69,11 @@ export default {
|
|||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
#scrollDown{
|
||||||
|
position: absolute;
|
||||||
|
background-color: #fff;
|
||||||
|
bottom: 5rem;
|
||||||
|
right: 1rem;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user