Skip to content

Commit ad645a5

Browse files
Peter Wilhelmsson2hdddg
authored andcommitted
Send hello message including routing
1 parent f2a74f7 commit ad645a5

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/internal/bolt-protocol-v4x1.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,39 @@
1818
*/
1919
import BoltProtocolV4 from './bolt-protocol-v4x0'
2020
import RequestMessage, { ALL } from './request-message'
21-
import { ResultStreamObserver } from './stream-observers'
2221
import { BOLT_PROTOCOL_V4_1 } from './constants'
22+
import { LoginObserver } from './stream-observers'
2323

2424
export default class BoltProtocol extends BoltProtocolV4 {
25+
/**
26+
* @constructor
27+
* @param {Connection} connection the connection.
28+
* @param {Chunker} chunker the chunker.
29+
* @param {boolean} disableLosslessIntegers if this connection should convert all received integers to native JS numbers.
30+
* @param {Object} serversideRouting
31+
*/
32+
constructor (connection, chunker, disableLosslessIntegers, serversideRouting) {
33+
super(connection, chunker, disableLosslessIntegers)
34+
this._serversideRouting = serversideRouting
35+
}
36+
2537
get version () {
2638
return BOLT_PROTOCOL_V4_1
2739
}
40+
41+
initialize ({ userAgent, authToken, onError, onComplete } = {}) {
42+
const observer = new LoginObserver({
43+
connection: this._connection,
44+
afterError: onError,
45+
afterComplete: onComplete
46+
})
47+
48+
this._connection.write(
49+
RequestMessage.hello(userAgent, authToken, this._serversideRouting),
50+
observer,
51+
true
52+
)
53+
54+
return observer
55+
}
2856
}

src/internal/request-message.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ export default class RequestMessage {
100100
* Create a new HELLO message.
101101
* @param {string} userAgent the user agent.
102102
* @param {Object} authToken the authentication token.
103+
* @param {Object} optional server side routing, set to routing context to turn on server side routing (> 4.1)
103104
* @return {RequestMessage} new HELLO message.
104105
*/
105-
static hello (userAgent, authToken) {
106+
static hello (userAgent, authToken, routing = null) {
106107
const metadata = Object.assign({ user_agent: userAgent }, authToken)
108+
if (routing != null) {
109+
metadata.routing = routing
110+
}
107111
return new RequestMessage(
108112
HELLO,
109113
[metadata],

0 commit comments

Comments
 (0)