birdpack 1.0.18 → 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/tools.js CHANGED
@@ -13,16 +13,24 @@ const tools = {
13
13
  let name = '';
14
14
  let value = '';
15
15
  if(data == -1){
16
- name = decodeURIComponent(x);
17
- value = '';
16
+ try{
17
+ name = decodeURIComponent(x);
18
+ }catch(e){
19
+ name = x;
20
+ }
18
21
  }else{
19
22
  try{
20
23
  name = decodeURIComponent(x.slice(0, data));
24
+ }catch(e){
25
+ name = x.slice(0, data);
26
+ }
27
+ try{
21
28
  value = decodeURIComponent(x.slice(data + 1));
22
29
  }catch(e){
23
- return {};
30
+ value = x.slice(data + 1);
24
31
  }
25
32
  }
33
+
26
34
  if(typeof output[name] == 'undefined'){
27
35
  output[name] = [value];
28
36
  }else{
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 = tools.encodeFrame('pong', 10);
316
+ let encode = this.encode('pong', 10);
314
317
  this.write(encode);
315
- };
318
+ }
316
319
  send = (text, opcode = 1) => {
317
- let encode = tools.encodeFrame(text, opcode);
320
+ let encode = this.encode(text, opcode);
318
321
  this.write(encode);
319
- };
322
+ }
320
323
  sends = (text, opcode = 1) => {
321
- let encode = tools.encodeFrame(text, opcode);
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 = 1);
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
  }
package/package.json CHANGED
@@ -3,6 +3,6 @@
3
3
  "description": "BirdPack web framework is a tool for web server via TCP HTTP supporting websocket focusing on speed.",
4
4
  "author":"R938",
5
5
  "license":"R938",
6
- "version":"1.0.18",
6
+ "version":"1.0.20",
7
7
  "main": "index.js"
8
8
  }