/
index.ts
241 lines (220 loc) · 6.72 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import { Injectable } from '@angular/core';
import { Plugin, Cordova, IonicNativePlugin } from '@youme-ionic/core';
/**
* chat type
*
* @export
* @enum {number}
*/
export enum ChatType {
Unknow = 0,
PrivateChat = 1,
RoomChat = 2,
};
/**
* file type
*
* @export
* @enum {number}
*/
export enum FileType {
Other = 0,
Audio = 1,
Image = 2,
Video = 3,
}
/**
* server's location
*
* @export
* @enum {number}
*/
export enum ServerZone {
China = 0, // China - default
Singapore = 1, // Singapore
America = 2, // America
HongKong = 3, // HongKong
Korea = 4, // Korea
Australia = 5, // Australia
Deutschland = 6, // Deutschland
Brazil = 7, // Brazil
India = 8, // India
Japan = 9, // Japan
Ireland = 10 // Ireland
};
/**
* @name YoumeIM
* @description
* This plugin facilitates the usage of Youme IM in an Ionic apps with the integrated YoumeIMSDK
*
* @usage
* ```typescript
* import { YoumeIM } from '@youme-ionic/youme-im';
*
*
* constructor(private youmeIM: YoumeIM) { }
*
* ...
*
*
* this.youmeIM.init('xxxxx', 'xxxxx', 0)
* .then((res: any) => console.log(res))
* .catch((error: any) => console.error(error));
*
* ```
*/
@Plugin({
pluginName: 'YoumeIM',
plugin: 'cordova-plugin-youme-im',
pluginRef: 'cordova.plugins.YoumeIMCordovaPlugin',
repo: 'https://github.com/youmesdk/YoumeIMCordovaPlugin',
install: 'cordova plugin add cordova-plugin-youme-im',
installVariables: [],
platforms: ['Android']
})
@Injectable()
export class YoumeIM extends IonicNativePlugin {
/**
* init sdk
* @param {string} appKey - iapp dentifier, obtained after registering at www.youme.im
* @param {string} secretKey - app security key, obtained after registering at www.youme.im
* @param {ServerZone} regionId - server zone
* @return {Promise<any>}
*/
@Cordova()
init(appKey: string, secretKey: string, regionId: ServerZone): Promise<any> { return; }
/**
* login
* @param {string} userid - User ID, assigned by the caller, cannot be an empty string.
* It can only be composed of letters or numbers or underscores.
* The length is limited to 255 bytes.
* @param {string} password - Login password, can not be an empty string,
* can be set to a fixed string without special requirements
* @param {string} token - User token, used when using server token authentication mode.
* If not used, token is passed in: "", the token value is obtained by restAPI.
* @return {Promise<any>}
*/
@Cordova()
login(userid: string, password: string, token: string): Promise<any> { return; }
/**
* logout
* @return {Promise<any>}
*/
@Cordova()
logout(): Promise<any> { return; }
/**
* send text message
* @param {string} strRecvId - reciver id
* @param {number} iChatType - chat type
* @param {string} strMsgContent - message content
* @param {string} strAttachParam - attach message
* @return {Promise<any>}
*/
@Cordova()
sendTextMessage(strRecvId: string, iChatType: ChatType, strMsgContent: string, strAttachParam: string): Promise<any> { return; }
/**
* regist callback function for reconnect event
* @param {Function} success - callback function for success
* @param {Function} error - callback function for error
* @return {Promise<any>}
*/
@Cordova({ sync: true })
registerReconnectCallback(success: Function, error: Function): void { return; }
/**
* regist callback function for kick out event
* @param {Funtion} success - callback function for success
* @param {Function} error - callback function for error
* @return
*/
@Cordova({ sync: true })
registerKickOffCallback(success: Function, error: Function): void { return; }
/**
* regist callback function for message event
*
* @param {Function} success - callback function for success
* @param {Function} error - callback function for error
* @returns {void}
*/
@Cordova({ sync: true })
registerMsgEventCallback(success: Function, error: Function): void { return; }
/**
* start record audio message
* @param {string} recvID - reciver's id; private chat: userid,room chat: roomid
* @param {ChatType} chatType - chatType
* @param {string} extraText - extra text message for voice message
* @param {boolean} needRecognize - Whether to enable only recognize voice text, not send voice messages
* @returns {Promise<any>}
*/
@Cordova()
startRecordAudioMessage(recvID: string, chatType: ChatType, extraText: string, needRecognize: boolean): Promise<any> { return; }
/**
* cancel record audio message, not send
* @returns {Promise<any>}
*/
@Cordova()
cancelAudioMessage(): Promise<any> { return; }
/**
* stop record audio message, and send it
* @returns {Promise<any>}
*/
@Cordova()
stopAndSendAudioMessage(): Promise<any> { return; }
/**
* join single chart room by room id
* @param {string} roomID - room id
* @returns {Promise<any>}
*/
@Cordova()
joinChatRoom(roomID: string): Promise<any> { return; }
/**
* leave chat room by id
* @param {string} roomID - room id
* @returns {Promise<any>}
*/
@Cordova()
leaveChatRoom(roomID: string): Promise<any> { return; }
/**
* start play audio
* @param {string} audioPath - audio file path
* @returns {Promise<any>}
*/
@Cordova()
startPlayAudio(audioPath: string): Promise<any> { return; }
/**
* stop play audio
* @return {Promise<any>}
*/
@Cordova()
stopPlayAudio(): Promise<any> { return; }
/**
* send file
*
* @param {string} strRecvId - reciver's id, private chat: userid,room chat: roomid
* @param {ChatType} iChatType - ChatType
* @param {string} filePath - file path
* @param {string} strAttachParam - attach string message
* @param {FileType} fileType - FileType
* @returns {Promise<any>}
*/
@Cordova()
sendFileMessage(strRecvId: string, iChatType: ChatType , filePath: string, strAttachParam: string, fileType: FileType): Promise<any> { return; }
/**
* switch transfer file type
*
* @param {(string | number)} transType - 0 message will delivery directly;
* 1 means just cc to app server, not delivery directly
* @returns {Promise<any>}
*/
@Cordova()
switchTransType(transType: string | number): Promise<any> { return; }
/**
* download file
*
* @param {string} strDownloadURL - http or https url
* @param {string} strSavePath - file path, full path
* @param {FileType} fileType - FileType
* @returns {Promise<any>}
*/
@Cordova()
downloadFileByUrl(strDownloadURL: string, strSavePath: string , fileType: FileType): Promise<any> { return; }
}