diff options
| author | Tom Smeding <tom.smeding@gmail.com> | 2020-06-28 22:46:50 +0200 | 
|---|---|---|
| committer | Tom Smeding <tom.smeding@gmail.com> | 2020-06-28 22:47:19 +0200 | 
| commit | ba849f06d5c287e6d04e5cc91fe96c0a54df3199 (patch) | |
| tree | 75efa7ad5f9f1149257277aa1b42a5f425959613 | |
| parent | b85c1a60bf7f27e37fe2a86b26aa83ff198e208e (diff) | |
webclient: Protocol version negotiation
| -rw-r--r-- | TODO.txt | 1 | ||||
| -rw-r--r-- | webclient/client.html | 19 | 
2 files changed, 17 insertions, 3 deletions
| @@ -1,5 +1,4 @@  - Store message as UTF8 text, not blob -- Protocol version negotiation  - `_push message` and the response on `send` should give the msgid, so the client can implement replies  - Message replies: referenced message should be msgid  - Somehow communicate (push? poll?) to room members whether a particular user is currently _active_, not just online. diff --git a/webclient/client.html b/webclient/client.html index 766b035..fce719d 100644 --- a/webclient/client.html +++ b/webclient/client.html @@ -4,7 +4,9 @@  <meta charset="utf-8">  <title>tomsg webclient</title>  <script> -var sock=null,username=null; +var PROTOCOL_VERSION=1; + +var sock=null,negotiated_version=false,username=null;  var roomlist=[":console"];  var currentroom=":console";  var roomlogs=new Map([[":console",[]]]); @@ -80,7 +82,7 @@ function formatTime(date){  function net_historyCollectionCallback(id,list,count,cb, item,err){  	if(err){ -		cb(err); +		cb(null,err);  	} else {  		list.push(item);  		if(list.length==count){ @@ -95,6 +97,7 @@ function reconnect(){  	if(sock)sock.close();  	net_callbacks={}; +	negotiated_version=false;  	var url;  	if(location.hostname!="")url="wss://"+location.hostname; @@ -145,6 +148,16 @@ function reconnect(){  	});  	sock.addEventListener("open",function(){  		updateStatus(); +		net_send("version "+PROTOCOL_VERSION,function(ok,err){ +			if(err){ +				var msg="Server version incompatible (we need protocol version "+ +							PROTOCOL_VERSION+"): "+err; +				addRoomEntry(":console","error",[now(),msg]); +			} else { +				negotiated_version=true; +				updateStatus(); +			} +		});  	});  	sock.addEventListener("close",function(ev){  		updateStatus(); @@ -196,6 +209,8 @@ function updateStatus(){  		str="not connected";  	} else if(sock.readyState==0){  		str="connecting..."; +	} else if(!negotiated_version){ +		str="versioning...";  	} else if(username){  		str="u: "+username;  	} else { | 
