@@ -2,8 +2,30 @@ declare const SzyxPush: ISzyxPush; | |||
export default SzyxPush; | |||
export declare type OS_TYPE = "ios" | "android" | "web" | "windows" | "mac" | "unknown"; | |||
export declare type MsgType = "text" | "unknown"; | |||
export declare enum OsType { | |||
ios = 1, | |||
android = 2, | |||
web = 3, | |||
windows = 4, | |||
mac = 5, | |||
wx = 6, | |||
unknown = -1, | |||
} | |||
export const enum MsgType { | |||
unknown = -1, | |||
text = 1, | |||
voice = 2, | |||
image = 3, | |||
location = 4, | |||
video = 5, | |||
file = 6, | |||
at = 7, | |||
other = 8, | |||
log = 9, | |||
} | |||
export declare type MessageListener = (messageType: MsgType, message: Message) => void; | |||
/** | |||
@@ -15,6 +37,9 @@ export declare interface TextMessage { | |||
export declare interface PictureMessage { | |||
url: string | |||
thumbnail: string | |||
thumbnailWidth: number | |||
thumbnailHeight: number | |||
} | |||
export declare interface Message { | |||
@@ -29,17 +54,24 @@ export declare interface Message { | |||
toClientId: string; | |||
timestamp: number; | |||
message: string | TextMessage | PictureMessage; | |||
describe: string; | |||
} | |||
export declare interface ISzyxPush { | |||
setBaseUrl(url: string) | |||
install(app, tenantNo: string, osType: OsType, url: string | null): Promise<void>; | |||
/** | |||
* 初始化方法,建议放在main.js中 | |||
* @param tenantNo 租户id,在平台获取 | |||
* @param osType 设备类型 | |||
* @param osType 设备类型 {@link OsType} | |||
* @param url 服务端地址,可以不传 | |||
*/ | |||
init(tenantNo: string, osType: OS_TYPE): Promise<void>; | |||
init(tenantNo: string, osType: OsType, url: string | null): Promise<void>; | |||
register(userId: string): Promise<void>; | |||
@@ -7,7 +7,6 @@ | |||
export default { | |||
name: 'App', | |||
mounted() { | |||
console.log('====================') | |||
} | |||
} | |||
</script> | |||
@@ -61,7 +61,7 @@ export declare interface ISzyxPush { | |||
setBaseUrl(url: string) | |||
install(app, tenantNo: string, osType: OsType, url: string | null): Promise<void>; | |||
install(app, tenantNo: string, osType: OsType, url?: string): Promise<void>; | |||
/** | |||
@@ -70,7 +70,7 @@ export declare interface ISzyxPush { | |||
* @param osType 设备类型 {@link OsType} | |||
* @param url 服务端地址,可以不传 | |||
*/ | |||
init(tenantNo: string, osType: OsType, url: string | null): Promise<void>; | |||
init(tenantNo: string, osType: OsType, url?: string): Promise<void>; | |||
register(userId: string): Promise<void>; | |||
@@ -87,5 +87,5 @@ export declare interface ISzyxPush { | |||
*/ | |||
unMessage(callId): void; | |||
sendTextMsg(userId: string, text: string): Promise<Message>; | |||
sendTextMsg(userId: string, text: string, describe?: string): Promise<Message>; | |||
} |
@@ -79,13 +79,13 @@ class SzyxPushClient { | |||
this.mapCall.delete(callId) | |||
} | |||
sendTextMsg(userId, text) { | |||
sendTextMsg(userId, text, describe) { | |||
return this.sendMessage({ | |||
toClientId: userId, messageType: MsgType.file, message: `{"text":"${text}"}` | |||
}) | |||
}, describe) | |||
} | |||
sendMessage(msg) { | |||
sendMessage(msg, describe) { | |||
return new Promise((resolve, reject) => { | |||
let messageId = this.guid() | |||
let message = { | |||
@@ -96,6 +96,8 @@ class SzyxPushClient { | |||
timestamp: Date.now(), | |||
packetType: "SEND", ...msg | |||
} | |||
if (describe) | |||
message.describe = describe | |||
this._mapMsg.set(messageId, {call: resolve, message: message}) | |||
this._client.send(`/topic/server`, {}, JSON.stringify(message)) | |||
setTimeout(() => { | |||
@@ -223,8 +225,8 @@ const _connect = (res, resolve, reject) => { | |||
_imUser._account = '56465456' | |||
_imUser._userName = 'xuqm' | |||
_imUser._password = 'xuqm' | |||
_imUser._userName = _imUser._userId | |||
_imUser._password = _imUser._userId | |||
_imClient.connect(_imUser).then(() => resolve()).catch(error => reject(error)) | |||
@@ -232,11 +234,13 @@ const _connect = (res, resolve, reject) => { | |||
const SzyxPush = { | |||
_baseUrl: 'http://192.168.115.137:8888', setBaseUrl: function (url) { | |||
this._baseUrl = url | |||
if (url && url.startsWith('http')) | |||
this._baseUrl = url | |||
}, install: function (app, tenantNo, osType, url) { | |||
return this.init(tenantNo, osType, url) | |||
}, init: function (tenantNo, osType, url) { | |||
this._baseUrl = url | |||
if (url && url.startsWith('http')) | |||
this._baseUrl = url | |||
console.log(`${tenantNo}::${osType}`) | |||
_imUser._tenantNo = tenantNo | |||
_imClient.setDeviceType(osType) | |||
@@ -277,8 +281,8 @@ const SzyxPush = { | |||
}) | |||
} | |||
}) | |||
}, sendTextMsg: function (userId, text) { | |||
return _imClient.sendTextMsg(userId, text) | |||
}, sendTextMsg: function (userId, text, describe) { | |||
return _imClient.sendTextMsg(userId, text, describe) | |||
} | |||
}; | |||
export default SzyxPush |
@@ -41,7 +41,7 @@ export default { | |||
}, | |||
methods: { | |||
sendMsg() { | |||
SzyxPush.sendTextMsg('xuqinmin', '你好!').then((res) => { | |||
SzyxPush.sendTextMsg('xuqinmin', '你好!','sas').then((res) => { | |||
console.log('>>>>>', '发送消息成功', res) | |||
}).catch(error => { | |||
console.log('>>>>>', '发送消息失败', error) | |||