New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

gt-socket

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gt-socket

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

latest
npmnpm
Version
1.1.0
Version published
Weekly downloads
13
85.71%
Maintainers
1
Weekly downloads
 
Created
Source

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)

FAQs

Package last updated on 29 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts