npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

webssh2-frontend

v1.0.3

Published

WebSSH2 前端终端库 - 可与任何后端集成

Readme

WebSSH2 Frontend

一个基于xterm.js的WebSSH前端库,可以与任何后端(如Java Spring Boot)集成。

安装

npm install webssh2-frontend

使用方法

1. 在Vue项目中使用

<template>
  <div>
    <div id="ssh-terminal" style="height: 600px;"></div>
  </div>
</template>

<script>
import { WebSSHTerminal } from 'webssh2-frontend';

export default {
  name: 'WebSSH',
  data() {
    return {
      terminal: null
    }
  },
  mounted() {
    this.initTerminal();
  },
  beforeDestroy() {
    if (this.terminal) {
      this.terminal.destroy();
    }
  },
  methods: {
    initTerminal() {
      const config = {
        // 连接配置
        socketUrl: 'http://localhost:9092',
        socketPath: '/socket.io',
        
        // SSH连接参数
        host: 'your-ssh-host',
        port: 22,
        username: 'your-username',
        password: 'your-password',
        
        // 终端配置
        terminal: {
          fontSize: 14,
          cursorBlink: true,
          scrollback: 1000,
          theme: {
            background: '#1e1e1e',
            foreground: '#d4d4d4',
            cursor: '#ffffff'
          }
        },
        
        // UI配置
        ui: {
          headerText: 'SSH终端',
          headerBackground: '#2c3e50',
          showReconnectButton: true
        },
        
        // 事件回调
        onConnected: () => {
          console.log('SSH连接已建立');
        },
        onDisconnected: () => {
          console.log('SSH连接已断开');
        },
        onError: (error) => {
          console.error('SSH连接错误:', error);
        }
      };

      this.terminal = new WebSSHTerminal('ssh-terminal', config);
      this.terminal.connect();
    }
  }
}
</script>

<style>
#ssh-terminal {
  width: 100%;
  height: 100%;
  background: #1e1e1e;
  border-radius: 4px;
  overflow: hidden;
}
</style>

2. 在普通HTML中使用

<!DOCTYPE html>
<html>
<head>
    <title>WebSSH Demo</title>
</head>
<body>
    <div id="ssh-terminal" style="height: 600px;"></div>
    
    <script src="node_modules/webssh2-frontend/dist/webssh2-frontend.js"></script>
    <script>
        const terminal = new WebSSHTerminal('ssh-terminal', {
            socketUrl: 'http://localhost:9092',
            host: 'your-ssh-host',
            username: 'your-username',
            password: 'your-password'
        });
        terminal.connect();
    </script>
</body>
</html>

3. 配置说明

基本配置

interface WebSSHConfig {
  // 连接配置
  socketUrl?: string;          // WebSocket服务器地址
  socketPath?: string;         // Socket路径,默认 '/socket.io'
  
  // SSH连接参数
  host: string;                // SSH主机地址
  port?: number;               // SSH端口,默认22
  username: string;            // 用户名
  password?: string;           // 密码
  privateKey?: string;         // 私钥内容
  
  // 终端配置
  terminal?: {
    theme?: any;               // 终端主题
    fontSize?: number;         // 字体大小
    fontFamily?: string;       // 字体族
    cursorBlink?: boolean;     // 光标闪烁
    scrollback?: number;       // 滚动缓冲区大小
    cols?: number;             // 列数
    rows?: number;             // 行数
  };
  
  // UI配置
  ui?: {
    headerText?: string;       // 头部文字
    headerBackground?: string; // 头部背景色
    showReconnectButton?: boolean; // 显示重连按钮
  };
  
  // 事件回调
  onConnected?: () => void;
  onDisconnected?: () => void;
  onError?: (error: string) => void;
  onData?: (data: string) => void;
}

4. 方法

  • connect(): 连接到SSH服务器
  • disconnect(): 断开SSH连接
  • sendData(data: string): 发送数据到终端
  • resize(): 调整终端大小
  • clear(): 清空终端
  • destroy(): 销毁终端实例

特性

  • 🚀 即插即用: 所有依赖已内置,无需额外安装CDN资源
  • 🎨 可定制: 支持主题、字体、UI样式等自定义配置
  • 🔒 安全: 支持密码和私钥认证
  • 📱 响应式: 自动适应容器大小变化
  • 🔌 通用: 可与任何支持Socket.IO的后端集成

许可证

MIT