wss with password

add support for wss://user:passwd@host:port/jsonrpc
This commit is contained in:
cmheia 2015-04-05 03:36:04 +08:00
parent c0a3a0639a
commit 53ce35102e
2 changed files with 12 additions and 1 deletions

View File

@ -37,6 +37,7 @@ function(_, JSON, name, utils, alerts) {
// when connection opens
onopen: function() {
console.log('websocket initialized!!!');
sockRPC.initialized = true;
},
@ -93,7 +94,16 @@ function(_, JSON, name, utils, alerts) {
}
try {
sockRPC.sock = new WebSocket(sockRPC.scheme + '://' + conf.host + ':' + conf.port + '/jsonrpc');
var authUrl = sockRPC.scheme + '://' + conf.host + ':' + conf.port + '/jsonrpc';
if (sockRPC.conf.auth && sockRPC.conf.auth.user && sockRPC.conf.auth.pass) {
authUrl = sockRPC.scheme + '://' +
sockRPC.conf.auth.user + ":" +
sockRPC.conf.auth.pass + "@" +
sockRPC.conf.host + ':' +
sockRPC.conf.port + '/jsonrpc';
}
sockRPC.sock = new WebSocket(authUrl);
sockRPC.sock.onopen = sockRPC.onopen;
sockRPC.sock.onclose = sockRPC.onclose;
sockRPC.sock.onerror = sockRPC.onerror;

View File

@ -34,6 +34,7 @@ function(log, jsonRPC, sockRPC, alerts) {
opts.error = opts.error || angular.noop;
if (sockRPC.initialized) {
console.log('calling sock rpc');
return sockRPC.invoke(opts);
}
else {