UNPKG

@speechkit/speechkit-audio-player

Version:

A web player component that can play audio from https://speechkit.io

60 lines (52 loc) 1.69 kB
import 'string.prototype.includes' import { fetchWithErrorHandling } from '../utils/BetterFetch' class EventTracker { constructor(options) { if (options.skBackend.includes('spkt.local')) { this.eventBackend = "http://localhost:9090/events-development" } else if (options.skBackend.includes('https://staging.spkt.io')) { this.eventBackend = "https://happen.spkt.io/events-staging" } else if (options.skBackend.includes('https://spkt.io')) { this.eventBackend = "https://happen.spkt.io/events" } this.projectId = options.projectId this.podcastId = options.podcastId this.publisherId = options.publisherId this.mediaType = options.mediaType this.projectCampaignId = options.projectCampaignId } // track events by posting data to event-backend trackEvent(params) { if (!this.eventBackend) { return } return new Promise((resolve, reject) => { const data = { project_id: this.projectId, podcast_id: this.podcastId, publisher_id: this.publisherId, media_type: this.mediaType, ...params } if (this.projectCampaignId) { data.project_campaign_id = this.projectCampaignId } // post event data as JSON return fetchWithErrorHandling(this.eventBackend, { method: 'POST', headers:{ 'Content-Type': 'application/json' }, body: JSON.stringify(data), }) .then(response => resolve()) .catch(error => { throw new Error('EventTracker Error: '+ error); }); }); } setMediaType(mediaType) { this.mediaType = mediaType } } export default EventTracker