2.0.0-alpha.6 • Published 2 years ago

tq-message-center-engine v2.0.0-alpha.6

Weekly downloads
2
License
ISC
Repository
-
Last release
2 years ago

TQMessageCenterEngine 天阙消息中心引擎

  • 注意事项:
    • 2.0.0+版本是适配聚光推送

    • 1.4.x版本是无线云平台推送

Installing

npm install tq-message-center-engine@2.0.0-alpha.6
/********************初始化引擎********************/
var options = {
        appKey: 'com.tianque.tqvdc', // pd端 appkey,业务端需要保证唯一不要使用com.tianque.tqvdc,
        namespace:'com.tianque.message.user',//聚光后台配置获取
        accessKey: 'ofOjgtx7613ow7p4',//聚光后台配置获取
        accessSecret: 'tCzjJ0JJ3Ahsnf6GE7zCeDrTdj6aF71U',//聚光后台配置获取
        socketHost: 'http://192.168.110.187:10800', // socket 服务器 杭州测试环境
        apiHost: 'http://192.168.1.74:11300', // api 请求服务器 杭州测试环境
        clientId: 'userId',//业务端用户唯一id
    }

/********************导入引擎********************/
import TQMessageCenterEngine from 'tq-message-center-engine'

/********************初始化引擎********************/
var engine = new TQMessageCenterEngine(options)
/********************系统事件********************/
//当前用户上线
engine.on(TQMessageCenterEngine.EVENT_TYPES.CONNECT, function (data, ackServerCallback) {
    console.log(TQMessageCenterEngine.EVENT_TYPES.CONNECT, data)
})
//当前用户下线
engine.on(TQMessageCenterEngine.EVENT_TYPES.DISCONNECT, function (data, ackServerCallback) {
    console.log(TQMessageCenterEngine.EVENT_TYPES.DISCONNECT, data)
})
//其他用户下线
engine.on(TQMessageCenterEngine.EVENT_TYPES.USER_DISCONNECTED, function (data, ackServerCallback) {
    console.log(TQMessageCenterEngine.EVENT_TYPES.USER_DISCONNECTED, data)
})
//当前用户加入房间
engine.on(TQMessageCenterEngine.EVENT_TYPES.JOINED, function (data, ackServerCallback) {
    console.log(TQMessageCenterEngine.EVENT_TYPES.JOINED, data)
})
//当前用户离开房间
engine.on(TQMessageCenterEngine.EVENT_TYPES.LEAVED, function (data, ackServerCallback) {
    console.log(TQMessageCenterEngine.EVENT_TYPES.LEAVED, data)
})

/********************加入群组********************/
/**
 *
 * @param options
 * | **参数名称**              | **参数说明**   | **是否必须** | **数据类型**     | **schema** |
 * | ------------------------- | -------------- | ------------ | ---------------- | ---------- |
 * | room                      | 群名称         | true         | string           |            |
 * | roomType                  | 群类型         |              |                  |            |
 * | 值为:                    |                |              |                  |            |
 * | appSubset(应用内部群)     |                |              |                  |            |
 * | projectSubset(项目内部群) | true           | string       |                  |            |
 * @returns {AxiosPromise<any>}
 */
joinRoom(options);

//Examples
const options = {
  room: 'room1',
  roomType:'projectSubset'
}
engine.joinRoom(options).then((data) => {
  console.log('joinRoom', data)
})

/********************发送消息********************/
/**
 *
 * @param options
 *      | **参数名称**              | **参数说明**               | **是否必须** | **数据类型**       | 备注                           |
 *      | ------------------------- | -------------------------- | ------------ | ------------------ | ------------------------------ |
 *      | messageContent            | 消息内容                   | true         | string或object      | string:透传,object:转为json后传输|
 *      | messageTitle              | 消息标题                   | true         | string             |                                |
 *      | messageType               | 通知类型                   | true         | string             | 消息框架和视频通话使用了message,chat,leave,join类型,业务端消息类型需要避开上述类型|
 *      | offLine                   | 离线通知                   | false        | boolean            | 默认非离线                     |
 *      | msgId                     | 消息id                     | true         | string             |                                |
 *      | targetClientId            | 指定用户列表,逗号分割      | false        | string             |                                |
 *      | room                      | 群名称                     | false        | string             | targetClientId和room必有一个值 |
 *      | roomType                  | 群类型                     |              |                    |                                |
 *      | 值为:                    |                            |              |                    |                                |
 *      | appSubset(应用内部群)     |                            |              |                    |                                |
 *      | projectSubset(项目内部群) | false                      | string       | 当room不为空时必填 |                                |
 *      | roomAppKey                | 应用级群所属应用           | false        | string             | 当                             |
 *      | roomType=appSubset 时必传 |                            |              |                    |                                |
 *      | appKeySet                 | 需要发送到的应用APPkey集合 | false        | array              |                                |
 *      | clientTypeSet             | 需要发送到的客户端类型集合 | false        | array              |                                |
 * @returns {AxiosPromise<any>}
 */
sendMessage(options);
//示例
//群发 给room1所有人发送消息
const options = {
  room: 'room1',
  msgId:'1',
  messageType:'deommsg',
  roomType:'projectSubset',
  messageTitle:'title',
  messageContent:'hello',
}
engine.sendMessage(options).then(data => {
  console.log('sendMessage', data)
})
//给指定的人发送消息
const options = {
  targetClientId:[1,2],
  msgId:'1',
  messageType:'deommsg',
  roomType:'projectSubset',
  messageTitle:'title',
  messageContent:'hello',
}
engine.sendMessage(options).then(data => {
  console.log('sendMessage', data)
})
/********************离开群组********************/

/**
 *
 * @param options
 * | **参数名称**              | **参数说明**   | **是否必须** | **数据类型**     | **schema** |
 * | ------------------------- | -------------- | ------------ | ---------------- | ---------- |
 * | room                      | 群名称         | true         | string           |            |
 * | roomType                  | 群类型         |              |                  |            |
 * | 值为:                    |                |              |                  |            |
 * | appSubset(应用内部群)     |                |              |                  |            |
 * | projectSubset(项目内部群) | true           | string       |                  |            |
 * @returns {AxiosPromise<any>}
 */
leaveRoom(options)

//示例:
const options = {
  room: 'room1',
  roomType:'projectSubset'
}
engine.leaveRoom(options).then(data => {
  console.log('leaveRoom', data)
})

/********************退出连接********************/
engine.disconnect()