1.1.5 • Published 1 year ago

heshuo-im-sdk v1.1.5

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

im-sdk

调用方式

  1. 在项目中引入, 实例化IM对象(传入vuex对象,和IM进行绑定)
    import store from './store'
    import IM from '../lib/sdk'
    const im = new IM(store, {
    	baseUrl: process.env.VUE_APP_BASE_API + '/rainbowchat_server',
    	baseAdminUrl: process.env.VUE_APP_BASE_ADMIN_URL,
    	baseImUrl: process.env.VUE_APP_BASE_NODE_API,
    	CHATTING_HISTORY_LOAD_TIME_INTERVAL: 3
    })
    Vue.prototype.$im = im
  2. 项目中直接使用this.$im进行调用IM的方法
  3. 如在项目中直接引入打包前的文件,可在vue.config.js或者webpack.config.js中注入变量, 用户区分小程序还是web
    • vue.config.js
    	configureWebpack: {
    		plugins: [
    			new webpack.DefinePlugin({
    				PLATFORM: JSON.stringify(process.env.PLATFORM),
    			})
    		]
    	}
    • webpack.config.js
     plugins: [
    	new webpack.DefinePlugin({
    		PLATFORM: JSON.stringify(process.env.PLATFORM),
    	})
     ]
  4. 常用功能可参考im-merchant
  5. 详细内容可参考wiki

restful接口

包含在im的restApi对象中,其返回为promise

使用方式

  1. 使用回调函数 回调函数定义于im的adopter对象中,可调用im.adopter.description进行查看详细内容
  2. 使用sdk中数据进行驱动
    • sdk中的数据存在于vuex中,im构造函函数将sdk中vuex modules动态载入了主项目中的vuex中,命名为imStore模块
    • 可使用普通的vuex方法(如mapState等)使用

自定义消息

  1. 消息的发送 参考messageHelper.sendSelfMsg方法
  2. 消息的接收展示 参考chatMsgHelper.createChatMsgEntity_COME_SELF以及chatMsgHelper.setCreateChatMsgEntity_COME_SELF方法,具体参考wiki
  3. 消息列表的展示 参考messageHelper.selfMsgContentForShow以及messageHelper.setSelfMsgContentForShow方法,具体参考wiki