web_socket_chat_server 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 908c10e8b6e1d6907c83b755b5698882957ecd97
4
- data.tar.gz: 2b8c2ff2b5beb46cc2bb995c36901193b25b5e94
3
+ metadata.gz: 59e8e56c2b0f2b5b3562909b1d5a52c4dcf93f14
4
+ data.tar.gz: 533733dbc57ffd91c685b43a129ac82eb3ddbe0b
5
5
  SHA512:
6
- metadata.gz: a1cebe92b3d42bfdaae20a4c8f47f5f33cb544e0009fe16eb0a38269a05b2ef13ed05f83db39d38f5d7a0fc33ab442313106338208370282e40473607dd184ad
7
- data.tar.gz: 8b410fa05463db45710a2676f0e653df42dec982b8e04f05a8b7690e62fe29e6eebac47c72a9ffd0cd45715e68e736127649387c879d26728d0954e737080527
6
+ metadata.gz: 8eb29dd2561bd88efa27fae20c8a3fea5b549be21d212125e26b9242ad9a9f250972a1f39c0ec1a2025ed2280a09b3f5cf19ee0e690f09c0ad06fa825e5c1721
7
+ data.tar.gz: e7e29c0a64056d62c124d3fdd1bfd79c5c5219d3fe313d2dac51d87c026d7c349907e86d9d7bf696cf54fbda867c6f4d85b408dca7306414b2fe87d7e3794f02
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Chatapp example</title>
5
+ <link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css">
6
+ <link rel="stylesheet" type="text/css" href="css/style.css">
7
+ </head>
8
+ <body>
9
+
10
+ <div id="main-container" class="container">
11
+ <div class="row">
12
+ <div id="login-div" class="col-sm-12 text-center">
13
+ <p class="lead">This is an example of a working Chat application based on WebSocketChatServer</p>
14
+ <p>Please enter your credentials to start testing it.</p>
15
+ <form id="login-form" class="form-inline">
16
+ <div class="form-group">
17
+ <label for="username">Name</label>
18
+ <input type="text" class="form-control" id="username" placeholder="username">
19
+ </div>
20
+ <div class="form-group">
21
+ <label for="password">Email</label>
22
+ <input type="password" class="form-control" id="password" placeholder="********">
23
+ </div>
24
+ <button type="submit" class="btn btn-primary">Login</button>
25
+ </form>
26
+ </div>
27
+
28
+
29
+ <div id="chat-components" class="col-sm-12">
30
+
31
+ <div class="row">
32
+ <div id="chat-log-wrapper" class="col-sm-10 lead">
33
+ <div id="chat-log">
34
+
35
+ </div>
36
+ </div>
37
+
38
+ <div id ="users-list" class="col-sm-2 text-right">
39
+
40
+ </div>
41
+ </div>
42
+
43
+ <div class="row">
44
+ <div id="chat-text-wrapper" class="col-sm-12">
45
+ <input type="text" class="form-control" id="chat-text" placeholder="Type to chat...">
46
+ </div>
47
+ </div>
48
+
49
+ </div>
50
+
51
+
52
+ </div>
53
+ </div>
54
+
55
+ <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js" type="text/javascript"></script>
56
+ <script src="js/script.js" type="text/javascript"></script>
57
+ </body>
58
+ </html>
@@ -0,0 +1,41 @@
1
+ html, body{
2
+ height: 100%;
3
+ padding-top: 30px;
4
+ overflow: hidden;
5
+ }
6
+
7
+ #chat-log-wrapper {
8
+ background-color: #DCDFEE;
9
+ overflow: scroll;
10
+ height: 400px;
11
+ }
12
+ #chat-log{
13
+ height: 100%;
14
+ overflow: auto;
15
+ }
16
+
17
+ #users-list{
18
+ background-color: #BBDFEE;
19
+ height: 400px;
20
+ font-weight: bold;
21
+ }
22
+
23
+ #chat-components {
24
+ margin-top: 20px;
25
+ }
26
+
27
+ #login-div{
28
+ margin-top: 200px;
29
+ }
30
+
31
+ #chat-log{
32
+ overflow: scroll;
33
+ }
34
+
35
+ #users-list {
36
+ overflow: scroll;
37
+ }
38
+
39
+ #chat-text-wrapper{
40
+ padding: 0px;
41
+ }
@@ -0,0 +1,143 @@
1
+ $(function(){
2
+ var ws = null;
3
+ showLoginForm();
4
+ hideChatComponents();
5
+ $("#login-form").on("submit", function(e){
6
+ e.preventDefault();
7
+
8
+ var username = $("#username").val();
9
+ var password = $("#password").val();
10
+
11
+ if(/^[a-zA-Z0-9]{3,}/i.test(username) === false){
12
+ alert("The username must be at least 3 alphnumeric characters.");
13
+ return;
14
+ }
15
+
16
+ if(/^[a-zA-Z0-9]{6,}/i.test(password) === false){
17
+ alert("The password must be at least 3 alphnumeric characters.");
18
+ return;
19
+ }
20
+
21
+ startChatting(username, password);
22
+ });
23
+
24
+
25
+ });
26
+
27
+
28
+ function startChatting(username, password){
29
+
30
+ var Socket = "MozWebSocket" in window ? MozWebSocket : WebSocket;
31
+ var socket = new Socket("ws://localhost:8080?username=" + username + "&password=" + password );
32
+
33
+ socket.onmessage = function(event)
34
+ {
35
+
36
+ var data = JSON.parse(event.data);
37
+ switch(data.command){
38
+ case "failed_connection":
39
+ alert(data.information);
40
+ location.reload();
41
+ break;
42
+
43
+ case "successful_connection":
44
+ if(data.data !== null){
45
+ for(i = 0; i < data.data.length; i++){
46
+ $("#users-list").append("<span class='label label-primary' id="+data.data[i]+">"+ data.data[i]+"<br></span>");
47
+ }
48
+ }
49
+ break;
50
+
51
+ case "new_connection":
52
+ $("#users-list").append("<span class='label label-primary' id="+data.data+">"+data.data+"<br></span>");
53
+ break;
54
+
55
+ case "user_disconnected":
56
+ displayChatText("<span class='label label-info'>" + data.data + " has disconnected</span><br>");
57
+ $('#'+data.data).remove();
58
+ break;
59
+
60
+ case "private_message":
61
+ displayChatText("<span class='label label-primary'>Private message from " + data.data.from_user + "</span>: " + data.data.message + "<br>");
62
+ break;
63
+
64
+ case "chat_message":
65
+ displayChatText("<span class='label label-primary'>" + data.data.from_user + "</span>: " + data.data.message + "<br>");
66
+ break;
67
+
68
+ case "ban_user":
69
+ displayChatText("<span class='label label-info'>" + data.information + "<br>");
70
+ break;
71
+
72
+ case "system_information":
73
+ displayChatText("<span class='label label-danger'>" + data.data.data + "<br>");
74
+ break;
75
+
76
+ default:
77
+ break;
78
+ }
79
+
80
+
81
+
82
+
83
+ };
84
+ socket.onclose = function(event) {
85
+ location.reload();
86
+ };
87
+ socket.onopen = function() {
88
+ hideLoginForm();
89
+ showChatComponents();
90
+
91
+ $(document).on("keyup", "#chat-text", function(event){
92
+ if(event.keyCode == 13){
93
+ var message = $("#chat-text").val();
94
+ if(message === "") return;
95
+ $("#chat-text").val("");
96
+
97
+ var words = message.split(" ");
98
+ if((words.length > 1) && (words[0] === "ban_user")){
99
+ socket.send(JSON.stringify({command: "ban_user", data: words[1]}));
100
+ return;
101
+ }
102
+
103
+ if((words.length > 2) && (words[0] === "private_message")){
104
+ var str = "";
105
+ for(i = 2; i < words.length; i++){
106
+ str = str + words[i] + " ";
107
+ }
108
+ socket.send(JSON.stringify({command: "private_message", data: {to_user: words[1], message: str}}));
109
+ return;
110
+ }
111
+ sendChatMessage(socket, message);
112
+ }
113
+ });
114
+ displayChatText("<h5><span class='alert-success'>Connected. to send a private message type (private_message USERNAME MESSAGE). To ban a user when you are logged in as admin, type (ban_user USERNAME)</span><br></h5>");
115
+ };
116
+ }
117
+
118
+
119
+ function sendChatMessage(socket, message){
120
+ socket.send(JSON.stringify({command: "chat_message", data: message}));
121
+ }
122
+
123
+ function hideChatComponents(){
124
+ $("#chat-components").hide();
125
+ }
126
+
127
+ function showChatComponents(){
128
+ $("#chat-components").show();
129
+ $("#chat-text").focus();
130
+ }
131
+
132
+ function hideLoginForm(){
133
+ $("#login-div").hide();
134
+ }
135
+
136
+ function showLoginForm(){
137
+ $("#login-div").show();
138
+ }
139
+
140
+ function displayChatText(text){
141
+ $("#chat-log").append(text);
142
+ $("#chat-log").animate({ scrollTop: $("#chat-log")[0].scrollHeight}, 1000);
143
+ }
data/README.md CHANGED
@@ -16,8 +16,12 @@ $ bundle
16
16
 
17
17
  Or install it yourself as:
18
18
 
19
+ ```
19
20
  $ gem install web_socket_chat_server
21
+ ```
20
22
 
23
+ ## Documentation
24
+ For better understanding, check the docs at http://abulewis.com/ws/doc/WebSocketChatServer/ChatServer.html
21
25
  ## Usage
22
26
 
23
27
  An example on how to run the server:
@@ -1,3 +1,3 @@
1
1
  module WebSocketChatServer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["jonemob@gmail.com"]
11
11
  spec.summary = %q{A wrapper class for em-websocket (https://github.com/igrigorik/em-websocket) implementing a custom chat server protocol.}
12
12
  spec.description = %q{For more details, please read the documentation at http://abulewis.com/doc/WebSocketChatServer.html}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/phenomen2277/web_socket_chat_server"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_socket_chat_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jone Samra
@@ -60,6 +60,9 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
+ - CHAT_CLIENT_EXAMPLE/chatapp.html
64
+ - CHAT_CLIENT_EXAMPLE/css/style.css
65
+ - CHAT_CLIENT_EXAMPLE/js/script.js
63
66
  - Gemfile
64
67
  - LICENSE.txt
65
68
  - README.md
@@ -67,7 +70,7 @@ files:
67
70
  - lib/web_socket_chat_server.rb
68
71
  - lib/web_socket_chat_server/version.rb
69
72
  - web_socket_chat_server.gemspec
70
- homepage: ''
73
+ homepage: https://github.com/phenomen2277/web_socket_chat_server
71
74
  licenses:
72
75
  - MIT
73
76
  metadata: {}