The Webex Recents Widget allows developers to easily incorporate Cisco Webex (formerly Cisco Spark) Recents list and events into an application.
This widget handles coordination between your application and the Webex APIs, and provides components of the Webex recents list experience without having to build all of the front end UI yourself. Furthermore, the widget functions as a central point of contact for all other widgets by providing a robust events api that allows a developer to listen to realtime events on the Webex platform and react to those events.
Our widget is built using React, Redux, and the Webex JavaScript SDK.
This widget supports:
- Listing all Spaces that the authenticated user is in.
- Listening for incoming messages, calls, and membership events and provided those details to the developer.
Depending on how comfortable you are with these frameworks, there are are a number of ways you can "install" our code.
If you haven't already, go to Cisco Webex for Developers and sign up for an account. Once you've created an account you can get your developer access token here.
When you want to eventually create an integration and have your own users take advantage of the widget, you'll need to create an integration with the following scopes:
spark:all
Head over to the Webex for Developers Documentation for more information about how to setup OAuth for your app: https://developer.webex.com/docs/integrations
Using our CDN requires the least amount of work to get started. Add the following into your HTML file:
<!-- Production compiled and minified CSS -->
<link rel="stylesheet" href="https://code.s4d.io/widget-recents/production/main.css">
<!-- Production compiled and minified JavaScript -->
<script src="https://code.s4d.io/widget-recents/production/bundle.js"></script>
For the latest builds that are pulled from the head of the master branch:
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://code.s4d.io/widget-recents/latest/main.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://code.s4d.io/widget-recents/latest/bundle.js"></script>
-
Follow these instructions to checkout and build the
react-widgets
repo https://github.com/webex/react-widgets/blob/master/README.md -
To build the Recents Widget, run the following from the root directory:
npm run build:package widget-recents
To use the space widget within an existing React appliction, a developer can install the component directly from npm.
- Install the module via NPM
npm install --save @webex/widget-recents
- Add the following import statements
import RecentsWidget from '@webex/widget-recents';
// Sass import required for styling widgets
import '@webex/widget-recents/src/momentum.scss';
- Finally, render the widget
<RecentsWidget accessToken='XXXXXXXXXXXXXX' />
All of the React configurable properties are listed in the "Configuration" section.
If you are developing an application that makes use of our Webex SDK in addition to the widgets, some additional configuration is needed.
In order for the Webex Recents Widget to function in a project that is already using the Webex SDK via npm, the versions of the SDK must match specifically.
Any "@webex" packages that are added to your project manually need to match the versions in the widgets' package.json file.
If you would just like to get running immediately, follow these instructions to get a webpack-dev-server running with the widget.
-
Create a
.env
file in the root of the React project with the following lines, replacing the Xs with the appropriate value:WEBEX_ACCESS_TOKEN=XXXXXXXXXXXXXXX
-
From the root directory run:
npm run serve:package widget-recents
When loading the widgets there are some configuration options you can provide:
Authentication methods:
Name | Data API | Description |
---|---|---|
accessToken |
data-access-token |
Access token for the user account initiating the messaging session. For testing purposes you can use a developer access token from https://developer.webex.com. |
guestToken |
data-guest-token |
Guest Access token for the user account initiating the messaging session. A guest issuer application is required to generate a guest token. https://developer.webex.com/docs/guest-issuer. |
sdkInstance |
N/A: global only feature | A Webex SDK instance that has already been created and authenticated. |
Optional configurations:
Name | Data API | Description |
---|---|---|
basicMode |
data-basic-mode |
(default: false) Loads the spaces list from webexapis.com. Note: this removes end-to-end encryption. |
logLevel |
data-log-level |
(default: silent ) When present, widget will log debug information to console. This can be set to: error , warn , debug , info , trace , or silent |
enableAddButton |
data-enable-add-button |
(default: false) Enables the "Add Space" button present on other clients in the header. |
enableSpaceListFilter |
data-enable-space-list-filter |
(default: true) This enables a search term input box for filtering the recents widget's space list. To disable, set this to false . |
enableUserProfile |
data-enable-user-profile |
(default: true) Enables the current user's profile display in the header. |
enableUserProfileMenu |
data-enable-user-profile-popover |
(default: false) Enables the current user's profile setting menu in the header. |
The easiest way to get the Webex Recents Widget into your web site is to add the built resources and attach data attributes to your a container.
If you're using our CDN, skip to the next section.
- Copy the resources in the
dist
directory to own project. - Add a
<script />
tag to your page to include thebundle.js
- Add a
<link />
tag to includemain.css
If you would like to embed with the widget without any additional behaviors into your page, use this data api. The div
containing our data-toggle
attribute must exist on the page before our javascript bundle loads.
Create a container where you would like to embed the widget and add the required configuration options. Be sure to include data-toggle="webex-recents"
.
<div
class="webexteams-widget"
data-toggle="webex-recents"
data-access-token="AN_ACCESS_TOKEN"
/>
If you need additional behaviors or need to do additional work before the widget loads, it may be useful for to programmatically instatiate the widget after the intial page loads.
<div id="my-webexteams-widget" />
<script>
var widgetEl = document.getElementById('my-webexteams-widget');
// Init a new widget
webex.widget(widgetEl).recentsWidget({
accessToken: 'AN_ACCESS_TOKEN'
});
</script>
my-webexteams-widget
is an arbitrary id to illustrate one way to select the DOM element. But please ensure that thewidgetEl
that you pass towebex.widget()
is a DOM element.
You can also attach to an existing widget. Currently this gives you access to events. Other functionality will be added in future releases.
var widgetEl = document.getElementById('webexteams-widget-id');
var widgetObject = webex.widget(widgetEl);
When a widget needs to be removed from the page you will want to call the .remove()
method. This will close any network connections active and remove the widget from the DOM. You can also pass a callback as a parameter to the .remove()
method. The method also returns a Promise that is thenable.
The returned value, removed
, is true
if a matching widget has been removed, and is false
no widget was found.
// Basic remove
webex.widget(widgetEl).remove();
// With callback
webex.widget(widgetEl).remove(function(removed) {
if (removed) {
console.log('removed!');
}
});
// With Promise
webex.widget(widgetEl).remove().then(function(removed) {
if (removed) {
console.log('removed!');
}
});
If you are also using the Webex JS SDK on the same page, please be sure to load that before you load the widget scripts.
The Recents widget exposes a few events for hooking into widget functionality. You can directly add DOM event listener like this:
<div
class="webexteams-widget"
data-toggle="webex-recents"
data-access-token="AN_ACCESS_TOKEN"
/>
<script>
document.getElementById('webexteams-widget').addEventListener('EVENT_NAME', function(event) {
// Handle the event here
console.log(event.detail);
});
</script>
If you are using browser globals, you can provide a callback parameter that will fire whenever any event occurs. You can filter the actions using the name provided like this:
var widgetEl = document.getElementById('my-webexteams-widget');
// Init a new widget
webex.widget(widgetEl).recentsWidget({
accessToken: 'AN_ACCESS_TOKEN',
onEvent: callback
});
function callback(name, detail) {
if (name === 'messages:created') {
// Perform an action if a new message has been created
}
}
Or you can use the (ampersand-events
)[https://github.com/AmpersandJS/ampersand-events] API to listen to events like this:
var widgetEl = document.getElementById('webexteams-widget');
webex.widget(widgetEl).on('messages:created', function(e) {
console.log(e.detail);
});
All available events are outlined in our events guide
This widget has been tested on the following browsers for messaging and meeting:
- Current release of Chrome
- Current release of Firefox
Please see CONTRIBUTING.md for more details.
© 2016-2018 Cisco and/or its affiliates. All Rights Reserved.