@polytric/openws-sdkgen 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -133,13 +133,13 @@ export class <%= ctx.className %> {
|
|
|
133
133
|
<% } -%>
|
|
134
134
|
<% for (const remoteRole of ctx.remoteRoles) { -%>
|
|
135
135
|
this.binder.fromRoles[<%- JSON.stringify(remoteRole.roleName) %>].onOpen(async (fromRole, peer) => {
|
|
136
|
-
await this.handleOpen(fromRole, peer as <%= ctx.className %>Peer)
|
|
136
|
+
await this.handleOpen(fromRole, peer as unknown as <%= ctx.className %>Peer)
|
|
137
137
|
})
|
|
138
138
|
this.binder.fromRoles[<%- JSON.stringify(remoteRole.roleName) %>].onClose(async (fromRole, peer) => {
|
|
139
|
-
await this.handleClose(fromRole, peer as <%= ctx.className %>Peer)
|
|
139
|
+
await this.handleClose(fromRole, peer as unknown as <%= ctx.className %>Peer)
|
|
140
140
|
})
|
|
141
141
|
this.binder.fromRoles[<%- JSON.stringify(remoteRole.roleName) %>].onError(async (fromRole, peer, error) => {
|
|
142
|
-
await this.handleError(fromRole, peer as <%= ctx.className %>Peer, error)
|
|
142
|
+
await this.handleError(fromRole, peer as unknown as <%= ctx.className %>Peer, error)
|
|
143
143
|
})
|
|
144
144
|
<% } -%>
|
|
145
145
|
if (canBindTransport(transport)) {
|
|
@@ -159,13 +159,21 @@ export class <%= ctx.className %> {
|
|
|
159
159
|
case <%- JSON.stringify(remoteRole.roleName) %>: {
|
|
160
160
|
const remoteEndpoint = endpoint ?? (<%- remoteRole.endpoints.length > 0 ? JSON.stringify(remoteRole.endpoints[0]) : 'undefined' %> as OpenWsEndpoint | undefined)
|
|
161
161
|
await this.transport.connect?.(roleName, remoteEndpoint)
|
|
162
|
-
|
|
162
|
+
let connection: <%= ctx.className %>Connection | undefined
|
|
163
|
+
const session = this.runtime.newSession(this.sendEnvelope, async () => {
|
|
164
|
+
if (!connection) {
|
|
165
|
+
await session.close()
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
await this.closeConnection(connection)
|
|
169
|
+
})
|
|
163
170
|
const <%= remoteRole.varName %>Peer = await session.open(<%- JSON.stringify(remoteRole.roleName) %>)
|
|
164
|
-
|
|
171
|
+
connection = {
|
|
165
172
|
roleName: <%- JSON.stringify(remoteRole.roleName) %>,
|
|
166
173
|
session,
|
|
167
174
|
peer: <%= remoteRole.varName %>Peer,
|
|
168
|
-
}
|
|
175
|
+
}
|
|
176
|
+
this.connections.add(connection)
|
|
169
177
|
this.<%= remoteRole.peerVarName %> = <%= remoteRole.varName %>Peer as unknown as <%= remoteRole.scopedPeerName %>
|
|
170
178
|
<% for (const handler of ctx.handlers) { -%>
|
|
171
179
|
<% const handlerDefaultPeer = handler.bindFromRoles.find(fromRole => ctx.remoteRoles.some(remoteRole => remoteRole.roleName === fromRole.roleName)) ?? ctx.remoteRoles[0] -%>
|
|
@@ -198,11 +206,11 @@ export class <%= ctx.className %> {
|
|
|
198
206
|
await this.closeSessions(peer)
|
|
199
207
|
return
|
|
200
208
|
}
|
|
201
|
-
const connection = this.findConnectionByPeer(peer as PeerProto)
|
|
209
|
+
const connection = this.findConnectionByPeer(peer as unknown as PeerProto)
|
|
202
210
|
if (!connection) {
|
|
203
211
|
throw new Error('Peer is not connected')
|
|
204
212
|
}
|
|
205
|
-
await this.
|
|
213
|
+
await this.runtime.disconnect(connection.peer)
|
|
206
214
|
}
|
|
207
215
|
|
|
208
216
|
/**
|
|
@@ -518,13 +526,21 @@ export class <%= ctx.className %> {
|
|
|
518
526
|
case <%- JSON.stringify(remoteRole.roleName) %>: {
|
|
519
527
|
const remoteEndpoint = endpoint ?? <%- remoteRole.endpoints.length > 0 ? JSON.stringify(remoteRole.endpoints[0]) : 'undefined' %>
|
|
520
528
|
await this.transport.connect?.(roleName, remoteEndpoint)
|
|
521
|
-
|
|
529
|
+
let connection
|
|
530
|
+
const session = this.runtime.newSession(this.sendEnvelope, async () => {
|
|
531
|
+
if (!connection) {
|
|
532
|
+
await session.close()
|
|
533
|
+
return
|
|
534
|
+
}
|
|
535
|
+
await this.#closeConnection(connection)
|
|
536
|
+
})
|
|
522
537
|
this.<%= remoteRole.peerVarName %> = await session.open(<%- JSON.stringify(remoteRole.roleName) %>)
|
|
523
|
-
|
|
538
|
+
connection = {
|
|
524
539
|
roleName: <%- JSON.stringify(remoteRole.roleName) %>,
|
|
525
540
|
session,
|
|
526
541
|
peer: this.<%= remoteRole.peerVarName %>,
|
|
527
|
-
}
|
|
542
|
+
}
|
|
543
|
+
this.#connections.add(connection)
|
|
528
544
|
<% for (const handler of ctx.handlers) { -%>
|
|
529
545
|
<% const handlerDefaultPeer = handler.bindFromRoles.find(fromRole => ctx.remoteRoles.some(remoteRole => remoteRole.roleName === fromRole.roleName)) ?? ctx.remoteRoles[0] -%>
|
|
530
546
|
<% if (handlerDefaultPeer?.roleName === remoteRole.roleName) { -%>
|
|
@@ -556,7 +572,7 @@ export class <%= ctx.className %> {
|
|
|
556
572
|
if (!connection) {
|
|
557
573
|
throw new Error('Peer is not connected')
|
|
558
574
|
}
|
|
559
|
-
await this
|
|
575
|
+
await this.runtime.disconnect(connection.peer)
|
|
560
576
|
}
|
|
561
577
|
|
|
562
578
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polytric/openws-sdkgen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "OpenWS SDK generator CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"tsx": "^4.21.0",
|
|
51
51
|
"typescript": "^5.9.3",
|
|
52
52
|
"ws": "^8.18.3",
|
|
53
|
-
"@polytric/openws": "^0.0.
|
|
53
|
+
"@polytric/openws": "^0.0.11"
|
|
54
54
|
},
|
|
55
55
|
"scripts": {
|
|
56
56
|
"build": "tsup",
|