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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user