-
Notifications
You must be signed in to change notification settings - Fork 0
/
yawsSocketConnect.min.js
1 lines (1 loc) · 2.51 KB
/
yawsSocketConnect.min.js
1
!function(){"use strict";"yaws"in window||(window.yaws={}),window.yaws.socketConnect=function(a,b,c){var d=function(a,b){if(!("Websocket"in window))throw"No Websocket Implementation found";var c=function(a,b){var c=function(a,b){return a&&"object"==typeof a&&b&&a[b]&&"number"==typeof a[b]},d={timeout:5e3,maxInterval:6e4};if(!c(a,b)){if(b in d)return d[b];throw"No default defined for "+b+"."}return parseInt(a[b],10)!==a[b]?parseInt(1e3*a[b],10):a[b]},d=function(a){var b=function(){if("protocol"in window.location&&"path"in window.location&&"domainname"in window.location)return{protocol:"ws"+("https"===window.location.protocol?"s":""),domain:window.location.domainname,path:window.location.path};var a={protocol:"ws"+(window.location.href.match(/^https:\/\//i)?"s":""),path:window.location.href.replace(/^https?:\/\/(.*?)(\?.*?)?(#.*?)?/i,"$1"),domain:""};return a.domain=a.path.replace(/\/.*/,"").replace(/:.*/,""),a.path=a.path.replace(/^.*?(\/|$)/,"$1"),a};a&&"string"==typeof a||(a="{protocol}://{domain}{path}");var c=b();return a.replace("{protocol}",c.protocol).replace("{path}",c.path).replace("{domain}",c.domain)};if("RobustWebSocket"in window){var e=new RobustWebSocket(d(a),[],{timeout:c(b,"timeout"),shouldReconnect:function(a,b){return 1008===a.code||1011===a.code?null:Math.min(500*Math.pow(1.05,(b.attempts+2)*b.attempts/2),b.maxInterval)}});return e.maxInterval=c(b,"maxInterval"),e}return"ReconnectingWebSocket"in window?new ReconnectingWebSocket(d(a),[],{maxReconnectInterval:c(b,"maxInterval"),reconnectDecay:2.5,timeoutInterval:c(b,"timeout")}):new Websocket(d(a),[])},e=function(){return"FileReader"in window?function(a){if("object"!=typeof a.data)throw"Got something ("+typeof a.data+") that shouldn't be returned by the socket.";if(a.data instanceof Blob)return void a.target.onMessageHandler(a.data);if(a.data instanceof ArrayBuffer){var b=new FileReader;return b.onLoadHandler=a.target.onMessageHandler,b.onload=function(a){a.target.onLoadHandler(a.target.result)},void b.readAsArrayBuffer(a.data)}throw"Got an object of a type that shouldn't be returned by the socket."}:function(a){if("object"!=typeof a.data)throw"Got something ("+typeof a.data+") that shouldn't be returned by the socket.";if(a.data instanceof Blob)return void a.target.onMessageHandler(a.data);throw"Got an object of a type that shouldn't be returned by the socket."}};if("function"!=typeof a)throw"The second parameter onMessage is required to be a function accepting a single parameter of type Blob.";var f=d(c,b);return f.onMessageHandler=a,f.onmessage=e(),f}}();