aboutsummaryrefslogtreecommitdiff
path: root/webclient/client.html
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-06-28 22:46:50 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-06-28 22:47:19 +0200
commitba849f06d5c287e6d04e5cc91fe96c0a54df3199 (patch)
tree75efa7ad5f9f1149257277aa1b42a5f425959613 /webclient/client.html
parentb85c1a60bf7f27e37fe2a86b26aa83ff198e208e (diff)
webclient: Protocol version negotiation
Diffstat (limited to 'webclient/client.html')
-rw-r--r--webclient/client.html19
1 files changed, 17 insertions, 2 deletions
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 {