forked from gbezyuk/logux-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
103 lines (100 loc) · 2.66 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var BrowserConnection = require('./browser-connection')
var ServerConnection = require('./server-connection')
var ClientSync = require('./client-sync')
var ServerSync = require('./server-sync')
var LocalPair = require('./local-pair')
var SyncError = require('./sync-error')
var Reconnect = require('./reconnect')
var BaseSync = require('./base-sync')
var TestPair = require('./test-pair')
module.exports = {
BrowserConnection: BrowserConnection,
ServerConnection: ServerConnection,
ClientSync: ClientSync,
ServerSync: ServerSync,
LocalPair: LocalPair,
SyncError: SyncError,
Reconnect: Reconnect,
BaseSync: BaseSync,
TestPair: TestPair
}
/**
* Logux protocol message. It is a array with string of message type in first
* position and strings/numbers/objects or arrays in next positions.
*
* @typedef {Array} Message
* @property {string} 0 Message type
*/
/**
* Abstract interface for connection to synchronize logs over it.
* For example, WebSocket or Loopback.
*
* @name Connection
* @class
* @abstract
*/
/**
* Send message to connection.
*
* @param {Message} message The message to be sent.
*
* @return {undefined}
*
* @name send
* @function
* @memberof Connection#
*/
/**
* Subscribe for connection events. It implements nanoevents API.
* Supported events:
*
* * `connecting`: connection establishing was started.
* * `connect`: connection was established by any side.
* * `disconnect`: connection was closed by any side.
* * `message`: message was receive from remote node.
* * `error`: error during connection, sending or receiving.
*
* @param {"connecting"|"connect"|"disconnect"|"message"|"error"} event Event.
* @param {function} listener The listener function.
*
* @return {function} Unbind listener from event.
*
* @name on
* @function
* @memberof Connection#
*/
/**
* Start connection. Connection should be in disconnected state
* from the beginning and start connection only on this method call.
*
* This method could be called again if connection moved to disconnected state.
*
* @return {Promise} Promise until connection will be established.
*
* @name connect
* @function
* @memberof Connection#
*/
/**
* Finish current connection.
*
* After disconnection, connection could be started again
* by {@link Connection#connect}.
*
* @param {"error"|"timeout"|"destroy"} [reason] Disconnection reason.
* It will not be sent
* to other machine.
*
* @return {undefined}
*
* @name disconnect
* @function
* @memberof Connection#
*/
/**
* Is connection is enabled.
*
* @name connected
* @type {boolean}
* @memberof Connection#
*/