xuqm 1 год назад
Родитель
Сommit
9be02f915c
6 измененных файлов: 7126 добавлений и 37 удалений
  1. +7005
    -20
      package-lock.json
  2. +1
    -0
      package.json
  3. +12
    -0
      src/App.vue
  4. +16
    -14
      src/main.js
  5. +89
    -0
      src/szyx-push-sdk.d.ts
  6. +3
    -3
      src/szyx-push-sdk.js

+ 7005
- 20
package-lock.json
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 1
- 0
package.json Просмотреть файл

@@ -51,6 +51,7 @@
"@dcloudio/uni-mp-toutiao": "3.0.0-3070920230324001",
"@dcloudio/uni-mp-weixin": "3.0.0-3070920230324001",
"@dcloudio/uni-quickapp-webview": "3.0.0-3070920230324001",
"@szyx/szyx-push-web": "^0.0.1",
"axios": "^1.3.4",
"fingerprintjs2": "^2.1.4",
"net": "^1.0.2",


+ 12
- 0
src/App.vue Просмотреть файл

@@ -1,7 +1,19 @@
<script>
import SzyxPush, {MsgType} from "@szyx/szyx-push-web";

export default {
onLaunch: function () {
console.log('App Launch')
this.$SzyxPush.register('xuqm').then(() => {
console.log('>>>>>', 'IM连接成功')
}).catch(error => {
console.log('>>>>>', 'im连接失败', error)
})
SzyxPush.onMessage((type, msg) => {
console.log('新消息送达', msg)
if (type === MsgType.text)
this.msg = msg.message.text
})
},
onShow: function () {
console.log('App Show')


+ 16
- 14
src/main.js Просмотреть файл

@@ -1,23 +1,25 @@
import {createSSRApp} from "vue";
import App from "./App.vue";
import SzyxPush from "@szyx/szyx-push-web";

import SzyxPush from "./szyx-push-sdk";
SzyxPush.init('sdada', 'wx').then(() => {
console.log('IM初始化完成')
})
SzyxPush.register('xuqm').then(r => {
console.log('注册im服务完成')
}).catch(e => {
console.log('注册im服务失败', e)
})
SzyxPush.onMessage((type, msg) => {
console.log('收到消息', type, msg)
})
// import SzyxPush from "./szyx-push-sdk";
//
//
// SzyxPush.init('sdada', 'wx').then(() => {
// console.log('IM初始化完成')
// })
// SzyxPush.register('xuqm').then(r => {
// console.log('注册im服务完成')
// }).catch(e => {
// console.log('注册im服务失败', e)
// })
// SzyxPush.onMessage((type, msg) => {
// console.log('收到消息', type, msg)
// })

export function createApp() {
const app = createSSRApp(App);
app.use(SzyxPush, '123456', OsType.wx)
return {
app,
};


+ 89
- 0
src/szyx-push-sdk.d.ts Просмотреть файл

@@ -0,0 +1,89 @@

declare const SzyxPush: ISzyxPush;
export default SzyxPush;


export const 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;

/**
* 当messageType为text的时候,返回这个
*/
export declare interface TextMessage {
text: string
}

export declare interface PictureMessage {
url: string
thumbnail: string
thumbnailWidth: number
thumbnailHeight: number
}

export declare interface Message {
/**
* 租户id
*/
tenantNo: string;
messageType: MsgType;
messageId: string;
target: string;
fromClientId: string;
toClientId: string;
timestamp: number;
message: string | TextMessage | PictureMessage;
}


export declare interface ISzyxPush {

install(app, tenantNo: string, osType: OsType): Promise<void>;


/**
* 初始化方法,建议放在main.js中
* @param tenantNo 租户id,在平台获取
* @param osType 设备类型
*/
init(tenantNo: string, osType: OsType): Promise<void>;

register(userId: string): Promise<void>;

/**
*添加消息回调,到达的消息统一分发入口
* @param callback
* @return callbackId 页面关闭时记得用 {@link unMessage}注销
*/
onMessage(callback: MessageListener): number;

/**
*注销消息回调
* @param callId 由{@link onMessage}返回
*/
unMessage(callId): void;

sendTextMsg(userId: string, text: string): Promise<Message>;
}

+ 3
- 3
src/szyx-push-sdk.js Просмотреть файл

@@ -18,6 +18,9 @@ class SzyxPushClient {

this._client = null;
this.socketOpen = false;
this.ws = {
send: this.sendSocketMessage
}
}

guid() {
@@ -105,9 +108,6 @@ class SzyxPushClient {
})
}

ws = {
send: this.sendSocketMessage
}

_connectClient(resolve, reject) {



Загрузка…
Отмена
Сохранить