Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

didi-pc-sdk

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

didi-pc-sdk

for didimessage pc sdk

  • 1.0.19
  • beta
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

SDK 使用文档

Install
npm i didi-pc-sdk
or
yarn add didi-pc-sdk

vue.config.js

configureWebpack: {
  devtool: "source-map",
  externals: {
    sequelize: "require('sequelize')",
    sqlite3: "require('sqlite3')",
  },
},
pluginOptions: {
  electronBuilder: {
    externals: ['sequelize'],
    nodeIntegration : true
  }
}
Use
初始化 & 建立连接
import MessageSDK from 'didi-pc-sdk'

const messageSDK = new MessageSDK({
  host: 'wss://xxxx.com/api/chat-socket',
  udid: 'didi.pc-8ad19023250c8ba17bba874de62255b01e3116f5bfe9fa3d040eaf5cd6cb3f3f',
  token: 'eyJhbGciOiJIUzUxMiJ9.eyJhdWQiOiJudWxsIiwiaGVhZEltZyI6Imh0dHBzOi8vb3Nzc2l0LmRpZGltZXNzYWdlLmNvbS9oZWFkc2hvdC8yMDIxLzExLzIzLzE2MTIyYTcxLTE4YTQtNDlhMy04NjhmLTNmNWJmOWYxZTJhNV8xMDF4MTAxLnBuZyIsIm5pY2tOYW1lIjoicWkubCBpYW5nMeKdpO-4jyIsImNvdW50cnlDb2RlIjoiUEhMIiwiaW52aXRlQ29kZSI6IjQ0NDQiLCJzZXgiOjEsImlzcyI6IjEwODU2NDg2MDQyNDg0Njk1MDQiLCJ1c2VyVHlwZSI6MCwiZXhwIjoyNjQ2MDE0OTI5LCJpYXQiOjE2NDYwMTQ5MzAsImVtYWlsIjpudWxsLCJqdGkiOiI3ZWJlZmFlYi05MzZkLTRjYmQtYmUxNy1iOWYwN2NmMmQ4NjEifQ.7KbZWCaNL5otO-MTr9ORNHqJQmyg0B90vqH369ARErObqAQcqFxnJquSV9X-VNKTfRizeIet6L-6un-TGeHikw',
  userId: '1085648604248469504',
  language: 'zh-cn',
  version: '196',
  platformType: 'PC',
  clientType: 'pc'
  clientPlatform: 'nl'
  PCPlatform: 'Mac.Windows',
});

then.

// 建立websocket连接
messageSDK.init()

关闭socket(退出等)
this.ws.wsr.close(code, reason)

正常关闭示例

this.ws.wsr.close(1000, '')

app 订阅 sdk 的事件
  • sdk-message
  • sdk-status
// sdk-message => 接收来自 sdk 的消息
messageSDK.addEventListener('sdk-message', (event) => {
  console.warn('vue sdk-message: => ',event)
  messageSDK.toSDK({
    reqId: event.data.reqId
  })
})

// sdk-status => 接收 websocket 状态
messageSDK.addEventListener('sdk-status', (event) => {
  console.warn('vue sdk-status: => ',event.code)
})


sdk-statuscode编码
keyvaluedesc
-1DISCONNECT无连接
0CONNECTING连接中
1CONNECTED连接成功
app 向 sdk 发送消息
  1. 发送消息

变化: 新增加code字段,关于code字段的说明

普通消息和加密消息格式照旧

messageSDK.sendMessage({
  message: ms,
})

// 示例
// - 普通消息:
{
    "code":"02000013",
    "reqId":"86374ea6-0bd2-4e28-958f-a8296d17bd97",
    "targetType":2,
    "targetId":"1283943746819764224",
    "fromType":999,
    "fromId":"1085648604248469504",
    "uniqueCode":"GROUP@1283943746819764224",
    "msgType":1,
    "msgBody":{
        "text":"json群聊"
    },
    "msgHeader":{
        "pubKey":null,
        "version":null,
        "msgSeqNo":1,
        "msgSeqTotal":1,
        "effectiveTime":604800000,
        "sourceSite":null,
        "language":"zh-cn",
        "sign":null,
        "signType":null,
        "effectiveTimeDate":1651044091791
    },
    "refMsgBody":{
        "fromName":"qi.l iang1❤️",
        "fromIcon":"https://osssit.didimessage.com/headshot/2021/11/23/16122a71-18a4-49a3-868f-3f5bf9f1e2a5_101x101.png",
        "tUrl":"https://ididisit.oss-accelerate.aliyuncs.com/headshot/2022/04/20/11a40d1e-c001-413d-ba53-6ec446cc6a48_240x240.png",
        "tName":"sdk测试群"
    }
}
- 加密消息
{
    "code":"02000022",
    "sendTime":1650439419792,
    "myMds":[
        {
            "ud":"1085648604248469504",
            "et":"E068E966-B2DA-425F-AC31-A83D9A244612",
            "deviceId":1,
            "regId":16313,
            "md":"加密单聊"
        }
    ],
    "mds":[
        {
            "ud":"1279608676230094848",
            "et":"538E561B-1F18-4890-AB3E-911DBA665B12",
            "deviceId":1,
            "regId":7831,
            "md":"加密单聊"
        }
    ],
    "reqId":"cc884668-eeea-41ca-a484-34b289895ff6"
}


  1. 接收到消息回复 ACK
messageSDK.toSDK({
  reqId: event.data.reqId
})

// 示例
this.ws.toSDK({
  reqId: event.data.reqId
})
SDK完成的功能说明
  1. 初始化(主要是websocket的连接参数)
  2. 发送消息(sdk记录数据,未收到服务器ack的消息将重复推送)
  3. 接受消息(sdk记录数据,未收到客户端ack的消息将重复推送)
  4. 关闭连接(断开websocket)
Other
node: 14+
electron: 11.4.6

FAQs

Package last updated on 23 May 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc