UNPKG

12.5 kBJavaScriptView Raw
1module.exports =
2/******/ (function(modules) { // webpackBootstrap
3/******/ // The module cache
4/******/ var installedModules = {};
5
6/******/ // The require function
7/******/ function __webpack_require__(moduleId) {
8
9/******/ // Check if module is in cache
10/******/ if(installedModules[moduleId])
11/******/ return installedModules[moduleId].exports;
12
13/******/ // Create a new module (and put it into the cache)
14/******/ var module = installedModules[moduleId] = {
15/******/ exports: {},
16/******/ id: moduleId,
17/******/ loaded: false
18/******/ };
19
20/******/ // Execute the module function
21/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22
23/******/ // Flag the module as loaded
24/******/ module.loaded = true;
25
26/******/ // Return the exports of the module
27/******/ return module.exports;
28/******/ }
29
30
31/******/ // expose the modules object (__webpack_modules__)
32/******/ __webpack_require__.m = modules;
33
34/******/ // expose the module cache
35/******/ __webpack_require__.c = installedModules;
36
37/******/ // __webpack_public_path__
38/******/ __webpack_require__.p = "";
39
40/******/ // Load entry module and return exports
41/******/ return __webpack_require__(0);
42/******/ })
43/************************************************************************/
44/******/ ([
45/* 0 */
46/***/ function(module, exports, __webpack_require__) {
47
48 'use strict';
49
50 module.exports = __webpack_require__(1);
51
52/***/ },
53/* 1 */
54/***/ function(module, exports, __webpack_require__) {
55
56 'use strict';
57
58 module.exports = __webpack_require__(2);
59
60/***/ },
61/* 2 */
62/***/ function(module, exports, __webpack_require__) {
63
64 'use strict';
65
66 var both = (function () {
67
68 var Both = undefined;
69
70 // Both should be avaible as function as well as object
71 Both = __webpack_require__(3);
72
73 // Register-Module which manage the registery
74 Both._globalRegistery = {};
75 Both.register = __webpack_require__(4);
76
77 // Command-Module to register commands
78 Both.command = __webpack_require__(5);
79
80 // Query-Module to register queries
81 Both.query = __webpack_require__(6);
82
83 // On-Module to register command-listeners
84 Both.on = __webpack_require__(7);
85
86 // Middleware-Module for third-party modules
87 Both.use = __webpack_require__(8);
88
89 // Registery
90 Both.registery = {
91 commands: {},
92 listeners: {},
93 queries: {} };
94
95 return Both;
96 })();
97
98 module.exports = both;
99
100/***/ },
101/* 3 */
102/***/ function(module, exports, __webpack_require__) {
103
104 'use strict';
105
106 module.exports = __webpack_require__(9);
107
108/***/ },
109/* 4 */
110/***/ function(module, exports, __webpack_require__) {
111
112 'use strict';
113
114 module.exports = __webpack_require__(10);
115
116/***/ },
117/* 5 */
118/***/ function(module, exports, __webpack_require__) {
119
120 'use strict';
121
122 module.exports = __webpack_require__(11);
123
124/***/ },
125/* 6 */
126/***/ function(module, exports, __webpack_require__) {
127
128 'use strict';
129
130 module.exports = __webpack_require__(12);
131
132/***/ },
133/* 7 */
134/***/ function(module, exports, __webpack_require__) {
135
136 'use strict';
137
138 module.exports = __webpack_require__(13);
139
140/***/ },
141/* 8 */
142/***/ function(module, exports, __webpack_require__) {
143
144 'use strict';
145
146 module.exports = __webpack_require__(14);
147
148/***/ },
149/* 9 */
150/***/ function(module, exports, __webpack_require__) {
151
152 'use strict';
153
154 var execute = function execute() {
155 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
156 args[_key] = arguments[_key];
157 }
158
159 var both = __webpack_require__(1);
160 var methodName = args[0] || false;
161 var methodOptional = args[1] || {};
162 var methodCallback = args[2] || false;
163
164 // Error Handling
165 if (args.length === 0) {
166 throw new Error('[both] to execute a command you should give us a identifier');
167 }
168
169 if (args.length > 3) {
170 throw new Error('[both] the execute command doesnt permit more than two arguments');
171 }
172
173 if (typeof methodName !== 'string') {
174 throw new Error('[both] to execute a command you should give us a string-identifier');
175 }
176
177 if (typeof methodOptional !== 'object') {
178 throw new Error('[both] the second argument when you execute a command should always be a object or a');
179 }
180
181 if (typeof methodCallback !== 'function' && methodCallback !== false) {
182 throw new Error('[both] to execute a command you should give us a function as callback');
183 }
184
185 // Execute commands
186 if (both._globalRegistery.command && both._globalRegistery.command[methodName] !== undefined) {
187 both._globalRegistery.command[methodName].func(methodName, methodOptional, methodCallback);
188 }
189
190 // Execute listeners
191 if (both._globalRegistery.listener && both._globalRegistery.listener[methodName] !== undefined) {
192 both._globalRegistery.listener[methodName].func(methodName, methodOptional, methodCallback);
193 }
194
195 // Execute queries
196 if (both._globalRegistery.query && both._globalRegistery.query[methodName] !== undefined) {
197 both._globalRegistery.query[methodName].func(methodName, methodOptional, methodCallback);
198 }
199
200 // Execute global listeners
201 if (both._globalRegistery.listener) {
202 Object.keys(both._globalRegistery.listener).forEach(function (listenerName) {
203 if (isNaN(listenerName) === false) {
204 both._globalRegistery.listener[listenerName].func(methodName, methodOptional, methodCallback);
205 }
206 });
207 }
208 };
209
210 module.exports = execute;
211
212/***/ },
213/* 10 */
214/***/ function(module, exports, __webpack_require__) {
215
216 'use strict';
217
218 var register = function register() {
219 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
220 args[_key] = arguments[_key];
221 }
222
223 var both = __webpack_require__(1);
224 var registerType = null;
225 var registerName = null;
226 var registerPayload = null;
227
228 // Error Handling
229 if (args.length < 2) {
230 throw new Error('[both] the `register` module expects at least two arguments');
231 }
232
233 if (typeof args[0] !== 'string') {
234 throw new Error('[both] the `register`module expects as first argument a registerType in string-format');
235 } else {
236 registerType = args[0];
237 }
238
239 if (args[1].toString() !== '[object Object]') {
240 throw new Error('[both] the `register` module expects as second argument a object');
241 } else {
242 registerPayload = args[1];
243 }
244
245 if (registerPayload.name === undefined) {
246 throw new Error('[both] the `register` module expets at least one `name` param in the given `registerObject`');
247 } else {
248 registerName = registerPayload.name;
249 }
250
251 // Module
252 both._globalRegistery[registerType] = both._globalRegistery[registerType] || {};
253 both._globalRegistery[registerType][registerName] = registerPayload;
254 };
255
256 module.exports = register;
257
258/***/ },
259/* 11 */
260/***/ function(module, exports, __webpack_require__) {
261
262 'use strict';
263
264 var command = function command(commandName, commandFn) {
265
266 var both = __webpack_require__(1);
267
268 // Error Handling
269 if (commandName === undefined && commandFn === undefined) {
270 throw new Error('[both] the `command` module expects a commandName and a commandFunction');
271 }
272
273 if (typeof commandName !== 'string') {
274 throw new Error('[both] the `command` module expects a commandName as string');
275 }
276
277 if (commandFn === undefined) {
278 throw new Error('[both] the `command` module expects a function as second argument');
279 }
280
281 if (typeof commandFn !== 'function') {
282 throw new Error('[both] the `command` module expects a function as second argument');
283 }
284
285 both.register('command', {
286 name: commandName,
287 func: commandFn
288 });
289 };
290
291 module.exports = command;
292
293/***/ },
294/* 12 */
295/***/ function(module, exports, __webpack_require__) {
296
297 'use strict';
298
299 var query = function query() {
300 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
301 args[_key] = arguments[_key];
302 }
303
304 var both = __webpack_require__(1);
305
306 var queryName = null;
307 var queryFn = null;
308
309 if (args.length < 2) {
310 throw new Error('[both] the `query` module expects a `queryName` and a `commandFunction`');
311 } else {
312 queryName = args[0];
313 queryFn = args[1];
314 }
315
316 if (typeof queryName !== 'string') {
317 throw new Error('[both] the `query` module expects a `queryName` in a string format');
318 }
319
320 if (typeof queryFn !== 'function') {
321 throw new Error('[both] the `query` module expects the `queryFn` as function');
322 }
323
324 // Register function in Both-Registery
325 both.register('query', {
326 name: queryName,
327 func: queryFn
328 });
329 };
330
331 module.exports = query;
332
333/***/ },
334/* 13 */
335/***/ function(module, exports, __webpack_require__) {
336
337 'use strict';
338
339 var on = function on() {
340 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
341 args[_key] = arguments[_key];
342 }
343
344 var both = __webpack_require__(1);
345 var listeners = both.registery.listeners || {};
346
347 // Error Handling
348 if (args.length > 2) {
349 throw new Error('[both] the `on` listener allow not more than two params');
350 }
351
352 if (args.length === 1 && typeof args[0] !== 'function') {
353 throw new Error('[both] the `on` expects at least one function passed');
354 }
355
356 if (args.length === 0) {
357 throw new Error('[both] the `on` expects some params, read the docs ;)');
358 }
359
360 // Module
361 if (args.length === 1 && typeof args[0] === 'function') {
362
363 var listenerID = 0;
364
365 if (both._globalRegistery.listener) {
366 listenerID = Object.keys(both._globalRegistery.listener).length === 0 ? 0 : Object.keys(listeners).length;
367 }
368
369 both.register('listener', {
370 name: listenerID,
371 func: args[0]
372 });
373 }
374
375 if (args.length === 2 && typeof args[0] === 'string' && typeof args[1] === 'function') {
376 var listenerID = args[0];
377
378 both.register('listener', {
379 name: listenerID,
380 func: args[1]
381 });
382 }
383 };
384
385 module.exports = on;
386
387/***/ },
388/* 14 */
389/***/ function(module, exports, __webpack_require__) {
390
391 'use strict';
392
393 var use = function use() {
394 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
395 args[_key] = arguments[_key];
396 }
397
398 // Register available middlewares
399 var middlewareCollection = {
400 'socket.io': {
401 'server': __webpack_require__(15),
402 'client': __webpack_require__(16)
403 }
404 };
405
406 var middlewareName = null;
407 var middlewareUnit = null;
408 var middlewareType = null;
409
410 // Error handling
411 if (args.length === 0) {
412 throw new Error('[both] the `use` adapter expects two arguments [middlewareName, middleware]');
413 }
414
415 if (typeof args[0] !== 'string') {
416 throw new Error('[both] the `use` adapter expects a [middlewareName]-String as first argument.');
417 } else {
418 middlewareName = args[0];
419 }
420
421 if (typeof args[1] === 'undefined') {
422 throw new Error('[both] the `use` adapter expects a [middleware] as second argument');
423 } else {
424 middlewareUnit = args[1];
425 }
426
427 // Check if client or server
428 if (typeof window !== 'undefined' && window) {
429 middlewareType = 'client';
430 } else {
431 middlewareType = 'server';
432 }
433
434 if (middlewareCollection[middlewareName] !== undefined && middlewareCollection[middlewareName][middlewareType] !== undefined) {
435 middlewareCollection[middlewareName][middlewareType](middlewareUnit);
436 } else {
437 throw new Error('[both] the `use` adapter didnt found any requested modules');
438 }
439 };
440
441 module.exports = use;
442
443/***/ },
444/* 15 */
445/***/ function(module, exports, __webpack_require__) {
446
447 'use strict';
448
449 var both = __webpack_require__(1);
450
451 module.exports = function (socket) {
452 if (socket !== 'undefined' && socket.on) {
453 socket.on('connection', function (io) {
454 io.on('both', function (args) {
455 var callback = arguments[1] === undefined ? false : arguments[1];
456
457 var commandName = args.commandName;
458 var payload = args.payload;
459 both(commandName, payload, callback);
460 });
461 });
462 }
463 };
464
465/***/ },
466/* 16 */
467/***/ function(module, exports, __webpack_require__) {
468
469 'use strict';
470
471 var both = __webpack_require__(1);
472
473 module.exports = function (socket) {
474 if (socket !== 'undefined' && typeof socket === 'function') {
475 both.on(function (commandName, payload, callback) {
476 socket().emit('both', {
477 commandName: commandName,
478 payload: payload
479 }, callback);
480 });
481 }
482 };
483
484/***/ }
485/******/ ]);
\No newline at end of file