Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 113 additions & 69 deletions app/stores/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,41 @@ import { useInfraStore } from "@ogw_front/stores/infra"

const request_timeout = 10 * 1000

export const useViewerStore = defineStore("viewer", {
state: () => ({
default_local_port: "1234",
client: {},
config: null,
picking_mode: false,
picked_point: { x: null, y: null },
request_counter: 0,
status: Status.NOT_CONNECTED,
}),
getters: {
protocol() {
export const useViewerStore = defineStore(
"viewer",
() => {
const infraStore = useInfraStore()

const default_local_port = ref("1234")
const client = ref({})
const config = ref(null)
const picking_mode = ref(false)
const picked_point = ref({ x: null, y: null })
const request_counter = ref(0)
const status = ref(Status.NOT_CONNECTED)
const buzy = ref(0)

const protocol = computed(() => {
if (useInfraStore().app_mode == appMode.CLOUD) {
return "wss"
} else {
return "ws"
}
},
port() {
})

const port = computed(() => {
if (useInfraStore().app_mode == appMode.CLOUD) {
return "443"
}
const VIEWER_PORT = useRuntimeConfig().public.VIEWER_PORT
if (VIEWER_PORT != null && VIEWER_PORT !== "") {
return VIEWER_PORT
}
return this.default_local_port
},
base_url() {
const infraStore = useInfraStore()
let viewer_url = `${this.protocol}://${infraStore.domain_name}:${this.port}`
return default_local_port.value
})

const base_url = computed(() => {
let viewer_url = `${protocol.value}://${infraStore.domain_name}:${port.value}`
if (infraStore.app_mode == appMode.CLOUD) {
if (infraStore.ID == "") {
throw new Error("ID must not be empty in cloud mode")
Expand All @@ -48,47 +52,50 @@ export const useViewerStore = defineStore("viewer", {
}
viewer_url += "/ws"
return viewer_url
},
is_busy() {
return this.request_counter > 0
},
},
actions: {
toggle_picking_mode(value) {
this.picking_mode = value
},
async set_picked_point(x, y) {
const response = await this.get_point_position({ x, y })
})

const is_busy = computed(() => {
return request_counter.value > 0
})

function toggle_picking_mode(value) {
picking_mode.value = value
}

async function set_picked_point(x, y) {
const response = await get_point_position({ x, y })
const { x: world_x, y: world_y } = response
this.picked_point.x = world_x
this.picked_point.y = world_y
this.picking_mode = false
},
async ws_connect() {
if (this.status === Status.CONNECTED) return
picked_point.value.x = world_x
picked_point.value.y = world_y
picking_mode.value = false
}

async function ws_connect() {
if (status.value === Status.CONNECTED) return

return navigator.locks.request("viewer.ws_connect", async (lock) => {
if (this.status === Status.CONNECTED) return
if (status.value === Status.CONNECTED) return
try {
console.log("VIEWER LOCK GRANTED !", lock)
this.status = Status.CONNECTING
status.value = Status.CONNECTING
const SmartConnect = await import("wslink/src/SmartConnect")
vtkWSLinkClient.setSmartConnectClass(SmartConnect)

const config = { application: "Viewer" }
config.sessionURL = this.base_url
const config_obj = { application: "Viewer" }
config_obj.sessionURL = base_url.value

if (this.status === Status.CONNECTED && this.client.isConnected()) {
this.client.disconnect(-1)
this.status = Status.NOT_CONNECTED
if (status.value === Status.CONNECTED && client.value.isConnected()) {
client.value.disconnect(-1)
status.value = Status.NOT_CONNECTED
}
let clientToConnect = this.client
let clientToConnect = client.value
if (_.isEmpty(clientToConnect)) {
clientToConnect = vtkWSLinkClient.newInstance()
}

// Connect to busy store
clientToConnect.onBusyChange((count) => {
this.buzy = count
buzy.value = count
})
clientToConnect.beginBusy()

Expand All @@ -111,45 +118,58 @@ export const useViewerStore = defineStore("viewer", {
// Connect
const { connectImageStream } =
await import("@kitware/vtk.js/Rendering/Misc/RemoteView")
this.client = await clientToConnect.connect(config)
connectImageStream(this.client.getConnection().getSession())
this.client.endBusy()
await this.request(
client.value = await clientToConnect.connect(config_obj)
connectImageStream(client.value.getConnection().getSession())
client.value.endBusy()
await request(
schemas.opengeodeweb_viewer.viewer.reset_visualization,
{},
{},
undefined,
)
this.status = Status.CONNECTED
status.value = Status.CONNECTED
} catch (error) {
console.error("error", error)
this.status = Status.NOT_CONNECTED
status.value = Status.NOT_CONNECTED
throw error
}
})
},
start_request() {
this.request_counter++
},
stop_request() {
this.request_counter--
},
async launch() {
}

function start_request() {
request_counter.value++
}

function stop_request() {
request_counter.value--
}

async function launch() {
console.log("[VIEWER] Launching viewer microservice...")
const port = await window.electronAPI.run_viewer()
console.log("[VIEWER] Viewer launched on port:", port)
return port
},
async connect() {
}

async function connect() {
console.log("[VIEWER] Connecting to viewer microservice...")
await this.ws_connect()
await ws_connect()
console.log("[VIEWER] Viewer connected successfully")
},
request(schema, params = {}, callbacks = {}, timeout = request_timeout) {
}

function request(
schema,
params = {},
callbacks = {},
timeout = request_timeout,
) {
console.log("[VIEWER] Request:", schema.$id)

// Get current store instance to pass to viewer_call
const store = useViewerStore()

return viewer_call(
this,
store,
{ schema, params },
{
...callbacks,
Expand All @@ -162,9 +182,33 @@ export const useViewerStore = defineStore("viewer", {
},
timeout,
)
},
}

return {
default_local_port,
client,
config,
picking_mode,
picked_point,
request_counter,
status,
protocol,
port,
base_url,
is_busy,
toggle_picking_mode,
set_picked_point,
ws_connect,
start_request,
stop_request,
launch,
connect,
request,
}
},
share: {
omit: ["status", "client"],
{
share: {
omit: ["status", "client"],
},
},
})
)
1 change: 0 additions & 1 deletion tests/integration/microservices/back/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
# pip-compile --output-file=tests/integration/microservices/back/requirements.txt tests/integration/microservices/back/requirements.in
#

opengeodeweb-back==6.*,>=6.1.0rc3
1 change: 0 additions & 1 deletion tests/integration/microservices/viewer/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
# pip-compile --output-file=tests/integration/microservices/viewer/requirements.txt tests/integration/microservices/viewer/requirements.in
#

opengeodeweb-viewer==1.*,>=1.15.1rc1
Loading