Skip to content

Instantly share code, notes, and snippets.

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