Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Derive the URI from windows.location

  • Loading branch information...
commit 159533c5cdee5aa81c0746305b7c3c666345f7c1 1 parent e1b22a8
Peter R. G. Small authored
Showing with 25 additions and 8 deletions.
  1. +25 −8 lib/acequiaClient.js
33 lib/acequiaClient.js
View
@@ -12,16 +12,13 @@ var objCallback = function (obj, func) {
};
};
-// TODO: do not require the uri. Derive it from the include path, some how...
-// Write it through the http request on the acequia server, in genclient...
-
/**
* Defines the AcequiaClient object, which is used to connect with the Acequia server
* through a WebSocket connection.
+ * @param {String} clientName The name used to uniquely identify this client.
* @param {String} uri The uri of the connection to the WebSocket.
- * @param {String} userName The user name, used to uniquely identify this user.
*/
-var AcequiaClient = function (uri, userName) {
+var AcequiaClient = function (clientName, uri) {
var m_connected = false,
m_connectionChangeHandlers = [];
@@ -41,14 +38,34 @@ var AcequiaClient = function (uri, userName) {
}
};
- this.uri = uri;
- this.userName = userName;
+ this.uri = (typeof(uri) === "undefined") ? this.getURI() : uri;
+ this.clientName = clientName;
this.socket = null;
this.listeners = {};
this.subscribes = [];
};
+/**
+ * Gets the URI for the Acequia client from window.location using the default
+ * Acequia port.
+ * @returns {String} the URI
+ */
+AcequiaClient.prototype.getURI = function () {
+ var pos, ret = window.location.server ? window.location.server :
+ window.location.href.substring(0, window.location.href.lastIndexOf("/"));
+
+ pos = ret.lastIndexOf(":");
+
+ if (pos > 4) {
+ ret = ret.substring(0, pos);
+ }
+
+ ret += ":9091";
+
+ return ret;
+};
+
AcequiaClient.prototype.getSocketIOJS = function (onload) {
if (typeof(io) === "undefined") {
var fileref = document.createElement('script');
@@ -134,7 +151,7 @@ AcequiaClient.prototype.send = function (msgName, body) {
if (msgName !== msg.MSG_CONNECT && !this.isConnected()) {
console.error("AcequiaClient.send " + msgName + ": client is not connected");
} else {
- var message = new msg.AcequiaMessage(this.userName, msgName, body);
+ var message = new msg.AcequiaMessage(this.clientName, msgName, body);
this.socket.send(message.toString());
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.