1.1.3 • Published 3 years ago
sendingme-sdk v1.1.3
sending me sdk
Getting Started
$ yarn add sendingme-sdk
create widget
step1
import { Widget } from 'sendingme-sdk'
const widget = new Widget()
step2
<div id="widget"></div>
step3
widget.createWidget(`https://h5.sending.me/#/`)
window.addEventListener('message', function (event) {
if (event.data.target && event.data.target === 'widget') {
console.log(event.data.data)
window.localStorage.setItem('sending-me-session', event.data.data)
}
})
step4
widget.openRoom(`roomid`)
room
const sendingMeClient = new SendingMeClient()
login
const accounts = await window.ethereum.request({
method: 'eth_requestAccounts'
})
const account = accounts[0]
const { user_id } = await sendingMeClient.login(account)
createRoom
const room_id = await sendingMeClient.createRoom({
is_direct: false,
preset: 'private_chat', // public_chat:房间将显示在已发布的房间列表中, private_chat:从已发布的房间列表中隐藏房间
name: 'name', // 房间的名称
topic: 'Topic', // 房间的主题
invite: ['string'] // 邀请到房间的用户 ID 列表。
})
inviteUser
sendingMeClient.inviteUser('roomid', 'userId')
setDisplayName
sendingMeClient.setDisplayName('自己聊天时的名称')