Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit eefa940

Browse files
authored
Move authentication info from query string to socket.io message. (#419)
1 parent e2d2d39 commit eefa940

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/samples/p2p/js/sc.websocket.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,7 @@ function SignalingChannel() {
4848

4949
this.connect = function(loginInfo) {
5050
const serverAddress = loginInfo.host;
51-
const token = loginInfo.token;
52-
const parameters = [];
53-
let queryString = null;
54-
parameters.push('clientType=' + clientType);
55-
parameters.push('clientVersion=' + clientVersion);
56-
if (token) {
57-
parameters.push('token=' + encodeURIComponent(token));
58-
}
59-
if (parameters) {
60-
queryString = parameters.join('&');
61-
}
62-
console.log('Query string: ' + queryString);
6351
const opts = {
64-
'query': queryString,
6552
'reconnection': true,
6653
'reconnectionAttempts': MAX_TRIALS,
6754
'force new connection': true,
@@ -70,15 +57,21 @@ function SignalingChannel() {
7057

7158
wsServer.on('connect', function() {
7259
reconnectTimes = 0;
73-
console.info('Connected to websocket server.');
74-
});
75-
76-
wsServer.on('server-authenticated', function(data) {
77-
console.log('Authentication passed. User ID: ' + data.uid);
78-
if (connectPromise) {
79-
connectPromise.resolve(data.uid);
80-
}
81-
connectPromise = null;
60+
wsServer.emit('authentication', {token: loginInfo.token}, (data) => {
61+
if (data.uid) {
62+
console.log('Authentication passed. User ID: ' + data.uid);
63+
} else {
64+
console.error('Faild to connect to Socket.IO server.');
65+
}
66+
if (connectPromise) {
67+
if (data.uid) {
68+
connectPromise.resolve(data.uid);
69+
} else if (data.error) {
70+
connectPromise.reject(data.error);
71+
}
72+
}
73+
connectPromise = null;
74+
});
8275
});
8376

8477
wsServer.on('reconnecting', function() {

0 commit comments

Comments
 (0)