Repository navigation
Expand file tree
/
Copy pathSTOMPManager.js
More file actions
111 lines (106 loc) · 2.74 KB
/
Copy pathSTOMPManager.js
File metadata and controls
111 lines (106 loc) · 2.74 KB
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
/**
* Created by will on 2016/7/5.
*/
import {NativeModules} from 'react-native';
let SPM = NativeModules.JSSTOMPManager;
import STOMPSender from './STOMPSender.js';
import STOMPReceiver from './STOMPReceiver.js';
/**
* @class STOMPManager
*/
export default class STOMPManager{
/**
* 创建一个AMQPManager对象
* @memberOf STOMPManager
* @returns {Promise.<AMQPManager>}
*/
async createObj(){
try{
var {_STOMPManagerId} = await SPM.createObj();
var STOMPManagerObj = new STOMPManager();
STOMPManagerObj.STOMPManagerId = _STOMPManagerId;
return STOMPManagerObj;
}catch(e){
console.error(e);
}
}
/**
* 初始化库。
* @memberOf STOMPManager
* @returns {Promise.<AMQPReceiver>}
*/
async initializeLibrary(){
try{
await SPM.initializeLibrary();
}catch(e){
console.error(e);
}
}
/**
* 释放环境。不可重复释放。
* @memberOf STOMPManager
* @returns {Promise.<AMQPReceiver>}
*/
async shutdownLibrary(){
try{
await SPM.shutdownLibrary();
}catch(e){
console.error(e);
}
}
/**
* 创建一个发送端
* @memberOf STOMPManager
* @returns {Promise.<AMQPSender>}
*/
async newSender(useTopic,name){
try{
var {STOMPSenderId} = await SPM.newSender(this.STOMPManagerId,useTopic,name);
var newSPS = new STOMPSender();
newSPS.STOMPSenderId = STOMPSenderId;
return newSPS;
}catch(e){
console.error(e);
}
}
/**
* 创建一个接收端
* @memberOf STOMPManager
* @returns {Promise.<AMQPSender>}
*/
async newReceiver(useTopic,name,clientID){
try{
var {STOMPReceiverId} = await SPM.newReceiver(this.STOMPManagerId,useTopic,name,clientID);
var newSPR = new STOMPReceiver();
newSPR.STOMPReceiverId = STOMPReceiverId;
return newSPS;
}catch(e){
console.error(e);
}
}
/**
* 建立链接
* @memberOf STOMPManager
* @returns {Promise.<bool>}
*/
async connection(URI,userName,passWord){
try{
var {isConnection} = await SPM.connection(this.STOMPManagerId,URI,userName,passWord);
return isConnection;
}catch(e){
console.error(e);
}
}
/**
* 断开链接
* @memberOf STOMPManager
* @returns {Promise.<bool>}
*/
async disconnection(){
try{
await SPM.disconnection(this.STOMPManagerId);
}catch(e){
console.error(e);
}
}
}