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

@mac-xiang/socket

v1.0.0

Published

适用于vue/uniapp 的socket.io 封装,如不想支持vue.则注释掉vue部分代码即可(index.ts 文件底部).记得编译哦.

Downloads

6

Readme

socket

介绍

适用于 vue/uniapp 的 weapp.socket.io 封装.

软件架构

编译: tsc 测试: 没有

安装教程

  1. npm i @mac-xiang/socket"

  2. import { tmkSocket, clients, history, events, ioEvent, send } from "@mac-xiang/socket";

    如果需要使用 vue 事件则在 main.js 中添加如下代码

Vue.mixin({
  created() {
    if (this.$options.events) {
      Object.keys(this.$options.events).forEach((key) => {
        let handler = this.$options.events[key];
        if (typeof handler === "string") {
          handler = this[handler];
        }
        this[key + "::handler"] = handler.bind(this);
        this.$root.$on(key, this[key + "::handler"]);
        if (ioEvent.indexOf(key) >= 0) {
          if (!this.events) this.events = {};
          this.events[key] = uuid.v1();
          if (!events[key]) events[key] = {};
          events[key][this.events[key]] = this[key + "::handler"];
        }
      });
    }
  },
  beforeDestroy() {
    if (this.$options.events) {
      Object.keys(this.$options.events).forEach((key) => {
        this.$root.$off(key, this[key + "::handler"]);
        if (ioEvent.indexOf(key) >= 0) {
          Object.keys(events[key]).map((k) => {
            delete events[key][k];
          });
        }
      });
    }
  },
});
  1. 在需要接收消息通知的 vue 页面添加如下属性.
<script>
  export default {
    events: {
      recv(data) {
        // 这里的data 就是送达 message 消息的内容.
      },
    },
  };
</script>

使用说明

  1. s=new tmkSocket(parm); // 创建实例. parm 参数如下
export interface createTmkSocket {
  address: string; // 服务器地址
  token: string; // 服务器认证信息
  reconnect?: number; // 重新连接尝试次数; 小于0 永远尝试连接;0|undefind 不重新连接.
  reTime?: number; // 重新连接间隔;最小值5000毫秒
  callback?: fun; // 连接成功后回调
  eventFuns?: of; // 需要覆盖监听的事件函数集合
}
  1. 可使用 s.send(data,method); 这里的 method 就是原 socket.io 中的 socket.emit(method,data);正好与之相反. method 默认是"message";
  2. 也可以使用 之前导出函数 send 进行发送.

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

特技

啥都没有.就自己用.自己能看懂就行.就几个方法,自己去 index.ts 中看吧,有注解. 逻辑有点杂.看代码去吧.

npm 上传包命令 npm publish --registry http://registry.npmjs.org npm config set registry https://registry.npmjs.org npm publish --access public --registry http://registry.npmjs.org npm config set scope mac-xiang --global

npm version prerelease

npm version prepatch 别笑,记不住

更新日志

1.0.0: 初次提交