diff --git a/index.html b/index.html index 1457c66d..28944e6e 100644 --- a/index.html +++ b/index.html @@ -26,9 +26,10 @@ // Name of this application, used in the User-Agent var APP_NAME = "TinodeReact/0.10"; - // Host name and port to connect to - var HOST = "api.tinode.co"; - // var HOST = "localhost:6060"; + var KNOWN_HOSTS = {hosted: "api.tinode.co", local: "localhost:6060"}; + // Default host name and port to connect to. + var DEFAULT_HOST = KNOWN_HOSTS.hosted; + // var DEFAULT_HOST = KNOWN_HOSTS.local; // API key. Use https://github.com/tinode/chat/tree/master/keygen to generate your own var API_KEY = "AQEAAAABAAD_rAp4DJh05a1HAwFT3A6K"; @@ -69,6 +70,17 @@ 'data:image/' + photo.type + ';base64,' + photo.data : null; } + // Detect server address from the URL + function detectServerAddress() { + var host = DEFAULT_HOST; + if (window.location.protocol === 'file:' || window.location.hostname === 'localhost') { + host = KNOWN_HOSTS.local; + } else if (window.location.hostname) { + host = window.location.hostname + (window.location.port ? ':' + window.location.port : ''); + } + return host; + } + /* BEGIN Popup/dropdown menu */ var ContextMenu = React.createClass({ componentWillUnmount: function() { @@ -189,12 +201,45 @@ }; /* END Popup/dropdown menu */ + /* BEGIN Combobox for selecting host name */ + var HostSelector = React.createClass({ + getInitialState: function() { + return { + hostName: this.props.serverAddress + }; + }, + handleHostNameChange: function(e) { + this.setState({hostName: e.target.value}); + this.props.onServerAddressChange(e.target.value.trim()); + }, + render: function() { + var hostOptions = []; + for (var key in KNOWN_HOSTS) { + var item = KNOWN_HOSTS[key]; + hostOptions.push( +