Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sendbird

Package Overview
Dependencies
Maintainers
1
Versions
226
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sendbird - npm Package Compare versions

Comparing version 2.4.11 to 2.4.12

2

bower.json
{
"name": "sendbird",
"version": "2.4.11",
"version": "2.4.12",
"authors": [

@@ -5,0 +5,0 @@ "SendBird <support@sendbird.com>"

@@ -5,2 +5,8 @@ Changelog

## v2.4.12
### update
* undefined navigator bugfix
## v2.4.11

@@ -7,0 +13,0 @@

{
"name": "sendbird",
"version": "2.4.11",
"version": "2.4.12",
"description": "SendBird JavaScript SDK",

@@ -5,0 +5,0 @@ "main": "SendBird.min.js",

@@ -30,8 +30,6 @@ SendBird-SDK-JavaScript

## Upgrading to v2.4.11
## Upgrading to v2.4.12
If you want to check the record of other version, go to [Change Log](https://github.com/smilefam/SendBird-SDK-JavaScript/blob/master/CHANGELOG.md).
* undefined window bugfix
* adjust reconnect function
* added `onReconnectFailed` event
* undefined navigator bugfix

@@ -38,0 +36,0 @@

/**
* SendBird JavaScript SDK v2.4.11
* SendBird JavaScript SDK v2.4.12
*/
!function(e,n){"function"==typeof define&&define.amd?define([],n().getInstance()):"object"==typeof exports?module.exports=n().getInstance():(e.SB=n(),e.sendbird=e.SB.getInstance())}(this,function(){function e(){try{if("undefined"==typeof navigator||"undefined"==typeof navigator.userAgent)return!1;var e=navigator.userAgent.toLowerCase();return-1!=e.indexOf("msie")?parseInt(e.split("msie")[1]):!1}catch(n){return!1}}function n(n,t,s,r,i,a){var o=new XMLHttpRequest,g=e();if(!("withCredentials"in o)&&g&&10>g){o=new XDomainRequest,o.withCredentials=!0;try{switch(s.toLowerCase()){case"get":o.open("GET",n);break;default:o.open("POST",n)}}catch(d){o.open("POST",n)}for(var p in r)t[p]=r[p];o.onload=function(){var e=JSON.parse(o.responseText);e.error?a(o.status,o.statusText):i(e)},o.onerror=function(){a(404,"There was a connection error")}}else{try{switch(o=new XMLHttpRequest,s.toLowerCase()){case"get":o.open("GET",n);break;default:o.open("POST",n)}o.onload=function(){if(o.status>=c&&o.status<u){var e=o.responseText;i(JSON.parse(e))}else a(o.status,o.statusText)},o.onerror=function(){a(404,"There was a connection error")}}catch(l){o=new ActiveXObject("Microsoft.XMLHTTP");try{switch(s.toLowerCase()){case"get":o.open("GET",n);break;default:o.open("POST",n)}}catch(d){o.open("POST",n)}o.onreadystatechange=function(){if(4==o.readyState)if(o.status>=c&&o.status<u){var e=o.responseText;i(JSON.parse(e))}else a(o.status,o.statusText)}}o.setRequestHeader("Content-Type","text/plain; charset=UTF-8");for(var p in r)t[p]=r[p]}switch(s.toLowerCase()){case"get":o.send();break;default:o.send(JSON.stringify(t))}}var t=!1,s=!1;try{var r=window.console||{log:function(){}}}catch(i){var r={log:function(){}}}var a=function(e){t&&r.log(e)},o=function(e){e=e||{};for(var n=arguments.length,t=1;n>t;t++)if(arguments[t])for(var s in arguments[t])arguments[t].hasOwnProperty(s)&&(e[s]=arguments[t][s]);return e};"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var c=200,u=400,g=function(){function e(){var e=new d;return e}var n,t=function(t){var s=o({},{newInstance:!1},t);return s.newInstance?e():(n||(n=e()),n)};return{getInstance:t}}(),d=function(){function e(e){return d(h+R.app_id),l+"v"+y.replace(/[^(0-9)]/gi,"")+"/"+e}function i(e){return d(h+R.app_id),l+"v3/"+e}function g(){_=3e3,m=5,v=0,a("=== Reset Reconnect Values ===")}function d(e,t,s){if(S)f="ws://localtest.me:9000",l="http://api.localtest.me:8000/","function"==typeof t&&t();else{var r=(new Date).getTime()/1e3;0==D||D-r>3?n(e,{},"GET",{SendBird:F+R.app_id},function(e){f=e.ws_server,l=e.api_server+"/",a("Routing Info Update: "+f+", "+l),D=r,"function"==typeof t&&t()},function(e,n){"function"==typeof s&&s(e,n)}):"function"==typeof t&&t()}}function p(e){R.app_id=e.app_id,R.guest_id=e.guest_id,R.user_name=e.user_name,R.image_url=void 0==e.image_url||null==e.image_url?"":e.image_url,R.access_token=void 0==e.access_token||null==e.access_token?"":e.access_token,H({successFunc:function(n){e.successFunc(n)},errorFunc:function(n,t){e.errorFunc(n,t)},async:e.async})}var l,f,_,m,v,S=!1,y="1",h="https://sbrouting.sendbird.com/app/",k="2.4.11",T="/?p=JS&pv="+encodeURI(navigator.userAgent)+"&sv="+k+"&ai=",F="JS,"+encodeURI(navigator.userAgent)+","+k+",",M=null,O={MESG:"MESG",FILE:"FILE",LOGI:"LOGI",JOIN:"JOIN",SYSM:"SYSM",BRDM:"BRDM",MCUP:"MCUP",READ:"READ",TPST:"TPST",TPEN:"TPEN",BAAN:"BAAN",FREZ:"FREZ",PING:"PING",PONG:"PONG"},R={},P={},N=0,w=0,b=null,I=null,C=null,E=0,L=!1,B=0,J=1e4,D=0;g();var G=function(e,n){switch(e){case O.MESG:x.onMessageReceived(JSON.parse(n));break;case O.SYSM:x.onSystemMessageReceived(JSON.parse(n));break;case O.FILE:x.onFileMessageReceived(JSON.parse(n));break;case O.BRDM:x.onBroadcastMessageReceived(JSON.parse(n));break;case O.TPST:x.onTypeStartReceived(JSON.parse(n));break;case O.TPEN:x.onTypeEndReceived(JSON.parse(n));break;case O.PONG:a(O.PONG);break;case O.READ:x.onReadReceived(JSON.parse(n));break;case O.BAAN:x.onBanReceived(JSON.parse(n));break;case O.FREZ:var t=JSON.parse(n),s=!1;try{s=t.freeze}catch(r){s=!1}P.data=JSON.stringify({freeze:s}),x.onChannelFreezeReceived(t);break;default:x.onUndefinedMessageReceived(e,JSON.parse(n))}return JSON.parse(n)},A={successFunc:function(e){},errorFunc:function(e,n){a(e),a(n)}},x={onMessageReceived:function(e){a(e)},onSystemMessageReceived:function(e){a(e)},onFileMessageReceived:function(e){a(e)},onBroadcastMessageReceived:function(e){a(e)},onReadReceived:function(e){a(e)},onMessagingChannelUpdateReceived:function(e){a(e)},onTypeStartReceived:function(e){a(e)},onTypeEndReceived:function(e){a(e)},onMessageDelivery:function(e){a(e)},onBanReceived:function(e){a(e)},onChannelFreezeReceived:function(e){a(e)},onUndefinedMessageReceived:function(e,n){a(e),a(n)},onReconnectFailed:function(){}},U=6,z=5,H=function(t){a("=== Start SendBird SDK ===");var s=o({},A,t),r="guest_login/",i={guest_id:R.guest_id,app_id:R.app_id,nickname:R.user_name,image_url:R.image_url,access_token:R.access_token};void 0!=R.gcm_reg_token&&""!=R.gcm_reg_token&&(i.gcm_reg_token=R.gcm_reg_token),void 0!=R.apns_device_token&&""!=R.apns_device_token&&(i.apns_device_token=R.apns_device_token),d(h+R.app_id,function(){n(e(r),i,"POST",{SendBird:F+R.app_id},function(e){e.error?s.errorFunc(c,e.message):(R.guest_key=e.key,s.successFunc({}))},function(e,n){s.errorFunc(e,n)})},function(e,n){s.errorFunc(e,n)})},W=function(t,s){a("=== Join Channel ===");var r=o({},A,s),i="channel_join/",u={app_id:R.app_id,session_key:R.guest_key,channel_url:t},g={};n(e(i),u,"POST",{SendBird:F+R.app_id},function(e){e.error?r.errorFunc(c,e.message):(e.isMessaging=!1,o(P,e),g=P,r.successFunc(g))},function(e,n){r.errorFunc(e,n)})},j=function(t,s){a("=== Leave Channel ===");var r=o({},A,s),i="channel_leave",u={app_id:R.app_id,session_key:R.guest_key,channel_url:t},g={};n(e(i),u,"POST",{SendBird:F+R.app_id},function(e){e.error?r.errorFunc(c,e.message):(g=e,r.successFunc(g))},function(e,n){r.errorFunc(e,n)})},q=function(t,s){a("=== Member List ===");var r=o({},A,s),i="member_list/",u={app_id:R.app_id,channel_url:t},g={};n(e(i),u,"POST",{SendBird:F+R.app_id},function(e){e.error?r.errorFunc(c,e.message):(g=e,r.successFunc(g))},function(e,n){r.errorFunc(e,n)})},X=function(t){a("=== Channel List ==="),t=o({},{limit:20,page:1,query:""},t);var s=o({},A,t),r="channel_list/",i={app_id:R.app_id,page:s.page,limit:s.limit,query:s.query},u={};n(e(r),i,"POST",{SendBird:F+R.app_id},function(e){e.error?s.errorFunc(c,e.message):(u=e,s.successFunc(u))},function(e,n){s.errorFunc(e,n)})},Y=function(e){X(e)},Z=function(e){return void 0!=e.last_message&&""!=e.last_message&&(e.last_message=JSON.parse(e.last_message.substring(4))),e},K=function(t,s){a("=== Join Messaging Channel ===");var r=o({},A,s),i="messaging_join/",u={app_id:R.app_id,session_key:R.guest_key,channel_url:t},g={};n(e(i),u,"POST",{SendBird:F+R.app_id},function(e){e.error?r.errorFunc(c,e.message):(e.channel.isMessaging=!0,o(P,e.channel),g=e,r.successFunc(Z(g)))},function(e,n){r.errorFunc(e,n)})},V=function(t,s){a("=== Start Messaging ==="),t=t instanceof Array?t:new Array(t);var r=o({},A,s),i="messaging_start/",u={app_id:R.app_id,session_key:R.guest_key,guest_ids:t},g={};n(e(i),u,"POST",{SendBird:F+R.app_id},function(e){e.error?r.errorFunc(c,e.message):(o(P,e.channel),g=e,r.successFunc(Z(g)))},function(e,n){r.errorFunc(e,n)})},$=function(e,n,t){if(2==arguments.length){var s=arguments[1].channel_url;void 0!=s&&""!=s||(s=P.channel_url),Q(arguments[0],s,arguments[1])}else Q(e,n,t)},Q=function(t,s,r){a("=== Invite Messaging ==="),t=t instanceof Array?t:new Array(t);var i=o({},A,r),u="messaging_invite/",g={app_id:R.app_id,session_key:R.guest_key,channel_url:s,guest_ids:t},d={};n(e(u),g,"POST",{SendBird:F+R.app_id},function(e){e.error?i.errorFunc(c,e.message):(o(P,e.channel),d=e,i.successFunc(Z(d)))},function(e,n){i.errorFunc(e,n)})},ee=function(t,s){a("=== End Messaging ===");var r=o({},A,s),i="messaging_end/",u={app_id:R.app_id,session_key:R.guest_key,channel_url:t},g={};n(e(i),u,"POST",{SendBird:F+R.app_id},function(e){e.error?r.errorFunc(c,e.message):(o(P,e),g=e,r.successFunc(Z(g)))},function(e,n){r.errorFunc(e,n)})},ne=function(t){a("=== Messaging Channel List ==="),t=o({},{limit:9999,page:1},t);var s=o({},A,t),r="messaging_list/",i={app_id:R.app_id,session_key:R.guest_key,page:s.page,limit:s.limit},u={};n(e(r),i,"POST",{SendBird:F+R.app_id},function(e){e.error?s.errorFunc(c,e.message):(u=e,u.channels.forEach(function(e,n){e=Z(e)}),s.successFunc(u))},function(e,n){s.errorFunc(e,n)})},te=function(e){a("=== Messaging Channel List ==="),e=o({},{limit:9999,page:1},e);var t=o({},A,e),s="messaging_list/",r={app_id:R.app_id,session_key:R.guest_key,page:t.page,limit:t.limit},u={};n(i(s),r,"POST",{SendBird:F+R.app_id},function(e){e.error?t.errorFunc(c,e.message):(u=e,u.channels.forEach(function(e,n){e=Z(e)}),t.successFunc(u))},function(e,n){t.errorFunc(e,n)})},se=function(t,s){a("=== Messaging Channel Info ===");var r=o({},A,s),i="messaging_info/",u={app_id:R.app_id,session_key:R.guest_key,channel_id:t};n(e(i),u,"POST",{SendBird:F+R.app_id},function(e){e.error?r.errorFunc(c,e.message):x.onMessagingChannelUpdateReceived(Z(e))},function(e,n){r.errorFunc(e,n)})},re=function(t,s){a("=== Message Mark As Read ===");var r=o({},A,s),i="mark_as_read/",u={app_id:R.app_id,session_key:R.guest_key,channel_url:t},g={};n(e(i),u,"POST",{SendBird:F+R.app_id},function(e){e.error?r.errorFunc(c,e.message):(g=e,r.successFunc(g))},function(e,n){r.errorFunc(e,n)})},ie=function(t){a("=== Message Load More ==="),t=o({},{limit:20},t);var s=o({},A,t),r=(new Date).getTime(),i="message_list",u={app_id:R.app_id,session_key:R.guest_key,channel_url:P.channel_url,message_ts:0==w?r:w,prev_limit:s.limit,next_limit:0,include:!1},g=[];n(e(i),u,"POST",{SendBird:F+R.app_id},function(e){e.error?s.errorFunc(c,e.message):(e.messages.forEach(function(e,n){var t=JSON.parse(e.substring(4));0==w?w=t.ts:w>t.ts&&(w=t.ts),g.push(Re(e))}),s.successFunc({messages:g}))},function(e,n){s.errorFunc(e,n)})},ae=function(t){a("=== User List ==="),t=o({},{token:"",page:1,limit:30},t);var s=o({},A,t),r="user_list/",i={app_id:R.app_id,session_key:R.guest_key,token:s.token,page:s.page,limit:s.limit};n(e(r),i,"POST",{SendBird:F+R.app_id},function(e){e.error?s.errorFunc(c,e.message):s.successFunc(e)},function(e,n){s.errorFunc(e,n)})},oe=function(e,n){a("=== Upload File ===");var t=o({},A,n),s="upload_file/",r='{"app_id": "'+R.app_id+'"}',i=new FormData;i.append("meta",r),i.append("file",e);var g="",d=l+"v"+y.replace(/[^(0-9)]/gi,"")+"/"+s,p=void 0==t.async?!0:t.async,f=new XMLHttpRequest;f.open("POST",d,p),f.onload=function(){if(f.status>=c&&f.status<u){var n=f.responseText,s=JSON.parse(n);s.error?t.errorFunc(c,s.message):(g={error:!1,url:s.url},Me({url:s.url,name:e.name,type:e.type,size:e.size,custom:""}),t.successFunc(g))}else t.errorFunc(f.status,f.statusText)},f.send(i)},ce=function(){a("=== Typing Start ===");var e=(new Date).getTime();ve(O.TPST,{channel_id:P.id,time:e}),B=e,L=!0},ue=function(){a("=== Typing End ===");var e=(new Date).getTime();ve(O.TPEN,{channel_id:P.id,time:e}),B=0,L=!1},ge=(setInterval(function(){var e=(new Date).getTime();L&&e-B>J&&ue()},J),function(t,s){a("=== Delete Message ===");var r=o({},A,s),i="message_delete/",u={app_id:R.app_id,session_key:R.guest_key,msg_id:t};n(e(i),u,"POST",{SendBird:F+R.app_id},function(e){e.error?r.errorFunc(c,e.message):r.successFunc(e)},function(e,n){r.errorFunc(e,n)})}),de=function(e){a("=== Web Socket Connect to Server ==="),_e();var n=o({},A,e);try{M=new WebSocket(f+T+R.app_id+"&key="+R.guest_key)}catch(t){r.log(t)}M.onopen=function(e){a("=== Web Socket Connected ==="),g(),Se(R.guest_key);var t=(new Date).getTime();if(void 0===P.id||ye(P.id,t)){var s={};n.successFunc(s)}else n.errorFunc(u,"WebSocket is not connected yet.");ke(!0)},M.onmessage=function(e){N=(new Date).getTime();for(var n=e.data.split("\n"),t=0;t<n.length;t++)if(0!=n[t].trim().length){var s=n[t].substring(0,4),r=n[t].substring(4);if(0!==s.trim().length||0!==r.trim().length)if(s==O.MCUP){var i=JSON.parse(r);se(i.channel_id)}else G(s,r)}},M.onerror=function(e){a("=== Web Socket onerror ==="),a(e)},M.onclose=function(e){a("=== Web Socket onclose ==="),a(e),s||le(),ke(!1)}},pe=function(e){"undefined"==typeof e?(s=!0,ke(!1)):s=e,a("=== Web Socket Disconnect ==="),fe()},le=function(){s!==!0&&(null==C?m>v?(a("=== Start Reconnect (After "+(_/1e3).toString()+" Seconds) ==="),C=setTimeout(function(){v++,_*=2,de(),C=null,a("=== Reconnect done: "+v.toString()+" ===")},_)):(x.onReconnectFailed(),a("=== Stop Reconnect ===")):a("=== Reconnect is in progress. (skip) ==="))},fe=function(){M&&_e(),P={},w=0;try{clearInterval(b),a("=== clearInterval: pingHandler ===")}catch(e){a("=== clearInterval fail: pingHandler ===")}b=null;try{clearTimeout(C),a("=== clearTimeout: retryHandler ===")}catch(e){a("=== clearTimeout fail: retryHandler ===")}C=null,E=0},_e=function(){M&&(M.close(),M.onmessage=function(e){},M.onopen=function(e){},M.onerror=function(e){},M.onclose=function(e){},M=null),w=0},me=function(){return M?M.readyState:WebSocket.CLOSED},ve=function(e,n){var t=e+JSON.stringify(n)+"\n";try{if(1!=M.readyState)return!1;M.send(t)}catch(s){return a(s),!1}return!0},Se=function(e){ve(O.LOGI,{key:e})},ye=function(e,n){return ve(O.JOIN,{channel_id:e,last_ts:n})},he=function(){var e=(new Date).getTime();E=e,ve(O.PING,{id:e})},ke=function(e){null!=b&&(clearInterval(b),b=null),e?(a("=== Start Pinger ==="),b=setInterval(function(){var e=(new Date).getTime(),n=e-N,t=parseInt(n/1e3);t>0&&t%15==0&&(a(O.PING),he(),clearTimeout(I),I=setTimeout(function(){var e=(new Date).getTime(),n=e-N,t=parseInt(n/1e3);t>=20&&(a("=== PING Timeout, Try Reconnect ==="),ke(!1),le())},6e3))},1e3)):a("=== Stop Pinger ===")},Te=function(e,n){"string"!=typeof e&&(e=e.toString()),n=n||"","string"!=typeof n&&(n=n.toString());var t=ve(O.MESG,{channel_id:P.id,message:e,data:"",tid:n});x.onMessageDelivery({sent:t,message:e,data:"",id:n}),t&&P.isMessaging&&setTimeout(function(){ue()},100)},Fe=function(e,n,t){"string"!=typeof e&&(e=e.toString()),t=t||"","string"!=typeof t&&(t=t.toString());var s=ve(O.MESG,{channel_id:P.id,message:e,data:n,tid:t});x.onMessageDelivery({sent:s,message:e,data:n,tid:t}),s&&P.isMessaging&&setTimeout(function(){ue()},100)},Me=function(e){ve(O.FILE,{channel_id:P.id,name:e.name,url:e.url,type:e.type,size:e.size,custom:e.custom})},Oe=function(e){t=e},Re=function(e){var n=e.substring(0,4),t=JSON.parse(e.substring(4));return{cmd:n,payload:t}},Pe=function(e){return e==O.MESG},Ne=function(e){return e==O.FILE},we=function(e){var n=e.url.split("."),t=n[n.length-1];return"png"==t||"jpeg"==t||"jpg"==t||"gif"==t||"bmp"==t?!0:e.type.indexOf("image")>=0},be=function(e){return e==U},Ie=function(e){return e==z},Ce=function(e){var n=!1;try{n=JSON.parse(P.data).freeze}catch(t){n=!1}e({channel_url:P.channel_url,cover_img_url:P.cover_img_url,member_count:P.member_count,name:P.name,isMessaging:P.isMessaging,max_length_message:P.max_length_message,freeze:n})},Ee=function(e){e({guest_id:R.guest_id,image_url:R.image_url,nickname:R.user_name})},Le=function(e){R.gcm_reg_token=e},Be=function(e){R.apns_device_token=e},Je="[version] "+k,De=function(e){w="string"==typeof e?parseInt(e):e};return{version:Je,events:x,joinChannel:W,leaveChannel:j,getMemberList:q,getChannelSearch:X,getChannelList:Y,joinMessagingChannel:K,startMessaging:V,inviteMessaging:$,endMessaging:ee,getMessagingChannelList:ne,getPrivateChannelList:te,markAsRead:re,getMessageLoadMore:ie,getUserList:ae,sendFile:oe,typeStart:ce,typeEnd:ue,deleteMessage:ge,connect:de,disconnect:pe,message:Te,messageWithData:Fe,sendFileURL:Me,setDebugMessage:Oe,isMessage:Pe,isFileMessage:Ne,hasImage:we,isGroupMessaging:be,isGroupMessagingChannel:be,isMessagingChannel:Ie,getChannelInfo:Ce,getUserInfo:Ee,getConnectionState:me,registerGCMToken:Le,registerAPNSToken:Be,init:p,setMinMessageTs:De}};return g});
!function(e,n){"function"==typeof define&&define.amd?define([],n().getInstance()):"object"==typeof exports?module.exports=n().getInstance():(e.SB=n(),e.sendbird=e.SB.getInstance())}(this,function(){function e(){try{if("undefined"==typeof navigator||"undefined"==typeof navigator.userAgent)return!1;var e=navigator.userAgent.toLowerCase();return-1!=e.indexOf("msie")?parseInt(e.split("msie")[1]):!1}catch(n){return!1}}function n(n,t,s,r,i,a){var o=new XMLHttpRequest,g=e();if(!("withCredentials"in o)&&g&&10>g){o=new XDomainRequest,o.withCredentials=!0;try{switch(s.toLowerCase()){case"get":o.open("GET",n);break;default:o.open("POST",n)}}catch(d){o.open("POST",n)}for(var p in r)t[p]=r[p];o.onload=function(){var e=JSON.parse(o.responseText);e.error?a(o.status,o.statusText):i(e)},o.onerror=function(){a(404,"There was a connection error")}}else{try{switch(o=new XMLHttpRequest,s.toLowerCase()){case"get":o.open("GET",n);break;default:o.open("POST",n)}o.onload=function(){if(o.status>=c&&o.status<u){var e=o.responseText;i(JSON.parse(e))}else a(o.status,o.statusText)},o.onerror=function(){a(404,"There was a connection error")}}catch(l){o=new ActiveXObject("Microsoft.XMLHTTP");try{switch(s.toLowerCase()){case"get":o.open("GET",n);break;default:o.open("POST",n)}}catch(d){o.open("POST",n)}o.onreadystatechange=function(){if(4==o.readyState)if(o.status>=c&&o.status<u){var e=o.responseText;i(JSON.parse(e))}else a(o.status,o.statusText)}}o.setRequestHeader("Content-Type","text/plain; charset=UTF-8");for(var p in r)t[p]=r[p]}switch(s.toLowerCase()){case"get":o.send();break;default:o.send(JSON.stringify(t))}}var t=!1,s=!1;try{var r=window.console||{log:function(){}}}catch(i){var r={log:function(){}}}var a=function(e){t&&r.log(e)},o=function(e){e=e||{};for(var n=arguments.length,t=1;n>t;t++)if(arguments[t])for(var s in arguments[t])arguments[t].hasOwnProperty(s)&&(e[s]=arguments[t][s]);return e};"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var c=200,u=400,g=function(){function e(){var e=new d;return e}var n,t=function(t){var s=o({},{newInstance:!1},t);return s.newInstance?e():(n||(n=e()),n)};return{getInstance:t}}(),d=function(){function e(e){return d(v+N.app_id),l+"v"+m.replace(/[^(0-9)]/gi,"")+"/"+e}function i(e){return d(v+N.app_id),l+"v3/"+e}function g(){k=3e3,T=5,F=0,a("=== Reset Reconnect Values ===")}function d(e,t,s){if(_)f="ws://localtest.me:9000",l="http://api.localtest.me:8000/","function"==typeof t&&t();else{var r=(new Date).getTime()/1e3;0==A||A-r>3?n(e,{},"GET",{SendBird:O+N.app_id},function(e){f=e.ws_server,l=e.api_server+"/",a("Routing Info Update: "+f+", "+l),A=r,"function"==typeof t&&t()},function(e,n){"function"==typeof s&&s(e,n)}):"function"==typeof t&&t()}}function p(e){N.app_id=e.app_id,N.guest_id=e.guest_id,N.user_name=e.user_name,N.image_url=void 0==e.image_url||null==e.image_url?"":e.image_url,N.access_token=void 0==e.access_token||null==e.access_token?"":e.access_token,j({successFunc:function(n){e.successFunc(n)},errorFunc:function(n,t){e.errorFunc(n,t)},async:e.async})}var l,f,_=!1,m="1",v="https://sbrouting.sendbird.com/app/",S="2.4.12";try{var y=encodeURI(navigator.userAgent)}catch(h){var y="undefined"}var k,T,F,M="/?p=JS&pv="+y+"&sv="+S+"&ai=",O="JS,"+y+","+S+",",R=null,P={MESG:"MESG",FILE:"FILE",LOGI:"LOGI",JOIN:"JOIN",SYSM:"SYSM",BRDM:"BRDM",MCUP:"MCUP",READ:"READ",TPST:"TPST",TPEN:"TPEN",BAAN:"BAAN",FREZ:"FREZ",PING:"PING",PONG:"PONG"},N={},w={},b=0,I=0,C=null,E=null,L=null,B=0,J=!1,D=0,G=1e4,A=0;g();var x=function(e,n){switch(e){case P.MESG:z.onMessageReceived(JSON.parse(n));break;case P.SYSM:z.onSystemMessageReceived(JSON.parse(n));break;case P.FILE:z.onFileMessageReceived(JSON.parse(n));break;case P.BRDM:z.onBroadcastMessageReceived(JSON.parse(n));break;case P.TPST:z.onTypeStartReceived(JSON.parse(n));break;case P.TPEN:z.onTypeEndReceived(JSON.parse(n));break;case P.PONG:a(P.PONG);break;case P.READ:z.onReadReceived(JSON.parse(n));break;case P.BAAN:z.onBanReceived(JSON.parse(n));break;case P.FREZ:var t=JSON.parse(n),s=!1;try{s=t.freeze}catch(r){s=!1}w.data=JSON.stringify({freeze:s}),z.onChannelFreezeReceived(t);break;default:z.onUndefinedMessageReceived(e,JSON.parse(n))}return JSON.parse(n)},U={successFunc:function(e){},errorFunc:function(e,n){a(e),a(n)}},z={onMessageReceived:function(e){a(e)},onSystemMessageReceived:function(e){a(e)},onFileMessageReceived:function(e){a(e)},onBroadcastMessageReceived:function(e){a(e)},onReadReceived:function(e){a(e)},onMessagingChannelUpdateReceived:function(e){a(e)},onTypeStartReceived:function(e){a(e)},onTypeEndReceived:function(e){a(e)},onMessageDelivery:function(e){a(e)},onBanReceived:function(e){a(e)},onChannelFreezeReceived:function(e){a(e)},onUndefinedMessageReceived:function(e,n){a(e),a(n)},onReconnectFailed:function(){}},H=6,W=5,j=function(t){a("=== Start SendBird SDK ===");var s=o({},U,t),r="guest_login/",i={guest_id:N.guest_id,app_id:N.app_id,nickname:N.user_name,image_url:N.image_url,access_token:N.access_token};void 0!=N.gcm_reg_token&&""!=N.gcm_reg_token&&(i.gcm_reg_token=N.gcm_reg_token),void 0!=N.apns_device_token&&""!=N.apns_device_token&&(i.apns_device_token=N.apns_device_token),d(v+N.app_id,function(){n(e(r),i,"POST",{SendBird:O+N.app_id},function(e){e.error?s.errorFunc(c,e.message):(N.guest_key=e.key,s.successFunc({}))},function(e,n){s.errorFunc(e,n)})},function(e,n){s.errorFunc(e,n)})},q=function(t,s){a("=== Join Channel ===");var r=o({},U,s),i="channel_join/",u={app_id:N.app_id,session_key:N.guest_key,channel_url:t},g={};n(e(i),u,"POST",{SendBird:O+N.app_id},function(e){e.error?r.errorFunc(c,e.message):(e.isMessaging=!1,o(w,e),g=w,r.successFunc(g))},function(e,n){r.errorFunc(e,n)})},X=function(t,s){a("=== Leave Channel ===");var r=o({},U,s),i="channel_leave",u={app_id:N.app_id,session_key:N.guest_key,channel_url:t},g={};n(e(i),u,"POST",{SendBird:O+N.app_id},function(e){e.error?r.errorFunc(c,e.message):(g=e,r.successFunc(g))},function(e,n){r.errorFunc(e,n)})},Y=function(t,s){a("=== Member List ===");var r=o({},U,s),i="member_list/",u={app_id:N.app_id,channel_url:t},g={};n(e(i),u,"POST",{SendBird:O+N.app_id},function(e){e.error?r.errorFunc(c,e.message):(g=e,r.successFunc(g))},function(e,n){r.errorFunc(e,n)})},Z=function(t){a("=== Channel List ==="),t=o({},{limit:20,page:1,query:""},t);var s=o({},U,t),r="channel_list/",i={app_id:N.app_id,page:s.page,limit:s.limit,query:s.query},u={};n(e(r),i,"POST",{SendBird:O+N.app_id},function(e){e.error?s.errorFunc(c,e.message):(u=e,s.successFunc(u))},function(e,n){s.errorFunc(e,n)})},K=function(e){Z(e)},V=function(e){return void 0!=e.last_message&&""!=e.last_message&&(e.last_message=JSON.parse(e.last_message.substring(4))),e},$=function(t,s){a("=== Join Messaging Channel ===");var r=o({},U,s),i="messaging_join/",u={app_id:N.app_id,session_key:N.guest_key,channel_url:t},g={};n(e(i),u,"POST",{SendBird:O+N.app_id},function(e){e.error?r.errorFunc(c,e.message):(e.channel.isMessaging=!0,o(w,e.channel),g=e,r.successFunc(V(g)))},function(e,n){r.errorFunc(e,n)})},Q=function(t,s){a("=== Start Messaging ==="),t=t instanceof Array?t:new Array(t);var r=o({},U,s),i="messaging_start/",u={app_id:N.app_id,session_key:N.guest_key,guest_ids:t},g={};n(e(i),u,"POST",{SendBird:O+N.app_id},function(e){e.error?r.errorFunc(c,e.message):(o(w,e.channel),g=e,r.successFunc(V(g)))},function(e,n){r.errorFunc(e,n)})},ee=function(e,n,t){if(2==arguments.length){var s=arguments[1].channel_url;void 0!=s&&""!=s||(s=w.channel_url),ne(arguments[0],s,arguments[1])}else ne(e,n,t)},ne=function(t,s,r){a("=== Invite Messaging ==="),t=t instanceof Array?t:new Array(t);var i=o({},U,r),u="messaging_invite/",g={app_id:N.app_id,session_key:N.guest_key,channel_url:s,guest_ids:t},d={};n(e(u),g,"POST",{SendBird:O+N.app_id},function(e){e.error?i.errorFunc(c,e.message):(o(w,e.channel),d=e,i.successFunc(V(d)))},function(e,n){i.errorFunc(e,n)})},te=function(t,s){a("=== End Messaging ===");var r=o({},U,s),i="messaging_end/",u={app_id:N.app_id,session_key:N.guest_key,channel_url:t},g={};n(e(i),u,"POST",{SendBird:O+N.app_id},function(e){e.error?r.errorFunc(c,e.message):(o(w,e),g=e,r.successFunc(V(g)))},function(e,n){r.errorFunc(e,n)})},se=function(t){a("=== Messaging Channel List ==="),t=o({},{limit:9999,page:1},t);var s=o({},U,t),r="messaging_list/",i={app_id:N.app_id,session_key:N.guest_key,page:s.page,limit:s.limit},u={};n(e(r),i,"POST",{SendBird:O+N.app_id},function(e){e.error?s.errorFunc(c,e.message):(u=e,u.channels.forEach(function(e,n){e=V(e)}),s.successFunc(u))},function(e,n){s.errorFunc(e,n)})},re=function(e){a("=== Messaging Channel List ==="),e=o({},{limit:9999,page:1},e);var t=o({},U,e),s="messaging_list/",r={app_id:N.app_id,session_key:N.guest_key,page:t.page,limit:t.limit},u={};n(i(s),r,"POST",{SendBird:O+N.app_id},function(e){e.error?t.errorFunc(c,e.message):(u=e,u.channels.forEach(function(e,n){e=V(e)}),t.successFunc(u))},function(e,n){t.errorFunc(e,n)})},ie=function(t,s){a("=== Messaging Channel Info ===");var r=o({},U,s),i="messaging_info/",u={app_id:N.app_id,session_key:N.guest_key,channel_id:t};n(e(i),u,"POST",{SendBird:O+N.app_id},function(e){e.error?r.errorFunc(c,e.message):z.onMessagingChannelUpdateReceived(V(e))},function(e,n){r.errorFunc(e,n)})},ae=function(t,s){a("=== Message Mark As Read ===");var r=o({},U,s),i="mark_as_read/",u={app_id:N.app_id,session_key:N.guest_key,channel_url:t},g={};n(e(i),u,"POST",{SendBird:O+N.app_id},function(e){e.error?r.errorFunc(c,e.message):(g=e,r.successFunc(g))},function(e,n){r.errorFunc(e,n)})},oe=function(t){a("=== Message Load More ==="),t=o({},{limit:20},t);var s=o({},U,t),r=(new Date).getTime(),i="message_list",u={app_id:N.app_id,session_key:N.guest_key,channel_url:w.channel_url,message_ts:0==I?r:I,prev_limit:s.limit,next_limit:0,include:!1},g=[];n(e(i),u,"POST",{SendBird:O+N.app_id},function(e){e.error?s.errorFunc(c,e.message):(e.messages.forEach(function(e,n){var t=JSON.parse(e.substring(4));0==I?I=t.ts:I>t.ts&&(I=t.ts),g.push(Ne(e))}),s.successFunc({messages:g}))},function(e,n){s.errorFunc(e,n)})},ce=function(t){a("=== User List ==="),t=o({},{token:"",page:1,limit:30},t);var s=o({},U,t),r="user_list/",i={app_id:N.app_id,session_key:N.guest_key,token:s.token,page:s.page,limit:s.limit};n(e(r),i,"POST",{SendBird:O+N.app_id},function(e){e.error?s.errorFunc(c,e.message):s.successFunc(e)},function(e,n){s.errorFunc(e,n)})},ue=function(e,n){a("=== Upload File ===");var t=o({},U,n),s="upload_file/",r='{"app_id": "'+N.app_id+'"}',i=new FormData;i.append("meta",r),i.append("file",e);var g="",d=l+"v"+m.replace(/[^(0-9)]/gi,"")+"/"+s,p=void 0==t.async?!0:t.async,f=new XMLHttpRequest;f.open("POST",d,p),f.onload=function(){if(f.status>=c&&f.status<u){var n=f.responseText,s=JSON.parse(n);s.error?t.errorFunc(c,s.message):(g={error:!1,url:s.url},Re({url:s.url,name:e.name,type:e.type,size:e.size,custom:""}),t.successFunc(g))}else t.errorFunc(f.status,f.statusText)},f.send(i)},ge=function(){a("=== Typing Start ===");var e=(new Date).getTime();ye(P.TPST,{channel_id:w.id,time:e}),D=e,J=!0},de=function(){a("=== Typing End ===");var e=(new Date).getTime();ye(P.TPEN,{channel_id:w.id,time:e}),D=0,J=!1},pe=(setInterval(function(){var e=(new Date).getTime();J&&e-D>G&&de()},G),function(t,s){a("=== Delete Message ===");var r=o({},U,s),i="message_delete/",u={app_id:N.app_id,session_key:N.guest_key,msg_id:t};n(e(i),u,"POST",{SendBird:O+N.app_id},function(e){e.error?r.errorFunc(c,e.message):r.successFunc(e)},function(e,n){r.errorFunc(e,n)})}),le=function(e){a("=== Web Socket Connect to Server ==="),ve();var n=o({},U,e);try{R=new WebSocket(f+M+N.app_id+"&key="+N.guest_key)}catch(t){r.log(t)}R.onopen=function(e){a("=== Web Socket Connected ==="),g(),he(N.guest_key);var t=(new Date).getTime();if(void 0===w.id||ke(w.id,t)){var s={};n.successFunc(s)}else n.errorFunc(u,"WebSocket is not connected yet.");Fe(!0)},R.onmessage=function(e){b=(new Date).getTime();for(var n=e.data.split("\n"),t=0;t<n.length;t++)if(0!=n[t].trim().length){var s=n[t].substring(0,4),r=n[t].substring(4);if(0!==s.trim().length||0!==r.trim().length)if(s==P.MCUP){var i=JSON.parse(r);ie(i.channel_id)}else x(s,r)}},R.onerror=function(e){a("=== Web Socket onerror ==="),a(e)},R.onclose=function(e){a("=== Web Socket onclose ==="),a(e),s||_e(),Fe(!1)}},fe=function(e){"undefined"==typeof e?(s=!0,Fe(!1)):s=e,a("=== Web Socket Disconnect ==="),me()},_e=function(){s!==!0&&(null==L?T>F?(a("=== Start Reconnect (After "+(k/1e3).toString()+" Seconds) ==="),L=setTimeout(function(){F++,k*=2,le(),L=null,a("=== Reconnect done: "+F.toString()+" ===")},k)):(z.onReconnectFailed(),a("=== Stop Reconnect ===")):a("=== Reconnect is in progress. (skip) ==="))},me=function(){R&&ve(),w={},I=0;try{clearInterval(C),a("=== clearInterval: pingHandler ===")}catch(e){a("=== clearInterval fail: pingHandler ===")}C=null;try{clearTimeout(L),a("=== clearTimeout: retryHandler ===")}catch(e){a("=== clearTimeout fail: retryHandler ===")}L=null,B=0},ve=function(){R&&(R.close(),R.onmessage=function(e){},R.onopen=function(e){},R.onerror=function(e){},R.onclose=function(e){},R=null),I=0},Se=function(){return R?R.readyState:WebSocket.CLOSED},ye=function(e,n){var t=e+JSON.stringify(n)+"\n";try{if(1!=R.readyState)return!1;R.send(t)}catch(s){return a(s),!1}return!0},he=function(e){ye(P.LOGI,{key:e})},ke=function(e,n){return ye(P.JOIN,{channel_id:e,last_ts:n})},Te=function(){var e=(new Date).getTime();B=e,ye(P.PING,{id:e})},Fe=function(e){null!=C&&(clearInterval(C),C=null),e?(a("=== Start Pinger ==="),C=setInterval(function(){var e=(new Date).getTime(),n=e-b,t=parseInt(n/1e3);t>0&&t%15==0&&(a(P.PING),Te(),clearTimeout(E),E=setTimeout(function(){var e=(new Date).getTime(),n=e-b,t=parseInt(n/1e3);t>=20&&(a("=== PING Timeout, Try Reconnect ==="),Fe(!1),_e())},6e3))},1e3)):a("=== Stop Pinger ===")},Me=function(e,n){"string"!=typeof e&&(e=e.toString()),n=n||"","string"!=typeof n&&(n=n.toString());var t=ye(P.MESG,{channel_id:w.id,message:e,data:"",tid:n});z.onMessageDelivery({sent:t,message:e,data:"",id:n}),t&&w.isMessaging&&setTimeout(function(){de()},100)},Oe=function(e,n,t){"string"!=typeof e&&(e=e.toString()),t=t||"","string"!=typeof t&&(t=t.toString());var s=ye(P.MESG,{channel_id:w.id,message:e,data:n,tid:t});z.onMessageDelivery({sent:s,message:e,data:n,tid:t}),s&&w.isMessaging&&setTimeout(function(){de()},100)},Re=function(e){ye(P.FILE,{channel_id:w.id,name:e.name,url:e.url,type:e.type,size:e.size,custom:e.custom})},Pe=function(e){t=e},Ne=function(e){var n=e.substring(0,4),t=JSON.parse(e.substring(4));return{cmd:n,payload:t}},we=function(e){return e==P.MESG},be=function(e){return e==P.FILE},Ie=function(e){var n=e.url.split("."),t=n[n.length-1];return"png"==t||"jpeg"==t||"jpg"==t||"gif"==t||"bmp"==t?!0:e.type.indexOf("image")>=0},Ce=function(e){return e==H},Ee=function(e){return e==W},Le=function(e){var n=!1;try{n=JSON.parse(w.data).freeze}catch(t){n=!1}e({channel_url:w.channel_url,cover_img_url:w.cover_img_url,member_count:w.member_count,name:w.name,isMessaging:w.isMessaging,max_length_message:w.max_length_message,freeze:n})},Be=function(e){e({guest_id:N.guest_id,image_url:N.image_url,nickname:N.user_name})},Je=function(e){N.gcm_reg_token=e},De=function(e){N.apns_device_token=e},Ge="[version] "+S,Ae=function(e){I="string"==typeof e?parseInt(e):e};return{version:Ge,events:z,joinChannel:q,leaveChannel:X,getMemberList:Y,getChannelSearch:Z,getChannelList:K,joinMessagingChannel:$,startMessaging:Q,inviteMessaging:ee,endMessaging:te,getMessagingChannelList:se,getPrivateChannelList:re,markAsRead:ae,getMessageLoadMore:oe,getUserList:ce,sendFile:ue,typeStart:ge,typeEnd:de,deleteMessage:pe,connect:le,disconnect:fe,message:Me,messageWithData:Oe,sendFileURL:Re,setDebugMessage:Pe,isMessage:we,isFileMessage:be,hasImage:Ie,isGroupMessaging:Ce,isGroupMessagingChannel:Ce,isMessagingChannel:Ee,getChannelInfo:Le,getUserInfo:Be,getConnectionState:Se,registerGCMToken:Je,registerAPNSToken:De,init:p,setMinMessageTs:Ae}};return g});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc