[Development] QtWebChannel internal protocol

Lutz Schönemann lutz.schoenemann at basyskom.com
Fri Jul 4 15:12:31 CEST 2014


Hey,

I've looked into the internal protocol that is used by QWebChannel and I 
think the usage of some properties is is a bit inconsistent.
In every message the client sends to the server it has to set the 
following properties (minimum):
{
   data: {
     type: 6 // an integer specifying the message type (read / write 
property; call method; ...)
   }
}

As far as I understood that protocol the 'data' property holds the 
message payload and 'data.type' property holds the type of the message.
There are also some more properties but the property that is confusing 
me the most is 'id'. If client sends a message to call a method it also 
has to contain that property:
{
   id: "id is of any type (number/string/array/object) and identifies 
the message itself",
   data: {
     type: 6
     // additional properties needed for calling a method
   }
}

The ID property is used by the server just to send put it as 'id' in the 
response:
{
   id: "id is of any type (number/string/array/object) and identifies 
the message itself",
   response: true,
   data: {
     // data returned by method
   }
}

Now, if the server sends any message to the client (property update / 
signal / ...) it uses the 'id' property not to identify the message but 
to set the message type. Here an example of a message that could be the 
result of a signal:
{
   id: 1,
   data: {
     "object": "myObject",
     "signal": "mySignal",
     "args": [ "arguments", "sent", "by", "signal" ]
   }
}
That makes processing messages from server more complex because the the 
client has to handle the 'id' property in different ways regarding if it 
is a response or not.

So is there a reason why you are not using the 'data.type' property in 
every case to set the message type? Maybe it should be moved from 
'data.type' to 'type' then because for method calls it would be bad to 
change the returned data.


Regards,
Lutz




More information about the Development mailing list