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.14 to 2.4.15

2

bower.json
{
"name": "sendbird",
"version": "2.4.14",
"version": "2.4.15",
"authors": [

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

@@ -5,2 +5,13 @@ Changelog

## v2.4.15
### update
* fixed `registerGCMToken` issues at after init.
* fixed `registerAPNSToken` issues at after init.
### add
* added `unregisterGCMToken`
* added `unregisterAPNSToken`
* [xhr2(>=0.1.3)](https://www.npmjs.com/package/xhr2) and [websocket(>=1.0.22)](https://www.npmjs.com/package/websocket) are required for compatibility when you are using node.js with npm.
## v2.4.14

@@ -7,0 +18,0 @@

{
"name": "sendbird",
"version": "2.4.14",
"version": "2.4.15",
"description": "SendBird JavaScript SDK",
"main": "SendBird.min.js",
"devDependencies": {
"summernote": ">=2.1.2"
"dependencies": {
"websocket": "^1.0.22",
"xhr2": "^0.1.3"
},

@@ -9,0 +10,0 @@ "scripts": {

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

## Upgrading to v2.4.14
## Upgrading to v2.4.15
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).
* adjust reconnect function
* fixed `registerGCMToken` issues at after init.
* fixed `registerAPNSToken` issues at after init.
* added `unregisterGCMToken`
* added `unregisterAPNSToken`
* [xhr2(>=0.1.3)](https://www.npmjs.com/package/xhr2) and [websocket(>=1.0.22)](https://www.npmjs.com/package/websocket) are required for compatibility when you are using node.js with npm.

@@ -36,0 +40,0 @@

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

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