Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Toiney Chat Client</title>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="description" content="">
- <meta name="author" content="">
- <link rel="shortcut icon" href="favicon.ico">
- <!-- will's pimpin css imports -->
- <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
- <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
- <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
- <style>
- body{
- background:#252830;
- margin:0px;
- height:900px;
- color:#cfd2da;
- font-family: sans-serif;
- height:100%;
- width:100%;
- margin-left:1%;
- }
- btn{
- color:#cfd2da;
- }
- h1,p,h2,h3{
- color:#cfd2da;
- }
- .chat_box{
- position:fixed;
- right:20px;
- bottom:0px;
- width:250px;
- }
- .chat_body{
- background:white;
- height:400px;
- padding:5px 0px;
- }
- .chat_head,.msg_head{
- background:#f39c12;
- color:white;
- padding:15px;
- font-weight:bold;
- cursor:pointer;
- border-radius:5px 5px 0px 0px;
- }
- .msg_box{
- position:fixed;
- bottom:-5px;
- width:250px;
- background:white;
- border-radius:5px 5px 0px 0px;
- }
- .msg_head{
- background:#3498db;
- }
- .msg_body{
- background:white;
- height:200px;
- font-size:12px;
- padding:15px;
- overflow:auto;
- overflow-x: hidden;
- }
- .msg_input{
- width:100%;
- border: 1px solid white;
- border-top:1px solid #DDDDDD;
- -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
- -moz-box-sizing: border-box; /* Firefox, other Gecko */
- box-sizing: border-box;
- }
- .close{
- float:right;
- cursor:pointer;
- }
- .minimize{
- float:right;
- cursor:pointer;
- padding-right:5px;
- }
- .user{
- position:relative;
- padding:10px 30px;
- }
- .user:hover{
- background:#f8f8f8;
- cursor:pointer;
- }
- .user:before{
- content:'';
- position:absolute;
- background:#2ecc71;
- height:10px;
- width:10px;
- left:10px;
- top:15px;
- border-radius:6px;
- }
- .msg_a{
- position:relative;
- background:#FDE4CE;
- padding:10px;
- min-height:10px;
- margin-bottom:5px;
- margin-right:10px;
- border-radius:5px;
- }
- .msg_a:before{
- content:"";
- position:absolute;
- width:0px;
- height:0px;
- border: 10px solid;
- border-color: transparent #FDE4CE transparent transparent;
- left:-20px;
- top:7px;
- }
- .msg_b{
- background:#EEF2E7;
- padding:10px;
- min-height:15px;
- margin-bottom:5px;
- position:relative;
- margin-left:10px;
- border-radius:5px;
- word-wrap: break-word;
- }
- .msg_b:after{
- content:"";
- position:absolute;
- width:0px;
- height:0px;
- border: 10px solid;
- border-color: transparent transparent transparent #EEF2E7;
- right:-20px;
- top:7px;
- }
- /* Dropdown Button */
- .dropbtn {
- background-color: #3498DB;
- color: white;
- padding: 16px;
- font-size: 16px;
- border: none;
- cursor: pointer;
- }
- /* Dropdown button on hover & focus */
- .dropbtn:hover, .dropbtn:focus {
- background-color: #2980B9;
- }
- /* The container <div> - needed to position the dropdown content */
- .dropdown {
- position: relative;
- display: inline-block;
- }
- /* Dropdown Content (Hidden by Default) */
- .dropdown-content {
- display: none;
- position: absolute;
- background-color: #f1f1f1;
- min-width: 160px;
- box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
- z-index: 1;
- }
- /* Links inside the dropdown */
- .dropdown-content a {
- color: black;
- padding: 12px 16px;
- text-decoration: none;
- display: block;
- }
- /* Change color of dropdown links on hover */
- .dropdown-content a:hover {background-color: #ddd}
- /* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
- .show {display:block;}
- </style>
- </head>
- <body>
- <h1>Toiney Chat Client</h1>
- <p>
- Host: <input id="webSocketHost" class="form-control" style="width:25%" type="text" value="www.teenchat.com/ws"/>
- </p>
- <p>
- <button class="btn btn-success" onClick="initWebSocket();">Connect</button>
- <button class="btn btn-danger" id="disconnectButton" onClick="stopWebSocket();" disabled>Disconnect</button>
- <button class="btn btn-warning" onClick="checkSocket();">State</button>
- <button class="btn btn-primary" id ="reqBtn" onClick="req_list({{ data }});">Send Requirements</button>
- </p>
- <p>
- <textarea id="debugTextArea" class="form-control" rows="3" style="width:40%" readonly></textarea>
- </p>
- <p>
- <textarea id="chatTextArea" class="form-control" style="width:40%;" readonly></textarea>
- </p>
- <p>
- <input type="text" id="inputText" class="form-control" style="width:40%;" onkeydown="if(event.keyCode===13)sendMessage();"/>
- <button id="sendButton" class="btn btn-success" onClick="sendMessage();" disabled>Send</button>
- </p>
- <div class="dropdown">
- <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
- User
- </button>
- <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
- <a class="dropdown-item" href="#">Action</a>
- <a class="dropdown-item" href="#">Another action</a>
- <a class="dropdown-item" href="#">Something else here</a>
- </div>
- </div>
- <script type="text/javascript">
- var debugTextArea = document.getElementById("debugTextArea");
- var chatTextArea = document.getElementById("chatTextArea");
- function debug(message) {
- debugTextArea.value += message + "\n";
- debugTextArea.scrollTop = debugTextArea.scrollHeight;
- }
- function format(msg) {
- chatTextArea.value += msg + "\n";
- chatTextArea.scrollTop = chatTextArea.scrollHeight;
- }
- function sendMessage() {
- var strToSend = document.getElementById("inputText").value;
- if ( websocket != null) {
- if (strToSend === '!main') {
- strToSend.replace("!main", "");
- document.getElementById("inputText").value = "";
- websocket.send( '{"Post": "' + 'lol' + '", "RoomID": "rdqlcurrmpk", "C": "post"}' );
- console.log( "string sent :", '"'+strToSend+'"' );
- format(strToSend);
- } else {
- document.getElementById("inputText").value = "";
- websocket.send(strToSend);
- console.log("string sent :", '"' + strToSend + '"');
- debug(strToSend);
- }
- }
- }
- var websocket = null;
- function initWebSocket() {
- try {
- if (typeof MozWebSocket === 'function')
- WebSocket = MozWebSocket;
- if ( websocket && websocket.readyState === 1 )
- websocket.close();
- var wsUri = "ws://" + document.getElementById("webSocketHost").value;
- websocket = new WebSocket( wsUri );
- websocket.onopen = function (evt) {
- debug("CONNECTED");
- document.getElementById("disconnectButton").disabled = false;
- document.getElementById("sendButton").disabled = false;
- document.getElementById("reqBtn").disabled = false;
- };
- websocket.onclose = function (evt) {
- debug("DISCONNECTED");
- document.getElementById("disconnectButton").disabled = true;
- document.getElementById("sendButton").disabled = true;
- document.getElementById("reqBtn").disabled = true;
- };
- websocket.onmessage = function (evt) {
- console.log( "Message received :", evt.data );
- debug( evt.data );
- // resp will be sent to format textbox
- var resp = JSON.parse(evt.data);
- if (resp !== undefined) {
- var options = [
- set0 = [resp['UID']]
- ];
- function makeUL(array) {
- // Create the list element:
- var list = document.createElement('ul');
- for(var i = 0; i < array.length; i++) {
- // Create the list item:
- var item = document.createElement('li');
- item.setAttribute("id", resp['UID']);
- // Set its contents:
- item.appendChild(document.createTextNode(array[i]));
- // Add it to the list:
- list.appendChild(item);
- }
- // Finally, return the constructed list:
- return list;
- }
- // Add the contents of options[0] to #myDropdown:
- document.getElementById('chatTabs').appendChild(makeUL(options[0]));
- }
- else {
- format("unlucky")
- }
- };
- websocket.onerror = function (evt) {
- debug('ERROR: ' + evt.data);
- };
- } catch (exception) {
- debug('ERROR: ' + exception);
- }
- }
- function req_list(data) {
- if (websocket != null) {
- debug("Sending REQ LIST");
- setTimeout(function () {
- arrayLength = data.length;
- for (var i = 0; i < arrayLength; i++) {
- websocket.send(data[i]);
- }
- }, 1000)
- }
- }
- function stopWebSocket() {
- if (websocket)
- websocket.close();
- }
- function checkSocket() {
- if (websocket != null) {
- var stateStr;
- switch (websocket.readyState) {
- case 0: {
- stateStr = "CONNECTING";
- break;
- }
- case 1: {
- stateStr = "OPEN";
- break;
- }
- case 2: {
- stateStr = "CLOSING";
- break;
- }
- case 3: {
- stateStr = "CLOSED";
- break;
- }
- default: {
- stateStr = "UNKNOWN";
- break;
- }
- }
- debug("WebSocket state = " + websocket.readyState + " ( " + stateStr + " )");
- } else {
- debug("WebSocket is null");
- }
- }
- /* When the user clicks on the button,
- toggle between hiding and showing the dropdown content */
- function myFunction() {
- document.getElementById("myDropdown").classList.toggle("show");
- }
- // Close the dropdown menu if the user clicks outside of it
- window.onclick = function(event) {
- if (!event.target.matches('.dropbtn')) {
- var dropdowns = document.getElementsByClassName("dropdown-content");
- var i;
- for (i = 0; i < dropdowns.length; i++) {
- var openDropdown = dropdowns[i];
- if (openDropdown.classList.contains('show')) {
- openDropdown.classList.remove('show');
- }
- }
- }
- }
- $(document).ready(function(){
- $('.chat_head').click(function(){
- $('.chat_body').slideToggle('slow');
- });
- $('.msg_head').click(function(){
- $('.msg_wrap').slideToggle('slow');
- });
- $('.close').click(function(){
- $('.msg_box').hide();
- });
- $('.user').click(function(){
- $('.msg_wrap').show();
- $('.msg_box').show();
- });
- $('textarea').keypress(
- function(e){
- if (e.keyCode == 13) {
- e.preventDefault();
- var msg = $(this).val();
- $(this).val('');
- if(msg!='')
- $('<div class="msg_b">'+msg+'</div>').insertBefore('.msg_push');
- $('.msg_body').scrollTop($('.msg_body')[0].scrollHeight);
- }
- });
- });
- </script>
- <div class="chat_box">
- <div class="chat_head"> Chat Box</div>
- <div class="chat_body">
- <div id="chatTabs"></div>
- </div>
- </div>
- <div class="msg_box" style="right:290px">
- <div class="msg_head">
- <div class="close">x</div>
- </div>
- <div class="msg_wrap">
- <div class="msg_body">
- <div class="msg_b" id="msgBody"></div>
- <div class="msg_push"></div>
- </div>
- <div class="msg_footer"><textarea class="msg_input" rows="4"></textarea></div>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement