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 🙏

© 2024 – Pkg Stats / Ryan Hefner

gt-socket

v1.1.0

Published

socket2.0 客户端连接插件(web端)

Downloads

1

Readme

gt-socket

socket2.0 客户端连接插件(web端)

安装

    npm install gt-socket

连接socket


/**
 *
 *
 * @param {string} url socket服务地址
 * @param {string} token 身份验证
 * @param {funciton} callback 接受到消息后的回调函数
 *
 * @returns {string} tag 用于断开连接的标识
 */
function gtSocket(url = '', token, callback) {

    return 'tag'
}

接收消息

  • data 数据

    • { code: 1, msg: '连接成功: ${ url }' }

    • { code: -1, msg: 'socket服务异常: ${ errmsg }' }

    • { code: 2, msg: 'socket断开链接: ${ reason }' }

    • { code: 0, msg: '${message}' }


function callback (data) {
    if (data.code == 0) {
        // data.msg 接收到的消息
        console.log(data.msg)
    } else if(data.code == 1) {
        // 连接成功
    }
}

断开连接

    gtSocket.disConnect(tag)

使用gtSocket()连接后, 会返回一个tag, 如果单个项目连接了多个socket, 断开的时候就需要传入tag来区分断开那个socket连接, 如果只有一个socket连接, 可传可不传

简单使用


const gtSocket = require('gtSocket')

let url = 'https://socket2.deeptel.com.cn'
let token = 'a6a00edcde0d68d84aa452b97871f073e964c7fb228dfba91139b23178ea90ee6d40cb75073caa53f06780bfc9b7b6baea7261f7ffb2353716c7f756392e1be21c0ccd1ff92e5b370904ba75f81b7aa1b8149e785181980ec9aacc465f0720efc3a1e6385ce228df'
function callback(data) {
    // *******  业务逻辑  *******
}

// 连接socket, 获取当前socket标识
let tag = gtSocket(url, token, callback)

// 断开连接
gtSocket.disConnect(tag)