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.10 to 2.4.11

2

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

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

@@ -5,2 +5,12 @@ Changelog

## v2.4.11
### update
* undefined window bugfix
* adjust reconnect function
### add
* added `onReconnectFailed` event
## v2.4.10

@@ -7,0 +17,0 @@

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

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

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

## Upgrading to v2.4.10
## Upgrading to v2.4.11
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).
* bugfix: for react-native
* undefined window bugfix
* adjust reconnect function
* added `onReconnectFailed` event

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

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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