Version the protocol.

The handshake message now contains a list of supported protocol
versions.  Version mismatch is currently a warning, but it will be a
hard error in the future.
This commit is contained in:
Juliusz Chroboczek
2022-09-02 14:30:51 +02:00
parent b55e531aa5
commit 533e4b9b32
4 changed files with 49 additions and 16 deletions
+4
View File
@@ -223,6 +223,7 @@ function ServerConnection() {
/**
* @typedef {Object} message
* @property {string} type
* @property {Array<string>} [version]
* @property {string} [kind]
* @property {string} [id]
* @property {string} [replace]
@@ -289,6 +290,7 @@ ServerConnection.prototype.connect = async function(url) {
this.socket.onopen = function(e) {
sc.send({
type: 'handshake',
version: ["1"],
id: sc.id,
});
if(sc.onconnected)
@@ -322,6 +324,8 @@ ServerConnection.prototype.connect = async function(url) {
let m = JSON.parse(e.data);
switch(m.type) {
case 'handshake':
if(!m.version || !m.version.includes('1'))
console.warn(`Unexpected protocol version ${m.version}.`);
break;
case 'offer':
sc.gotOffer(m.id, m.label, m.source, m.username,