birdpack 1.0.19 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/websocket.js +31 -16
- package/package.json +1 -1
package/lib/websocket.js
CHANGED
|
@@ -277,11 +277,11 @@ module.exports = class{
|
|
|
277
277
|
break;
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
-
}
|
|
280
|
+
}
|
|
281
281
|
userLength(){
|
|
282
282
|
if(!this.callback.users)return 0;
|
|
283
283
|
return this.callback.users.length;
|
|
284
|
-
}
|
|
284
|
+
}
|
|
285
285
|
userHas(uid){
|
|
286
286
|
if(!this.callback.users)return false;
|
|
287
287
|
if(this.callback.users.member.hasOwnProperty(uid)){
|
|
@@ -309,34 +309,46 @@ module.exports = class{
|
|
|
309
309
|
}
|
|
310
310
|
return false;
|
|
311
311
|
}
|
|
312
|
+
encode(text, opcode = 1){
|
|
313
|
+
return tools.encodeFrame(text, opcode);
|
|
314
|
+
}
|
|
312
315
|
pong(){
|
|
313
|
-
let encode =
|
|
316
|
+
let encode = this.encode('pong', 10);
|
|
314
317
|
this.write(encode);
|
|
315
|
-
}
|
|
318
|
+
}
|
|
316
319
|
send = (text, opcode = 1) => {
|
|
317
|
-
let encode =
|
|
320
|
+
let encode = this.encode(text, opcode);
|
|
318
321
|
this.write(encode);
|
|
319
|
-
}
|
|
322
|
+
}
|
|
320
323
|
sends = (text, opcode = 1) => {
|
|
321
|
-
let encode =
|
|
324
|
+
let encode = this.encode(text, opcode);
|
|
322
325
|
this.userEach((user)=>{
|
|
323
326
|
user.write(encode);
|
|
324
327
|
});
|
|
325
|
-
};
|
|
326
|
-
json(json){
|
|
327
|
-
this.send(JSON.stringify(json), 1);
|
|
328
|
-
}
|
|
329
|
-
jsons(json){
|
|
330
|
-
this.sends(JSON.stringify(json), 1);
|
|
331
328
|
}
|
|
332
329
|
sendto(uid, text, opcode = 1){
|
|
333
330
|
let user = this.userHas(uid);
|
|
334
331
|
if(user !== false){
|
|
335
|
-
user.send(text, opcode
|
|
332
|
+
user.send(text, opcode);
|
|
336
333
|
return true;
|
|
337
334
|
}
|
|
338
335
|
return false;
|
|
339
|
-
}
|
|
336
|
+
}
|
|
337
|
+
sendc = (text, opcode = 1, call) => {
|
|
338
|
+
let encode = this.encode(text, opcode);
|
|
339
|
+
this.userEach(async(user)=>{
|
|
340
|
+
if(await call(user)){
|
|
341
|
+
user.write(encode);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
json(json){
|
|
347
|
+
this.send(JSON.stringify(json), 1);
|
|
348
|
+
}
|
|
349
|
+
jsons(json){
|
|
350
|
+
this.sends(JSON.stringify(json), 1);
|
|
351
|
+
}
|
|
340
352
|
jsonto(uid, json){
|
|
341
353
|
let user = this.userHas(uid);
|
|
342
354
|
if(user !== false){
|
|
@@ -344,5 +356,8 @@ module.exports = class{
|
|
|
344
356
|
return true;
|
|
345
357
|
}
|
|
346
358
|
return false;
|
|
347
|
-
}
|
|
359
|
+
}
|
|
360
|
+
jsonc(json, call){
|
|
361
|
+
this.sendc(JSON.stringify(json), 1, call);
|
|
362
|
+
}
|
|
348
363
|
}
|