/*! ************************************************************************** sgcWebSocket component written by eSeGeCe copyright © 2020 Email : info@esegece.com Web : http://www.esegece.com ************************************************************************** */ function sgcws(){if(0!=arguments.length){1==arguments.length?"object"==typeof arguments[0]?(arguments[0].subprotocol="esegece.com",sgcWebSocket.call(this,arguments[0])):"string"==typeof arguments[0]&&(arguments[1]="esegece.com",sgcWebSocket.call(this,arguments[0],arguments[1])):2==arguments.length?"object"==typeof arguments[0]?(arguments[0].subprotocol=arguments[1]+".esegece.com",sgcWebSocket.call(this,arguments[0])):"string"==typeof arguments[0]&&(arguments[1]=arguments[1]+".esegece.com",sgcWebSocket.call(this,arguments[0],arguments[1])):3==arguments.length&&("object"==typeof arguments[0]?(arguments[0].subprotocol=arguments[1]+".esegece.com",arguments[0].transport=arguments[2],sgcWebSocket.call(this,arguments[0])):"string"==typeof arguments[0]&&(arguments[1]=arguments[1]+".esegece.com",sgcWebSocket.call(this,arguments[0],arguments[1],arguments[2])));var e="";this.qoslevel0=function(){e="qosLevel0"},this.qoslevel1=function(){e="qosLevel1"},this.qoslevel2=function(){e="qosLevel2"};var s="";this.queuelevel0=function(){s="queueLevel0"},this.queuelevel1=function(){s="queueLevel1"},this.queuelevel2=function(){s="queueLevel2"};var t=this.send;this.send=function(c,o,n,i){_qos="",""!==e&&void 0!==e&&(_qos=', "qos":"'+e+'"'),_queue="",""!==s&&void 0!==s&&"sgc@publish"==o&&(_queue=', "queue":"'+s+'"'),_message=c,"{"!==_message.substr(0,1)&&"["!==_message.substr(0,1)&&'"'!==_message.substr(0,1)&&(_message='"'+_message+'"'),1==arguments.length?arguments[0]='{"jsonrpc":"2.0", "method":"sgc@message", "params":{"message":'+_message+_qos+_queue+'}, "id":"'+GUID()+'"}':2==arguments.length?arguments[0]='{"jsonrpc":"2.0", "method":"'+o+'", "params":{"message":'+_message+_qos+_queue+'}, "id":"'+GUID()+'"}':""!==i&&void 0!==i?arguments[0]='{"jsonrpc":"2.0", "method":"'+o+'", "params":{"channel":"'+n+'", "message":'+_message+_qos+_queue+'}, "id":"'+i+'"}':arguments[0]='{"jsonrpc":"2.0", "method":"'+o+'", "params":{"channel":"'+n+'", "message":'+_message+"}}",t.apply(this,arguments)},this.broadcast=function(){1==arguments.length?this.send(arguments[0],"sgc@broadcast",""):2==arguments.length&&this.send(arguments[0],"sgc@broadcast",arguments[1])},this.publish=function(){this.send(arguments[0],"sgc@publish",arguments[1],GUID())},this.subscribe=function(e){this.send("","sgc@subscribe",e,GUID())},this.unsubscribe=function(e){this.send("","sgc@unsubscribe",e,GUID())},this.rpc=function(e,s,c){arguments[0]='{"jsonrpc":"2.0", "method":"'+s+'", "params":"'+c+'", "id":"'+e+'"}',t.apply(this,arguments)},this.notify=function(e){arguments[0]='{"jsonrpc":"2.0", "method":"'+e+'", "params":""}',t.apply(this,arguments)},this.request=function(e){arguments[0]='{"jsonrpc":"2.0", "method":"'+e+'"}',t.apply(this,arguments)},this.getsession=function(){this.request("sgc@session")},this.starttransaction=function(e){void 0==e&&(e=""),this.send("","sgc@transaction",e,"")},this.commit=function(e){void 0==e&&(e=""),this.send("","sgc@commit",e,"")},this.rollback=function(e){void 0==e&&(e=""),this.send("","sgc@rollback",e,"")},this.pubrel=function(e){this.send("","sgc@pubrel","",e)};var c=new event("onsgcmessage"),o=new event("onsgcevent"),n=new event("onsgcsubscribe"),i=new event("onsgcunsubscribe"),r=new event("onsgcrpcresult"),u=new event("onsgcrpcerror"),g=new event("onsgcacknowledgment"),a=new event("onsgcpubrec"),b=new event("onsgcsession");DoEventMessage=function(e){var s=e.data;obj=JSON.parse(s),void 0!==obj.result?"sgc@subscribe"==obj.result.method?n.fire({name:"onsgcsubscribe",channel:obj.result.channel}):"sgc@unsubscribe"==obj.result.method?i.fire({name:"onsgcunsubscribe",channel:obj.result.channel}):"sgc@pubrec"==obj.result.method?a.fire({name:"onsgcpubrec",id:obj.id}):"sgc@event"==obj.result.method?o.fire({name:"onsgcevent",channel:obj.result.channel,message:obj.result.message}):"sgc@session"==obj.result.method?b.fire({name:"onsgcsession",guid:obj.result.message}):"sgc@message"==obj.result.method?c.fire({name:"onsgcmessage",message:obj.result.message}):"sgc@acknowledgment"==obj.result.method?g.fire({name:"onsgcacknowledgment",id:obj.id}):r.fire({name:"onsgcrpcresult",result:obj.result,id:obj.id}):void 0!==obj.error&&u.fire({name:"onsgcrpcerror",code:obj.error.code,message:obj.error.message,data:obj.error.data})};var l=this.on;this.on=function(e,s){"sgcmessage"==e?c.subscribe(s):"sgcevent"==e?o.subscribe(s):"sgcsession"==e?b.subscribe(s):"sgcsubscribe"==e?n.subscribe(s):"sgcunsubscribe"==e?i.subscribe(s):"sgcacknowledgment"==e?g.subscribe(s):"sgcpubrec"==e?a.subscribe(s):"sgcrpcresult"==e?r.subscribe(s):"sgcrpcerror"==e?u.subscribe(s):l.apply(this,arguments)}}}sgcws.prototype=new sgcWebSocket,sgcws.prototype.constructor=sgcws;