Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TerminalManager bug: output Terminals unavailable #16599

Closed
jack-hub-maker opened this issue Jul 18, 2024 · 5 comments
Closed

TerminalManager bug: output Terminals unavailable #16599

jack-hub-maker opened this issue Jul 18, 2024 · 5 comments
Assignees

Comments

@jack-hub-maker
Copy link

jack-hub-maker commented Jul 18, 2024

run output: Terminals unavailable;

What should I do to handle the TerminalManager connection problem? serverSettings should be correct, because I can access jupyterlab at http://localhost:8888 and I type
curl -H "Authorization: Token bdea148105459385ee20889c2c820066d345b23a1f3a80c2" http://localhost:8888/api/terminals

He will return

[{" name ":" 1 ", "last_activity" : "the 2024-07-18 T05: abide. 795755 z"}] %

I understand that this should be able to successfully access the terminal service, but my react project is not, what should I do

"@jupyterlab/services": "7.2.2",
"@jupyterlab/terminal": "4.2.2",

Here is my code snippet:

import { useEffect, useRef } from 'react'
import { Terminal as XTerminal } from 'xterm'
import { FitAddon } from 'xterm-addon-fit'
import { TerminalManager,  ServerConnection } from '@jupyterlab/services'
import 'xterm/css/xterm.css'
import styles from './style.less'
import { WebLinksAddon } from '@xterm/addon-web-links';

function Index() {
  const ref = useRef()
  // const serverSettings = ServerConnection.makeSettings();
  // console.log('serverSettings: ', serverSettings);
  useEffect(async () => {
    const term = new XTerminal({
      cursorBlink: true, 
      allowTransparency: false,
      rendererType: 'canvas', 
      convertEol: true,
      scrollback: 800, 
      row: 70,
      theme: {
        foreground: 'white',
        background: '#181E29'
      },
    })
    term.loadAddon(new WebLinksAddon());
    const fitAddon = new FitAddon()
    term.loadAddon(fitAddon)
    term.open(ref.current)
    fitAddon.fit()
    term.focus()
    const terminalManager = new TerminalManager({
      serverSettings: {
        baseUrl: 'http://localhost:8888',
        wsUrl: '/terminals/websocket',
        token: 'bdea148105459385ee20889c2c820066d345b23a1f3a80c2',
      },
    });

    console.log('terminalManager: ', terminalManager);

    terminalManager.ready.then(() => {
      console.log('TerminalManager is ready and connected to the Jupyter server.');
    }).catch(reason => {
      console.error('Failed to connect to the Jupyter server:', reason);
    });
    // try {
    //   console.log('terminalManager.isReady: ', terminalManager.isReady);
    //   await terminalManager.ready;
    //   console.log('TerminalManager ready');

    //   if (terminalManager.isAvailable()) {
    //     const session = await terminalManager.startNew();
    //     console.log('session: ', session);
    //   } else {
    //     console.log('terminalManager.isReady2: ', terminalManager.isReady);
    //     console.error('Terminal service is not available.');
    //   }
    // } catch (error) {
    //   console.error('Error initializing TerminalManager:', error);
    // }

  }, [])

  return <div ref={ref} className={styles.index}></div>
}

export default Index
@jupyterlab-probot jupyterlab-probot bot added the status:Needs Triage Applied to new issues that need triage label Jul 18, 2024
@JasonWeill
Copy link
Contributor

@jack-hub-maker Thank you for your contribution! Can you provide some more details about how you're running JupyterLab and your application? What are you trying to do with the result of this call to the websocket? Is this something that you could do in a JupyterLab Extension instead? More information will help us triage this issue. Thanks again.

@JasonWeill
Copy link
Contributor

@jack-hub-maker Any updates regarding the questions above? Thanks!

@jack-hub-maker
Copy link
Author

@jack-hub-maker Thank you for your contribution! Can you provide some more details about how you're running JupyterLab and your application? What are you trying to do with the result of this call to the websocket? Is this something that you could do in a JupyterLab Extension instead? More information will help us triage this issue. Thanks again.

Yes, I want to use this direct extension in the react project. I need to communicate with jupyter's websocket. It looks like this class is exposed directly to me, but I can't seem to initialize it properly

@jack-hub-maker
Copy link
Author

In other words, the function of this terminal does not support the extension use of react. Looking forward to your answer

@JasonWeill JasonWeill added pkg:services and removed status:Needs Triage Applied to new issues that need triage labels Aug 6, 2024
@zhangchao828
Copy link

@jack-hub-maker Try adding this line of code document.body.dataset.terminalsAvailable = 'true'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants