1 var realtimeMoudles = { 2 "system": { 3 "tip": function() { 4 alert("hello world!"); 5 }, 6 "test": function (parameter) { 7 alert(parameter[0]); 8 alert(parameter[1]); 9 } 10 }, 11 "execute": function(module, method) { 12 realtimeMoudles[module][method](); 13 }, 14 "executeWithParameter": function(module, method, parameters) { 15 realtimeMoudles[module][method](JSON.parse(parameters)); 16 } 17 }; 18 var instance = null; 19 var Realtime = { 20 "Call" : function(module, moduleItem, method) { 21 $.post("Library/Realtime/Call.ashx", {"module" : module, "moduleItem": moduleItem, "method": method}, function (result) { 22 }); 23 }, 24 "CallForResult": function (module, moduleItem, method, func) { 25 $.post("Library/Realtime/CallForResult.ashx", { "module": module, "moduleItem": moduleItem, "method": method }, function (result) { 26 func(result); 27 }); 28 }, 29 "CallForJson": function (module, moduleItem, method, func) { 30 $.post("Library/Realtime/CallForJson.ashx", { "module": module, "moduleItem": moduleItem, "method": method }, function (result) { 31 func(result); 32 }); 33 }, 34 "CallWithParams": function (module, moduleItem, method, params) { 35 $.post("Library/Realtime/CallWithParams.ashx", { "module": module, "moduleItem": moduleItem, "method": method, "params": params.join("`") }, function (result) { 36 }); 37 }, 38 "CallWithParamsForResult": function (module, moduleItem, method, params, func) { 39 $.post("Library/Realtime/CallWithParamsForResult.ashx", { "module": module, "moduleItem": moduleItem, "method": method, "params": params.join("`") }, function (result) { 40 func(result); 41 }); 42 }, 43 "CallWithParamsForJson": function (module, moduleItem, method, params, func) { 44 $.post("Library/Realtime/CallWithParamsForJson.ashx", { "module": module, "moduleItem": moduleItem, "method": method, "params": params.join("`") }, function (result) { 45 func(result); 46 }); 47 }, 48 "AddClientFunction": function (module, moduleItem, func) { 49 if (realtimeMoudles[module] == null) { 50 realtimeMoudles[module] = {}; 51 } 52 eval("realtimeMoudles[module]." + moduleItem + "= func"); 53 if (instance != null) { 54 if (instance.client[module] == null) { 55 instance.client[module] = {}; 56 } 57 eval("instance.client[module]." + moduleItem + " = func"); 58 if (Realtime[module] == null) { 59 Realtime[module] = {}; 60 } 61 eval("Realtime[module]." + moduleItem + " = func"); 62 } 63 } 64 }; 65 66 $(function () { 67 instance = $.connection.realtimeInstance; 68 for (var module in realtimeMoudles) { 69 if (instance.client[module] == null) { 70 instance.client[module] = {}; 71 } 72 instance.client[module] = realtimeMoudles[module]; 73 if (Realtime[module] == null) { 74 Realtime[module] = {}; 75 } 76 Realtime[module] = realtimeMoudles[module]; 77 } 78 $.connection.hub.start(); 79 });