Socket.D - JavaScript 开发
开发,主要是对 “会话” 与 “监听器” 接口的应用组合!另外,客户端使用单连接即可:
//如果不能连接正常返回(由心跳尝试不断连接)
const session = await SocketD.createClient("sd:ws://127.0.0.1:8602/?u=a&p=2")
.open();
//如果不能连接则异常
const session = await SocketD.createClient("sd:ws://127.0.0.1:8602/?u=a&p=2")
.openOrThow();
目前 JavaScript 的传输适配有:
适配 | 基础传输协议 | 支持端 | 安全 | 备注 | 支持平台 |
---|---|---|---|---|---|
socket.d.js | sd:ws, sd:wss | c | ssl | nio(41kb) | 浏览器, uniapp(h5, android, ios), weixin, node.js |
功效:
- 在前端接口开发时,socket.d 协议可同时可替代 http 和 ws
引用库文件或安装模块包
- js.zip(for Browser, WebView...)
https://gitee.com/noear/socket.d/releases/download/v2.5.12/socket.d.js.zip
https://github.com/noear/socket.d/releases/download/v2.5.12/socket.d.js.zip
<script src="https://cdn.jsdelivr.net/gh/noear/socket.d@2.5.12/javascript/release/socket.d.js"></script>
<script>
//全局单例即可
const session = await SocketD.createClient("sd:ws://127.0.0.1:8602/?token=1b0VsGusEkddgr3d")
.open();
</script>
- js-esm.zip (for Vue, Wechat...)
https://gitee.com/noear/socket.d/releases/download/v2.5.12/socket.d.esm.js.zip
https://github.com/noear/socket.d/releases/download/v2.5.12/socket.d.esm.js.zip
import {SocketD} from "socket.d.esm"
//全局单例即可
const session = await SocketD.createClient("sd:ws://127.0.0.1:8602/?token=1b0VsGusEkddgr3d")
.open();
- npm(for All...)
npm install @noear/socket.d@2.5.12
// CommonJS
const {SocketD} = require("@noear/socket.d")
// ES modules
import {SocketD} from "@noear/socket.d"
//全局单例即可
const session = await SocketD.createClient("sd:ws://127.0.0.1:8602/?token=1b0VsGusEkddgr3d")
.open()