|
1 | 1 | import _ from "lodash" |
2 | 2 | import vtkWSLinkClient from "@kitware/vtk.js/IO/Core/WSLinkClient" |
3 | | -import SmartConnect from "wslink/src/SmartConnect" |
4 | 3 | import "@kitware/vtk.js/Rendering/OpenGL/Profiles/Geometry" |
5 | 4 | import { connectImageStream } from "@kitware/vtk.js/Rendering/Misc/RemoteView" |
6 | 5 | import schemas from "@geode/opengeodeweb-viewer/schemas.json" |
7 | 6 |
|
8 | | -vtkWSLinkClient.setSmartConnectClass(SmartConnect) |
9 | | - |
10 | 7 | export const use_viewer_store = defineStore("viewer", { |
11 | 8 | state: () => ({ |
12 | 9 | client: {}, |
@@ -42,64 +39,71 @@ export const use_viewer_store = defineStore("viewer", { |
42 | 39 | this.picked_point.y = world_y |
43 | 40 | this.picking_mode = false |
44 | 41 | }, |
45 | | - ws_connect() { |
46 | | - if (process.env.NODE_ENV != "test") { |
47 | | - const config = { application: "Viewer" } |
48 | | - config.sessionURL = this.base_url |
| 42 | + async ws_connect() { |
| 43 | + if (process.env.NODE_ENV == "test") { |
| 44 | + return |
| 45 | + } |
| 46 | + const SmartConnect = await import("wslink/src/SmartConnect") |
| 47 | + vtkWSLinkClient.setSmartConnectClass(SmartConnect) |
49 | 48 |
|
50 | | - const { client } = this |
51 | | - if (this.is_running && client.isConnected()) { |
52 | | - client.disconnect(-1) |
53 | | - this.is_running = false |
54 | | - } |
55 | | - let clientToConnect = client |
56 | | - if (_.isEmpty(clientToConnect)) { |
57 | | - clientToConnect = vtkWSLinkClient.newInstance() |
58 | | - } |
| 49 | + const config = { application: "Viewer" } |
| 50 | + config.sessionURL = this.base_url |
59 | 51 |
|
60 | | - // Connect to busy store |
61 | | - clientToConnect.onBusyChange((count) => { |
62 | | - this.buzy = count |
63 | | - }) |
64 | | - clientToConnect.beginBusy() |
| 52 | + const { client } = this |
| 53 | + if (this.is_running && client.isConnected()) { |
| 54 | + client.disconnect(-1) |
| 55 | + this.is_running = false |
| 56 | + } |
| 57 | + let clientToConnect = client |
| 58 | + if (_.isEmpty(clientToConnect)) { |
| 59 | + clientToConnect = vtkWSLinkClient.newInstance() |
| 60 | + } |
65 | 61 |
|
66 | | - // Error |
67 | | - clientToConnect.onConnectionError((httpReq) => { |
68 | | - const message = |
69 | | - (httpReq && httpReq.response && httpReq.response.error) || |
70 | | - `Connection error` |
71 | | - console.error(message) |
72 | | - }) |
| 62 | + // Connect to busy store |
| 63 | + clientToConnect.onBusyChange((count) => { |
| 64 | + this.buzy = count |
| 65 | + }) |
| 66 | + clientToConnect.beginBusy() |
73 | 67 |
|
74 | | - // Close |
75 | | - clientToConnect.onConnectionClose((httpReq) => { |
76 | | - const message = |
77 | | - (httpReq && httpReq.response && httpReq.response.error) || |
78 | | - `Connection close` |
79 | | - console.error(message) |
80 | | - }) |
| 68 | + // Error |
| 69 | + clientToConnect.onConnectionError((httpReq) => { |
| 70 | + const message = |
| 71 | + (httpReq && httpReq.response && httpReq.response.error) || |
| 72 | + `Connection error` |
| 73 | + console.error(message) |
| 74 | + }) |
| 75 | + |
| 76 | + // Close |
| 77 | + clientToConnect.onConnectionClose((httpReq) => { |
| 78 | + const message = |
| 79 | + (httpReq && httpReq.response && httpReq.response.error) || |
| 80 | + `Connection close` |
| 81 | + console.error(message) |
| 82 | + }) |
81 | 83 |
|
82 | | - // Connect |
83 | | - clientToConnect |
84 | | - .connect(config) |
85 | | - .then((validClient) => { |
86 | | - connectImageStream(validClient.getConnection().getSession()) |
87 | | - this.client = validClient |
88 | | - clientToConnect.endBusy() |
| 84 | + // Connect |
| 85 | + const { connectImageStream } = await import( |
| 86 | + "@kitware/vtk.js/Rendering/Misc/RemoteView" |
| 87 | + ) |
| 88 | + clientToConnect |
| 89 | + .connect(config) |
| 90 | + .then((validClient) => { |
| 91 | + connectImageStream(validClient.getConnection().getSession()) |
| 92 | + this.client = validClient |
| 93 | + clientToConnect.endBusy() |
89 | 94 |
|
90 | | - // Now that the client is ready let's setup the server for us |
91 | | - viewer_call({ |
92 | | - schema: schemas.opengeodeweb_viewer.create_visualization, |
93 | | - }) |
94 | | - viewer_call({ |
95 | | - schema: schemas.opengeodeweb_viewer.reset, |
96 | | - }) |
97 | | - this.is_running = true |
| 95 | + // Now that the client is ready let's setup the server for us |
| 96 | + viewer_call({ |
| 97 | + schema: schemas.opengeodeweb_viewer.create_visualization, |
98 | 98 | }) |
99 | | - .catch((error) => { |
100 | | - console.error(error) |
| 99 | + viewer_call({ |
| 100 | + schema: schemas.opengeodeweb_viewer.reset, |
101 | 101 | }) |
102 | | - } |
| 102 | + this.is_running = true |
| 103 | + }) |
| 104 | + .catch((error) => { |
| 105 | + console.error(error) |
| 106 | + }) |
103 | 107 | }, |
104 | 108 | start_request() { |
105 | 109 | this.request_counter++ |
|
0 commit comments