@councilbox/shutter-js
Version:
Shutter API - javascript SDK
266 lines (229 loc) • 9.29 kB
JavaScript
/* eslint-disable no-console */
const Shutter = require('./lib/index');
// PRE
/* const email = 'sdk@shutter.com';
const password = 'Pc1UjsTCXy3LKW0tWEun';
const uri = 'https://api.shutter.pre.councilbox.com/graphql'; */
// LOCAL API
// const email = 'sdk2@shutter.com';
// const password = '4wym23jsfnv95hpa2';
const email = 'sdk@shutter.com';
const password = 'Pc1UjsTCXy3LKW0tWEun';
const uri = 'http://localhost:4040/graphql';
const shutter = new Shutter({ email, password, uri });
const main = async () => {
const time = new Date().getTime();
// ME
const me = await shutter.users.me();
console.debug('ME => ', me);
// CREATE ORGANIZATION || ONLY FIRST TIME
const newOrg = {
name: `SDK Test Org ${time}`,
logo: {
filetype: 'png',
base64: 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAAdgAAAHYBTnsmCAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAEySURBVDiNhdJPK0VhEMfxz3UlsmDBQkn+lPxZKJYsRCErO2WpvAXvwXuwJaykJGWHYmFhgZ2UUjZYyC0RizM3zz0d3alper7PzO/Mc2ZKim0ZvTn2gN18Yumfwn7c5+6qrEaoMZc0jDNcFXRVZVMpzAvAEMZwjdFgNwmrsYYCgQ6sRXwOT1ldgSvsROwOT1ldgQlsRmwKT1ldgbtIvMNbeMpqrOgn9qFdNuKRYE8JqysAr5FcKWA1VsIMFuJcwa1smR4wGfw8YSNoidqjMlaxh/cQ+sKl7M1daI5Oq2wcBzjFYhnTmI83fmJLtm2H+MEjThI2iE7M4qUU7WxjI3nKWRQsxXk/YXCMdaw0xJe7cRGX6chew/NjHJCtdaWMObTK9r4n2hbCbfjwN432yPmO2PQLRLdIycezsR4AAAAASUVORK5CYII='
}
};
const createdOrganization = await shutter.organizations.create({ organization: newOrg });
console.debug('ORGANIZATION CREATED => ', createdOrganization);
/* try {
const createdOrganization = await shutter.organizations.create({ organization: undefined });
console.debug('ORGANIZATION CREATED => ', createdOrganization);
} catch (err) {
console.error('ERROR => ', err);
} */
// UPDATE ORGANIZATION
const organizationToUpdate = { ...createdOrganization, name: `SDK Test Org Upd ${time}`, logo: newOrg.logo };
const organization = await shutter.organizations.update({ organization: organizationToUpdate });
console.debug('UPDATED ORGANIZATION => ', organization);
// LIST ORGANIZATIONS
const organizations = await shutter.organizations.list();
console.debug('ORGANIZATIONS => ', organizations);
// CREATE USER
const newUser = {
name: 'SDK Test',
surname: 'User',
email: `sdk_test_user_${time}@shutter.com`,
password: 'abc1234',
organizationsIDs: [organization.id],
language: 'en',
type: 'BASIC'
};
const user = await shutter.users.create({ user: newUser });
console.debug('USER CREATED => ', user);
// CREATE ROOM
const newRoom = {
type: 'MEET',
displayName: `SDK MEET ${time}`,
externalID: '12345687',
agenda: 'Meet agenda',
locked: false,
enabledWaitingRoom: false,
webhook: null,
data: '',
attendees: [
{
email: 'moderator@shutter.com',
role: 'MODERATOR',
canShareScreen: true,
canBroadcast: true,
canChat: true,
canMuteAudio: true,
canMuteVideo: true,
canMuteAudioAll: true,
canMuteVideoAll: true,
canShareFiles: true,
canSeeAttendeesList: true,
canRaiseHand: true,
broadcasting: true,
mutedMic: false,
mutedCam: false,
displayName: 'Moderador',
language: 'es'
},
{
email: 'speaker@shutter.com',
role: 'SPEAKER',
canShareScreen: false,
canBroadcast: true,
canChat: true,
canMuteAudio: true,
canMuteVideo: true,
canMuteAudioAll: true,
canMuteVideoAll: true,
canShareFiles: false,
canSeeAttendeesList: true,
canRaiseHand: true,
broadcasting: true,
mutedMic: false,
mutedCam: false,
displayName: 'Speaker',
language: 'en'
},
{
email: 'viewer@shutter.com',
role: 'VIEWER',
canShareScreen: true,
canBroadcast: true,
canChat: true,
canMuteAudio: true,
canMuteVideo: true,
canMuteAudioAll: true,
canMuteVideoAll: true,
canShareFiles: false,
canSeeAttendeesList: true,
canRaiseHand: true,
broadcasting: true,
mutedMic: false,
mutedCam: false,
displayName: 'Viewer',
language: 'en'
}
],
password: 'abc12345',
canRecord: false,
autoRecord: false,
security: 'PRIVATE',
state: 'DRAFT'
};
const createdRoom = await shutter.rooms.create({ room: newRoom, organizationID: organization.id });
console.debug('ROOM CREATED => ', createdRoom);
// UPDATE ROOM
const roomToUpdate = { roomNumber: createdRoom.roomNumber, displayName: `SDK MEET Upd ${time}` };
const room = await shutter.rooms.update({ room: roomToUpdate, organizationID: organization.id });
console.debug('UPDATED ROOM => ', room);
// START ROOM
const startedRoom = await shutter.rooms.start({ roomNumber: room.roomNumber });
console.debug('STARTED ROOM => ', startedRoom);
// CLOSE ROOM
const closedRoom = await shutter.rooms.close({ roomNumber: room.roomNumber });
console.debug('CLOSED ROOM => ', closedRoom);
// // ROOM START RECORDING
// const roomStartedRecording = await shutter.rooms.startRecording({ roomNumber: room.roomNumber });
// console.debug('STARTED RECORDING ROOM => ', roomStartedRecording);
// // ROOM STOP RECORDING
// const roomStoppedRecording = await shutter.rooms.stopRecording({ roomNumber: room.roomNumber });
// console.debug('STOPPED RECORDING ROOM => ', roomStoppedRecording);
// // RECORDINGS LIST
// const recordings = await shutter.recordings.list({ roomNumber: room.roomNumber });
// console.debug('RECORDINGS LIST => ', recordings);
// // RECORDINGS IFRAME URL
// const recordingsIframeUrl = await shutter.recordings.getIframeUrl({ roomNumber: room.roomNumber });
// console.debug('RECORDINGS IFRAME URL => ', recordingsIframeUrl);
// // ROOM START LIVE STREAMING
// const roomStartedStreaming = await shutter.rooms.startStreaming({ roomNumber: room.roomNumber });
// console.debug('STARTED STREAMING ROOM => ', roomStartedStreaming);
// // ROOM STOP LIVE STREAMING
// const roomStoppedStreaming = await shutter.rooms.stopStreaming({ roomNumber: room.roomNumber });
// console.debug('STOPPED STREAMING ROOM => ', roomStoppedStreaming);
// // CREATE ATTENDEE
// const newAttendee = {
// email: 'speaker2@shutter.com',
// role: 'SPEAKER',
// canShareScreen: true,
// canBroadcast: true,
// canChat: true,
// canMuteAudio: true,
// canMuteVideo: true,
// canMuteAudioAll: true,
// canMuteVideoAll: true,
// canShareFiles: false,
// canSeeAttendeesList: true,
// canRaiseHand: true,
// broadcasting: true,
// mutedMic: false,
// mutedCam: false,
// displayName: 'Speaker Test',
// language: 'en'
// };
// const createdAttendee = await shutter.attendees.create({ roomNumber: room.roomNumber, attendee: newAttendee });
// console.debug('ATTENDEE CREATED => ', createdAttendee);
// // UPDATE ATTENDEE
// const attendeeToUpdate = { id: createdAttendee.id, displayName: `Speaker Test Upd ${time}` };
// const attendee = await shutter.attendees.update({ roomNumber: room.roomNumber, attendee: attendeeToUpdate });
// console.debug('UPDATED ATTENDEE => ', attendee);
// // ATTENDEE RAISE HAND
// const attendeeRaisedHand = await shutter.attendees.raiseHand({ roomNumber: room.roomNumber, id: attendee.id });
// console.debug('RAISED HAND ATTENDEE => ', attendeeRaisedHand);
// // ATTENDEE LOWER HAND
// const attendeeLoweredHand = await shutter.attendees.lowerHand({ roomNumber: room.roomNumber, id: attendee.id });
// console.debug('LOWERED HAND ATTENDEE => ', attendeeLoweredHand);
// // ATTENDEE GRANT WORD
// const attendeeGrantedWord = await shutter.attendees.grantWord({ roomNumber: room.roomNumber, id: attendee.id });
// console.debug('GRANTED WORD ATTENDEE => ', attendeeGrantedWord);
// // ATTENDEE DENY WORD
// const attendeeDeniedWord = await shutter.attendees.denyWord({ roomNumber: room.roomNumber, id: attendee.id });
// console.debug('DENIED WORD ATTENDEE => ', attendeeDeniedWord);
// // ATTENDEES URLS
// const roomAttendeesUrls = await shutter.rooms.attendeesUrls({ roomNumber: room.roomNumber });
// console.debug('ROOM ATTENDEES URLS => ', roomAttendeesUrls);
// LIST ROOMS
const rooms = await shutter.rooms.list();
console.debug('ROOMS LIST => ', rooms);
// GET ROOM
const roomGet = await shutter.rooms.get({ roomNumber: room.roomNumber });
console.debug('ROOM GET => ', roomGet);
/* // LIST ATTENDEES
const attendees = await shutter.attendees.list({ roomNumber: room.roomNumber });
console.debug('ATTENDEES LIST => ', attendees);
// GET ATTENDEE
const attendeeGet = await shutter.attendees.get({ roomNumber: room.roomNumber, id: attendee.id });
console.debug('ATTENDEE GET => ', attendeeGet);
// DELETE ATTENDEE
const deletedAttendee = await shutter.attendees.delete({ roomNumber: room.roomNumber, id: attendee.id });
console.debug('ATTENDEE DELETED => ', deletedAttendee); */
// DELETE ROOM
const deletedRoom = await shutter.rooms.delete({ roomNumber: room.roomNumber });
console.debug('ROOM DELETED => ', deletedRoom);
// DELETE USER
const deletedUser = await shutter.users.delete({ id: user.id });
console.debug('USER DELETED => ', deletedUser);
// DELETE ORGANIZATION
const deletedOrganization = await shutter.organizations.delete({ id: organization.id });
console.debug('ORGANIZATION DELETED => ', deletedOrganization);
};
main().then(() => {
console.info('MAIN FINISHED');
}).catch(err => {
console.error(err);
});