pull/15/head
Metin 8 years ago
parent 16fd63cb0a
commit fcf4b1bf39

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Vue-Socket.io</title>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div v-if="!join" id="join" class="text-center">
<div class="form-group">
<input type="text" max="12" class="form-control input-lg text-center" v-model="name" placeholder="Name">
</div>
<button @click="joinChat(name)" class="btn btn-primary btn-lg">Join Chat</button>
</div>
<div v-if="join" id="group">
<div class="users">
<h4>Users</h4>
<ul class="list-unstyled">
<li v-for="user in users" track-by="$index">{{user}}</li>
</ul>
</div>
<div class="chat">
<div class="messages">
<ul class="list-unstyled">
<li v-for="m in messages" :class="{me: (m.name === name)}">{{m.name}} - {{m.message}}</li>
</ul>
</div>
<div class="input">
<form @submit.prevent="send(message)">
<div class="input-group">
<input type="text" class="form-control" v-model="message" placeholder="uyudun mu?...">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">-></button>
</span>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.22/vue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.6/socket.io.min.js"></script>
<script src="test.js"></script>
<script src="script.js"></script>
</body>
</html>

@ -0,0 +1,49 @@
Vue.use(VueSocketio, 'http://metinseylan.com:1923');
new Vue({
el: '.container',
data: {
join: false,
name: null,
users: null,
message: null,
messages: {}
},
methods: {
joinChat: function (name) {
if (name) {
this.$socket.emit('join', name);
}
},
send: function (message) {
if (message) {
this.$socket.emit('send', message);
this.$set('message', null);
}
}
},
watch: {
messages: function () {
setTimeout(function () {
$('.messages ul').scrollTop(999999999);
}, 100)
}
},
sockets: {
users: function (users) {
this.$set('users', users);
},
joined: function () {
this.$set('join', true)
},
messages: function (data) {
this.$set('messages', data);
},
onmessage: function (data) {
this.messages.push(data);
},
adduser: function (user) {
this.users.push(user);
}
}
});

@ -0,0 +1,63 @@
body {
color: #373a3c;
background-color: #f9f9f9;
}
* {
border-radius: 0 !important;
}
.container {
max-width: 700px;
margin-top: 5%;
box-shadow: 0 2px 3px rgba(0, 0, 0, .05);
background-color: #fff;
border: 1px solid #eee;
padding: 15px;
}
.users {
border-right: 1px solid #eee;
float: left;
width: 140px;
}
.users ul {
height: 250px;
overflow-y: scroll;
margin: 0;
}
.users h4 {
margin: 0;
border-bottom: 1px solid #eee;
padding-bottom: 3px;
margin-bottom: 5px;
}
::-webkit-scrollbar {
width: 5px;
}
::-webkit-scrollbar-thumb {
background: #666;
}
.chat {
width: 528px;
float: left;
padding-left: 15px;
position: relative;
height: 278px;
}
.chat .messages ul {
height: 240px;
margin: 0;
overflow-y: scroll;
}
.chat .input {
position: absolute;
bottom: 0;
}
Loading…
Cancel
Save