@@ -4,6 +4,7 @@ var logger = require('./logger');
4
4
var ACTIONS = require ( './message-actions' ) . ACTIONS ;
5
5
var types = require ( './types' ) ;
6
6
var util = require ( './util' ) ;
7
+ var protocol = require ( './protocol' ) ;
7
8
8
9
var ERROR_CODE = ShareDBError . CODES ;
9
10
@@ -62,6 +63,8 @@ function Agent(backend, stream) {
62
63
// active, and it is passed to each middleware call
63
64
this . custom = Object . create ( null ) ;
64
65
66
+ this . protocol = Object . create ( null ) ;
67
+
65
68
// The first message received over the connection. Stored to warn if messages
66
69
// are being sent before the handshake.
67
70
this . _firstReceivedMessage = null ;
@@ -437,6 +440,7 @@ Agent.prototype._handleMessage = function(request, callback) {
437
440
switch ( request . a ) {
438
441
case ACTIONS . handshake :
439
442
if ( request . id ) this . src = request . id ;
443
+ this . _setProtocol ( request ) ;
440
444
return callback ( null , this . _initMessage ( ACTIONS . handshake ) ) ;
441
445
case ACTIONS . queryFetch :
442
446
return this . _queryFetch ( request . id , request . c , request . q , getQueryOptions ( request ) , callback ) ;
@@ -788,8 +792,8 @@ Agent.prototype._fetchSnapshotByTimestamp = function(collection, id, timestamp,
788
792
Agent . prototype . _initMessage = function ( action ) {
789
793
return {
790
794
a : action ,
791
- protocol : 1 ,
792
- protocolMinor : 1 ,
795
+ protocol : protocol . major ,
796
+ protocolMinor : protocol . minor ,
793
797
id : this . _src ( ) ,
794
798
type : types . defaultType . uri
795
799
} ;
@@ -973,6 +977,11 @@ Agent.prototype._checkFirstMessage = function(request) {
973
977
}
974
978
} ;
975
979
980
+ Agent . prototype . _setProtocol = function ( request ) {
981
+ this . protocol . major = request . protocol ;
982
+ this . protocol . minor = request . protocolMinor ;
983
+ } ;
984
+
976
985
function createClientOp ( request , clientId ) {
977
986
// src can be provided if it is not the same as the current agent,
978
987
// such as a resubmission after a reconnect, but it usually isn't needed
0 commit comments