-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
204 lines (182 loc) · 8.36 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/css/bootstrap.min.css'
integrity='sha512-jnSuA4Ss2PkkikSOLtYs8BlYIeeIK1h99ty4YfvRPAlzr377vr3CXDb7sb7eEEBYjDtcYj+AjBH3FLv5uSJuXg=='
crossorigin='anonymous' />
<link rel="stylesheet" href="style/style.css">
</head>
<body>
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-10">
<div class="row">
<!-- Sol Menü -->
<div class="col-md-3">
<!-- Oda -->
<input class="form-control form-control-lg disabled" type="text" placeholder="Oda Adını Giriniz"
id="groupName" />
<br>
<button type="button" id="btnCreateGroup" class="btn btn-info rightButton disabled">
Create Room
</button>
<br> <br>
<select size="5" style="width: 100%" class="form-select disabled rooms" multiple>
<option selected value="-1">Tüm Odalar</option>
</select>
<br>
<br>
<button type="button" id="btnJoinGroups" class="btn btn-primary rightButton disabled">
Join to Groups
</button>
<!-- Oda -->
<br /><br /><br />
<!-- Clientlar -->
<div class="list-group clients">
<a class="list-group-item list-group-item-action users active">
All CLients
</a>
<div id="_clients"></div>
</div>
<!-- Clientlar -->
</div>
<div class="col-md-6">
<!-- Mesajlasma -->
<div class="alert alert-success" role="alert" id="clientStatusMessage" style="display: none;">
</div>
<div class="alert alert-success" id="clientDurumMessages" style="display: none"></div>
<div class="alert alert-success" id="clientJoinedTrigger" style="display: none"></div>
<textarea rows="3" class="form-control" style="margin-top: 5px" placeholder="Mesajınız"
id="txtMessage"></textarea>
<br>
<button type="button" class="btn btn-info rightButton disabled" id="btnSendGroup">
Send To Group
</button>
<button type="button" class="btn btn-warning rightButton disabled" id="btnSend">
Herkese Gönder
</button>
<button type="button" class="btn btn-primary rightButton disabled" id="btnSendPrimary">
Send
</button>
<br /><br /><br />
<div class="list-group messages">
<a class="list-group-item list-group-item-action message" aria-current="true">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1"></h5> <!--Kimden-->
<h5 class="mb-2"></h5><!--Kime-->
</div>
<p class="mb-1"></p><!--Mesaj-->
</a>
</div>
<!-- Mesajlasma -->
</div>
<div class="col-md-3">
<input class="form-control form-control-lg" type="text" placeholder="Nickname" id="txtNickName" />
<br>
<button type="button" class="btn btn-success leftButton" id="btnLogin">
Login
</button>
</div>
</div>
</div>
<div class="col-md-1"></div>
</div>
<script src="script/signalr.js"></script>
<script src="script/jquery.min.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/js/bootstrap.min.js'
integrity='sha512-ykZ1QQr0Jy/4ZkvKuqWn4iF3lqPZyij9iRv6sGqLRdTPkY69YX6+7wvVGmsdBbiIfN/8OdsI7HABjvEok6ZopQ=='
crossorigin='anonymous'></script>
<script>
$(document).ready(() => {
const connection = new signalR.HubConnectionBuilder()
.withUrl("https://localhost:7021/chatHub")
.build();
connection.start();
$('.disabled').attr("disabled", "disabled");
$("body").on('click', ".users", function () {
$(".users").each((index, item) => {
item.classList.remove("active");
});
$(".rightButton").each((index, item) => {
item.classList.remove("disabled")
})
$(this).addClass("active");
});
$("#btnLogin").click(() => {
const nickName = $("#txtNickName").val();
connection.invoke("GetNickName", nickName)
.catch(error => console.log(error));
$('.disabled').removeAttr("disabled");
});
connection.on("clientJoined", nickName => {
$("#clientStatusMessage").html(`${nickName} client entered`)
$("#clientStatusMessage").fadeIn(2000, () => {
setTimeout(() => {
$("#clientStatusMessage").fadeOut(2000)
}, 2000)
});
});
connection.on("clients", clients => {
$("#_clients").html("")
$.each(clients, (index, item) => {
const user = $(".users").first().clone();
user.removeClass('active');
user.html(item.nickName);
$("#_clients").append(user);
});
});
connection.on("receiveMessage", (message, nickName) => {
console.log(message);
const messages = $('.message').clone();
messages.removeClass('message');
messages.find('p').html(message);
messages.find('h5')[0].innerHTML = nickName;
$('.messages').append(messages);
});
$("#btnSendPrimary").click(() => {
const clientName = $(".users.active").first().html()
const message = $("#txtMessage").val();
connection.invoke("SendMessageAsync", message, clientName);
messages.find('h5')[1].innerHTML = 'You';
});
$("#btnCreateGroup").click(() => {
connection.invoke("AddGroup", $("#groupName").val());
});
connection.on('groups', groups => {
$('.rooms').html('')
let options = `<option selected value="-1">Tüm Odalar</option>`;
$.each(groups, (index, item) => {
options += `<option value="${item.groupName}">${item.groupName}</option>`
});
$('.rooms').append(options);
});
$("#btnJoinGroups").click(() => {
let groupNames = [];
$(".rooms option:selected").map((i, e) => {
groupNames.push(e.innerHTML);
})
connection.invoke("AddClientToGroup", )
});
let _groupName = "";
$("#btnSendGroup").click(() => {
const message = $("#txtMessage").val();
if(_groupName != ''){
connection.invoke("SendMessageToGroup", _groupName, message);
messages.removeClass('message');
messages.find('p').html(message);
messages.find('h5')[0].innerHTML = nickName;
$('.messages').append(messages);
}
})
$(".rooms").change(function() {
let groupName = $(this).val();
_groupName = groupName[0];
connection.invoke('GetClientToGroup', groupName[0]);
});
})
</script>
</body>
</html>