Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Can't load phoenix.js library - Cannot read property 'WebSocket' of undefined
Forum Updated to NodeBB v4.3 + New Features

Can't load phoenix.js library - Cannot read property 'WebSocket' of undefined

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 195 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kobid
    wrote on 1 Jul 2024, 19:47 last edited by Kobid 7 Jan 2024, 19:49
    #1

    Hi,
    My friend have phoenix server to which one I want to connect as client.
    He gave me simple example:
    source: https://github.com/phoenixframework/phoenix/blob/main/priv/static/phoenix.js

    import {Socket, Presence} from "phoenix"
    let socket = new Socket("ws://localhost:4000/socket", {params: {token: "test_token"}})
    

    First problem was importing module. I have syntax errors with import {Socket, Presence} from "phoenix". Finally I was able to import it with this: import "./phoenix.js" as MyScript
    Now. This:

    let socket = new Socket("ws://localhost:4000/socket", {params: {token: "test_token"}})
    

    Return: ReferenceError: Socket is not defined
    This:

    let socket = new Phoenix.Socket("ws://localhost:4000/socket", {params: {token: "test_token"}})
    

    Return: ReferenceError: Phoenix is not defined
    This:

    let socket = new MyScript.Socket("ws://localhost:4000/socket", {params: {token: "test_token"}})
    

    Return: TypeError: Type error
    And finally this:

    let socket = new MyScript.Phoenix.Socket("ws://localhost:4000/socket", {params: {token: "test_token"}})
    

    Return: TypeError: Cannot read property 'WebSocket' of undefined
    First attempts were with phoenix.js from master but same errors with downloaded from stable release like 1.7.14.
    Also. Seems that phoenix library worked fine with QML JavaScript because there is also this article:
    https://chatgpt.com/share/4aa7e9c0-5b74-4e6b-9412-c5be248c95ac
    He is using Qt.include("js/phoenix.js") which doesn't work on my Qt 6.7:
    Qt.include(): Can only be called from JavaScript files
    Probably he made it on some Qt 5.X. Qt Doc is saying that this method is deprecated and will be removed in future Qt.

    Any ideas?
    Regards

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kobid
      wrote on 2 Jul 2024, 18:49 last edited by
      #2

      I found this topic:
      https://stackoverflow.com/questions/38935558/instantiate-browser-like-websocket-in-qml-js
      Seems like Qt QML JavaScript engine has cut out websockets which is understandable since QML has its own WebSocket component. Is there any workaround?

      1 Reply Last reply
      0

      1/2

      1 Jul 2024, 19:47

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved