|
@@ -0,0 +1,157 @@
|
|
1
|
+"use strict";
|
|
2
|
+var __assign = (this && this.__assign) || function () {
|
|
3
|
+ __assign = Object.assign || function(t) {
|
|
4
|
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+ s = arguments[i];
|
|
6
|
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+ t[p] = s[p];
|
|
8
|
+ }
|
|
9
|
+ return t;
|
|
10
|
+ };
|
|
11
|
+ return __assign.apply(this, arguments);
|
|
12
|
+};
|
|
13
|
+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+ return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
18
|
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+ });
|
|
20
|
+};
|
|
21
|
+var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+ function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+ function step(op) {
|
|
26
|
+ if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+ while (_) try {
|
|
28
|
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+ if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+ switch (op[0]) {
|
|
31
|
+ case 0: case 1: t = op; break;
|
|
32
|
+ case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+ case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+ default:
|
|
36
|
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+ if (t[2]) _.ops.pop();
|
|
41
|
+ _.trys.pop(); continue;
|
|
42
|
+ }
|
|
43
|
+ op = body.call(thisArg, _);
|
|
44
|
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+ }
|
|
47
|
+};
|
|
48
|
+Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+var CmdMsg_1 = require("../protocol/CmdMsg");
|
|
50
|
+var WsApi = (function () {
|
|
51
|
+ function WsApi() {
|
|
52
|
+ }
|
|
53
|
+ WsApi.prototype.sendMsg = function (msg) {
|
|
54
|
+ return __awaiter(this, void 0, void 0, function () {
|
|
55
|
+ return __generator(this, function (_a) {
|
|
56
|
+ console.log(msg);
|
|
57
|
+ return [2];
|
|
58
|
+ });
|
|
59
|
+ });
|
|
60
|
+ };
|
|
61
|
+ WsApi.prototype.sendGetCmdMsg = function (action, extra) {
|
|
62
|
+ if (extra === void 0) { extra = {}; }
|
|
63
|
+ return __awaiter(this, void 0, void 0, function () {
|
|
64
|
+ var msg;
|
|
65
|
+ return __generator(this, function (_a) {
|
|
66
|
+ msg = CmdMsg_1.CmdMsg.createMsg(__assign({ from: this.from, action: action }, extra));
|
|
67
|
+ return [2, this.sendMsg(msg)];
|
|
68
|
+ });
|
|
69
|
+ });
|
|
70
|
+ };
|
|
71
|
+ WsApi.prototype.sendPostCmdMsg = function (action, userIds, extra) {
|
|
72
|
+ if (extra === void 0) { extra = {}; }
|
|
73
|
+ return __awaiter(this, void 0, void 0, function () {
|
|
74
|
+ var msg;
|
|
75
|
+ return __generator(this, function (_a) {
|
|
76
|
+ msg = CmdMsg_1.CmdMsg.createMsg(__assign({ from: this.from, to: (userIds || []).join(','), action: action }, extra));
|
|
77
|
+ return [2, this.sendMsg(msg)];
|
|
78
|
+ });
|
|
79
|
+ });
|
|
80
|
+ };
|
|
81
|
+ WsApi.prototype.getRoster = function () {
|
|
82
|
+ return this.sendGetCmdMsg('getRoster');
|
|
83
|
+ };
|
|
84
|
+ WsApi.prototype.addFriends = function (userIds) {
|
|
85
|
+ return this.sendPostCmdMsg('addFriends', userIds);
|
|
86
|
+ };
|
|
87
|
+ WsApi.prototype.agreeFriends = function (userIds) {
|
|
88
|
+ return this.sendPostCmdMsg('agreeFriends', userIds);
|
|
89
|
+ };
|
|
90
|
+ WsApi.prototype.rejectFriends = function (userIds) {
|
|
91
|
+ return this.sendPostCmdMsg('rejectFriends', userIds);
|
|
92
|
+ };
|
|
93
|
+ WsApi.prototype.removeFriends = function (userIds) {
|
|
94
|
+ return this.sendPostCmdMsg('removeFriends', userIds);
|
|
95
|
+ };
|
|
96
|
+ WsApi.prototype.getBlacklist = function () {
|
|
97
|
+ return this.sendGetCmdMsg('getBlacklist');
|
|
98
|
+ };
|
|
99
|
+ WsApi.prototype.addToBlackList = function (userIds) {
|
|
100
|
+ return this.sendPostCmdMsg('addToBlackList', userIds);
|
|
101
|
+ };
|
|
102
|
+ WsApi.prototype.removeBlackList = function (userIds) {
|
|
103
|
+ return this.sendPostCmdMsg('removeBlackList', userIds);
|
|
104
|
+ };
|
|
105
|
+ WsApi.prototype.listGroups = function () {
|
|
106
|
+ return this.sendGetCmdMsg('listGroups');
|
|
107
|
+ };
|
|
108
|
+ WsApi.prototype.queryGroupInfo = function (roomId) {
|
|
109
|
+ return this.sendGetCmdMsg('queryGroupInfo', { to: roomId });
|
|
110
|
+ };
|
|
111
|
+ WsApi.prototype.queryRoomMember = function (roomId) {
|
|
112
|
+ return this.sendGetCmdMsg('queryRoomMember', { to: roomId });
|
|
113
|
+ };
|
|
114
|
+ WsApi.prototype.getGroupBlackList = function (roomId) {
|
|
115
|
+ return this.sendGetCmdMsg('getGroupBlackList', { to: roomId });
|
|
116
|
+ };
|
|
117
|
+ WsApi.prototype.createGroup = function (groupOption) {
|
|
118
|
+ return this.sendPostCmdMsg('createGroup', null, { ext: groupOption });
|
|
119
|
+ };
|
|
120
|
+ WsApi.prototype.changeGroupInfo = function (groupOption) {
|
|
121
|
+ return this.sendPostCmdMsg('changeGroupInfo', null, { ext: groupOption });
|
|
122
|
+ };
|
|
123
|
+ WsApi.prototype.addGroupMembers = function (roomId, userIds) {
|
|
124
|
+ return this.sendPostCmdMsg('addGroupMembers', [roomId], {
|
|
125
|
+ ext: {
|
|
126
|
+ members: userIds
|
|
127
|
+ }
|
|
128
|
+ });
|
|
129
|
+ };
|
|
130
|
+ WsApi.prototype.addToGroupBlackList = function (roomId, userIds) {
|
|
131
|
+ return this.sendPostCmdMsg('addToGroupBlackList', [roomId], {
|
|
132
|
+ ext: {
|
|
133
|
+ members: userIds
|
|
134
|
+ }
|
|
135
|
+ });
|
|
136
|
+ };
|
|
137
|
+ WsApi.prototype.destroyGroup = function (roomId) {
|
|
138
|
+ return this.sendPostCmdMsg('destroyGroup', [roomId]);
|
|
139
|
+ };
|
|
140
|
+ WsApi.prototype.leaveGroup = function (roomId) {
|
|
141
|
+ return this.sendPostCmdMsg('leaveGroup', [roomId]);
|
|
142
|
+ };
|
|
143
|
+ WsApi.prototype.createRoom = function (groupOption) {
|
|
144
|
+ return this.sendPostCmdMsg('createGroup', null, { ext: groupOption });
|
|
145
|
+ };
|
|
146
|
+ WsApi.prototype.listRooms = function () {
|
|
147
|
+ return this.sendGetCmdMsg('listRooms');
|
|
148
|
+ };
|
|
149
|
+ WsApi.prototype.joinRoom = function (roomId) {
|
|
150
|
+ return this.sendPostCmdMsg('joinRoom', [roomId]);
|
|
151
|
+ };
|
|
152
|
+ WsApi.prototype.quitRoom = function (roomId) {
|
|
153
|
+ return this.sendPostCmdMsg('quitRoom', [roomId]);
|
|
154
|
+ };
|
|
155
|
+ return WsApi;
|
|
156
|
+}());
|
|
157
|
+exports.WsApi = WsApi;
|