-
Notifications
You must be signed in to change notification settings - Fork 330
/
index.js
107 lines (94 loc) · 2.75 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*!
* Copyright (c) 2015-2018 Cisco Systems, Inc. See LICENSE file.
*/
import {StatelessSparkPlugin} from '@ciscospark/spark-core';
import {
MEETINGS,
_MEETING_LINK_,
_SIP_URI_
} from '../constants';
import MeetingInfoCollection from './collection';
import MeetingInfoRequest from './request';
import MeetingInfoUtil from './util';
/**
* @class MeetingInfo
*/
export default class MeetingInfo extends StatelessSparkPlugin {
namespace = MEETINGS;
/**
*
* @param {Object} attrs
* @param {Object} options
*/
constructor(attrs, options) {
super({}, options);
this.meetingInfoRequest = new MeetingInfoRequest({}, options);
this.meetingInfoCollection = new MeetingInfoCollection();
}
/**
* @param {string} id
* @returns {object}
* @public
* @memberof MeetingInfo
*/
getMeetingInfo(id) {
return this.meetingInfoCollection.get(id);
}
/**
* @param {string} id
* @param {object} info
* @returns {null}
* @public
* @memberof MeetingInfo
*/
setMeetingInfo(id, info) {
this.meetingInfoCollection.set(id, info);
}
/**
* Helper to make the actual MeetingInfo request and set the meetingInfo if successful, else reject
* @param {Object} options
* @returns {Promise}
* @private
*/
requestFetchInfo(options) {
return this.meetingInfoRequest.fetchMeetingInfo(options).then((info) => {
if (info && info.body) {
this.setMeetingInfo(info.body.sipMeetingUri || info.body.meetingLink, info.body);
}
return info;
}).catch((error) => Promise.reject(error));
}
/**
* Helper to generate the options for the MeetingInfo request
* @param {String} destination
* @param {String} type
* @returns {Object}
* @private
*/
fetchInfoOptions(destination, type) {
return MeetingInfoUtil.generateOptions({
destination,
type,
conversationServiceUrl: this.spark.internal.device.services.conversationServiceUrl
});
}
/**
* Fetches meeting info from the server
* @param {String} destination one of many different types of destinations to look up info for
* @param {String} type optional type to match up with the destination value
* @returns {Promise} returns a meeting info object
* @public
*/
fetchMeetingInfo(destination, type = null) {
const options = this.fetchInfoOptions(destination, type);
// fetch meeting info
return this.requestFetchInfo(options).catch((error) => {
// if it failed the first time as meeting link
if (options.type === _MEETING_LINK_) {
// convert the meeting link to sip URI and retry
return this.requestFetchInfo(this.fetchInfoOptions(MeetingInfoUtil.convertLinkToSip(destination), _SIP_URI_));
}
return Promise.reject(error);
});
}
}