web_socket_chat_server 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -15
- data/lib/web_socket_chat_server/version.rb +1 -1
- data/lib/web_socket_chat_server.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 240864386719a853161a794b90a66f287eda2df2
|
4
|
+
data.tar.gz: 4af6181438cb88427ae8e0614488ad3a89511eed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9aa2b30d0290fb9afd02e0cde20f1373c828adfb5122e57afe20ab0c587a9a5e24dcc527c6d9c18ce0e3069cb4319bef86065f1c9bfc543eed21aeb4505d357
|
7
|
+
data.tar.gz: ceb1e274764aeabde2e05433a0afe5b899b2d041ef447066b30050f4bf2121e1c354e33409eee0ac521cea394d7108117960946e2232caa195b798b73bbeb431
|
data/README.md
CHANGED
@@ -2,19 +2,12 @@
|
|
2
2
|
|
3
3
|
A wrapper class for em-websocket (https://github.com/igrigorik/em-websocket) implementing a custom chat server protocol.
|
4
4
|
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'web_socket_chat_server'
|
11
|
-
```
|
12
5
|
|
13
|
-
|
6
|
+
![alt tag](http://abulewis.com/ws/wscs.png)
|
14
7
|
|
15
|
-
|
8
|
+
## Installation
|
16
9
|
|
17
|
-
|
10
|
+
Type this in the console:
|
18
11
|
|
19
12
|
```
|
20
13
|
$ gem install web_socket_chat_server
|
@@ -63,17 +56,19 @@ You have to pass the query parameters username & password to the socket client w
|
|
63
56
|
|
64
57
|
On successful connection, you can send a JSON hash of the format {command: ”…”, data: ”…}
|
65
58
|
|
66
|
-
### Available commands are:
|
59
|
+
### Available client commands are:
|
60
|
+
```
|
67
61
|
{command: ”chat_message”, data: ”your message”}
|
68
62
|
|
69
63
|
{command: ”private_message”, data: {to_user: ”chuck_norris”, message: ”Private message”}}
|
70
64
|
|
71
65
|
{command: ”ban_user”, data: ”chuck_norris”}
|
72
|
-
|
66
|
+
```
|
73
67
|
|
74
68
|
The server will respond with a JSON hash of the format {command: ”…”, data: ”…”, information: ”…”}
|
75
69
|
|
76
|
-
### Available responses are:
|
70
|
+
### Available server responses are:
|
71
|
+
```
|
77
72
|
{command: ”failed_connection”, data: nil, information: ”Some details”}
|
78
73
|
|
79
74
|
{command: ”successful_connection”, data: array_of_connected_users, information: ”Some details”}
|
@@ -82,11 +77,11 @@ The server will respond with a JSON hash of the format {command: ”…”, data
|
|
82
77
|
|
83
78
|
{command: ”chat_message”, data: {from_user: ”chuck_norris”, message: ”The message”}, information: ”Some details.”}
|
84
79
|
|
85
|
-
{command: ”ban_user”, data:
|
80
|
+
{command: ”ban_user”, data: boolean, information: ”Some details.”}
|
86
81
|
|
87
82
|
{command: ”private_message”, data: {from_user: ”chuck_norris”, message: ”The message”}, information: ”Some details.”}
|
88
83
|
|
89
84
|
{command: ”system_information”, data: ”Issue”, information: ”Some details.”}
|
90
85
|
|
91
86
|
{command: ”user_disconnected”, data: ”username”, information: ”Some details.”}
|
92
|
-
|
87
|
+
```
|
@@ -33,10 +33,16 @@ class ChatServer
|
|
33
33
|
# * +:tls-options+ (Optional) - The TLS options as allowed by em-websocket (https://github.com/igrigorik/em-websocket#secure-server).
|
34
34
|
# * +:secure_proxy+ (Optional) - When ruinng behind a SSL proxy (https://github.com/igrigorik/em-websocket#running-behind-an-ssl-proxyterminator-like-stunnel).
|
35
35
|
# * +:admins+ (Optional) - In order to have admins (for banning users). Pass an array of ChatUser objects to this key. The ChatUser object contains of username and password attributes. The username must consist of at least 3 alphanumeric characters. The password must at least consist of 6 alphanumeric characters.
|
36
|
+
# * +:allowed_origin (Optional) - Allow connections only from the passed URI. The URI should be the domain and/or port (depending on the server setup), in which your application is operating.
|
36
37
|
def initialize(args = {:host => "0.0.0.0", :port => 8080})
|
38
|
+
@server_started = false
|
37
39
|
raise ArgumentError, "The :host parameter is required" unless args.has_key?(:host)
|
38
40
|
raise ArgumentError, "The :port parameter is required" unless args.has_key?(:port)
|
39
41
|
raise ArgumentError, "The port value is not valid" unless valid_port?( args[:port])
|
42
|
+
|
43
|
+
@origin = ""
|
44
|
+
@origin = args[:allowed_origin] if args.has_key?(:allowed_origin)
|
45
|
+
|
40
46
|
@max_connections = args[:max_connections].to_s.to_i
|
41
47
|
@max_connections = 100 if @max_connections <= 1
|
42
48
|
@host = args[:host]
|
@@ -114,6 +120,13 @@ end
|
|
114
120
|
EM::WebSocket.run(@server_options) do |ws|
|
115
121
|
ws.onopen { |handshake|
|
116
122
|
begin
|
123
|
+
unless @origin.empty?
|
124
|
+
if @origin != handshake.origin
|
125
|
+
ws.close
|
126
|
+
break
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
117
130
|
response = nil
|
118
131
|
if (@connected_users.count + 1) > @max_connections
|
119
132
|
response = create_response_json("failed_connection", nil, "The max connections limit is reached.")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web_socket_chat_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jone Samra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-websocket
|