diff options
-rw-r--r-- | views/client.html | 22 | ||||
-rw-r--r-- | webcastor.js | 27 |
2 files changed, 38 insertions, 11 deletions
diff --git a/views/client.html b/views/client.html index c322042..ebb3810 100644 --- a/views/client.html +++ b/views/client.html | |||
@@ -5,6 +5,8 @@ | |||
5 | <input type="text" id="channelField"> | 5 | <input type="text" id="channelField"> |
6 | <label for="passwordField">Password (optional)</label> | 6 | <label for="passwordField">Password (optional)</label> |
7 | <input type="password" id="passwordField"> | 7 | <input type="password" id="passwordField"> |
8 | <input type="checkbox" id="usePassword"> | ||
9 | <label for="usePassword">Use password</label> | ||
8 | <input type="submit" value="Connect" id="connectButton"> | 10 | <input type="submit" value="Connect" id="connectButton"> |
9 | </form> | 11 | </form> |
10 | <br> | 12 | <br> |
@@ -43,9 +45,9 @@ | |||
43 | var socket; | 45 | var socket; |
44 | var socketConnected = false; | 46 | var socketConnected = false; |
45 | 47 | ||
46 | function connectSocket(channel, password) { | 48 | function connectSocket(channel, password, authenticate) { |
47 | socket = io.connect("/", { | 49 | socket = io.connect("/", { |
48 | "query" : "channel=" + channel + "&password=" + password, | 50 | "query" : "channel=" + channel + ( authenticate ? "&password=" + password : ""), |
49 | "force new connection" : true | 51 | "force new connection" : true |
50 | }); | 52 | }); |
51 | 53 | ||
@@ -59,6 +61,20 @@ | |||
59 | println("disconnected"); | 61 | println("disconnected"); |
60 | }); | 62 | }); |
61 | 63 | ||
64 | socket.on("unknown_channel", function() { | ||
65 | changeControlState(false); | ||
66 | println("unknown_channel"); | ||
67 | }); | ||
68 | |||
69 | socket.on("authentication_error", function() { | ||
70 | changeControlState(false); | ||
71 | println("authentication_error"); | ||
72 | }); | ||
73 | |||
74 | socket.on("authenticated", function() { | ||
75 | println("authenticated"); | ||
76 | }); | ||
77 | |||
62 | socket.on("message", function(message) { | 78 | socket.on("message", function(message) { |
63 | println(message); | 79 | println(message); |
64 | }); | 80 | }); |
@@ -70,7 +86,7 @@ | |||
70 | if (socketConnected) { | 86 | if (socketConnected) { |
71 | socket.disconnect(); | 87 | socket.disconnect(); |
72 | } else { | 88 | } else { |
73 | connectSocket(channelField.value, passwordField.value); | 89 | connectSocket(channelField.value, passwordField.value, usePassword.checked); |
74 | } | 90 | } |
75 | }); | 91 | }); |
76 | 92 | ||
diff --git a/webcastor.js b/webcastor.js index 39c37a9..d1828fc 100644 --- a/webcastor.js +++ b/webcastor.js | |||
@@ -173,22 +173,33 @@ var Server = { | |||
173 | Channel.getPassword(channel, function(hashedPassword) { | 173 | Channel.getPassword(channel, function(hashedPassword) { |
174 | 174 | ||
175 | if (hashedPassword === null) { | 175 | if (hashedPassword === null) { |
176 | console.log('Client joined an unknown channel'); | 176 | console.log('Client tried to join an unknown channel'); |
177 | socket.emit('unknown_channel'); | ||
177 | return; | 178 | return; |
178 | } | 179 | } |
179 | 180 | ||
180 | socket.join(channel); | 181 | socket.join(channel); |
181 | 182 | ||
182 | if (!imports.passwordHash.verify(password, hashedPassword) && hashedPassword !== 'none') { | 183 | if (password === undefined) { |
184 | |||
183 | console.log('Client joined ' + channel); | 185 | console.log('Client joined ' + channel); |
184 | return; | ||
185 | } | ||
186 | 186 | ||
187 | console.log('Broadcaster joined ' + channel); | 187 | } else { |
188 | |||
189 | if (hashedPassword === 'none' || imports.passwordHash.verify(password, hashedPassword)) { | ||
190 | console.log('Broadcaster joined ' + channel); | ||
191 | socket.emit("authenticated"); | ||
192 | |||
193 | socket.on('message', function(event) { | ||
194 | Server.broadcast(socket, channel, event); | ||
195 | }); | ||
196 | } else { | ||
197 | console.log('Authentication error on channel ' + channel); | ||
198 | socket.emit('authentication_error'); | ||
199 | } | ||
200 | |||
201 | } | ||
188 | 202 | ||
189 | socket.on('message', function(event) { | ||
190 | Server.broadcast(socket, channel, event); | ||
191 | }); | ||
192 | }); | 203 | }); |
193 | }, | 204 | }, |
194 | 205 | ||