-
Notifications
You must be signed in to change notification settings - Fork 55
/
presence.js
80 lines (70 loc) · 2.64 KB
/
presence.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import Utils from '../util/utils';
import EventEmitter from '../util/eventemitter';
import Logger from '../util/logger';
import Http from 'platform-http';
import PaginatedResource from './paginatedresource';
import PresenceMessage from '../types/presencemessage';
var Presence = (function() {
function noop() {}
function Presence(channel) {
this.channel = channel;
this.basePath = channel.basePath + '/presence';
}
Utils.inherits(Presence, EventEmitter);
Presence.prototype.get = function(params, callback) {
Logger.logAction(Logger.LOG_MICRO, 'Presence.get()', 'channel = ' + this.channel.name);
/* params and callback are optional; see if params contains the callback */
if(callback === undefined) {
if(typeof(params) == 'function') {
callback = params;
params = null;
} else {
if(this.channel.rest.options.promises) {
return Utils.promisify(this, 'get', arguments);
}
callback = noop;
}
}
var rest = this.channel.rest,
format = rest.options.useBinaryProtocol ? 'msgpack' : 'json',
envelope = Http.supportsLinkHeaders ? undefined : format,
headers = Utils.defaultGetHeaders(format);
if(rest.options.headers)
Utils.mixin(headers, rest.options.headers);
var options = this.channel.channelOptions;
(new PaginatedResource(rest, this.basePath, headers, envelope, function(body, headers, unpacked) {
return PresenceMessage.fromResponseBody(body, options, !unpacked && format);
})).get(params, callback);
};
Presence.prototype.history = function(params, callback) {
Logger.logAction(Logger.LOG_MICRO, 'Presence.history()', 'channel = ' + this.channel.name);
this._history(params, callback);
};
Presence.prototype._history = function(params, callback) {
/* params and callback are optional; see if params contains the callback */
if(callback === undefined) {
if(typeof(params) == 'function') {
callback = params;
params = null;
} else {
if(this.channel.rest.options.promises) {
return Utils.promisify(this, '_history', arguments);
}
callback = noop;
}
}
var rest = this.channel.rest,
format = rest.options.useBinaryProtocol ? 'msgpack' : 'json',
envelope = Http.supportsLinkHeaders ? undefined : format,
headers = Utils.defaultGetHeaders(format),
channel = this.channel;
if(rest.options.headers)
Utils.mixin(headers, rest.options.headers);
var options = this.channel.channelOptions;
(new PaginatedResource(rest, this.basePath + '/history', headers, envelope, function(body, headers, unpacked) {
return PresenceMessage.fromResponseBody(body, options, !unpacked && format);
})).get(params, callback);
};
return Presence;
})();
export default Presence;