parent
ff6c5baac8
commit
6f88daf695
@ -0,0 +1,66 @@
|
|||||||
|
// venue.js
|
||||||
|
// Copyright (C) 2022 Digital Telepresence, LLC
|
||||||
|
// License: Apache-2.0
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fetch = require('node-fetch'); // jshint ignore:line
|
||||||
|
|
||||||
|
const CACHE_DURATION = 60 * 5;
|
||||||
|
|
||||||
|
const { SiteService, SiteError } = require('../../lib/site-lib');
|
||||||
|
|
||||||
|
class VenueService extends SiteService {
|
||||||
|
|
||||||
|
constructor (dtp) {
|
||||||
|
super(dtp, module.exports);
|
||||||
|
}
|
||||||
|
|
||||||
|
channelMiddleware ( ) {
|
||||||
|
return async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
if (!res.locals.site || !res.locals.site.shingChannelSlug) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
res.locals.shingChannelFeed = await this.getChannelFeed(res.locals.site.shingChannelSlug, { allowCache: true });
|
||||||
|
return next();
|
||||||
|
} catch (error) {
|
||||||
|
this.log.error('failed to populate Shing.tv channel feed', { error });
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async getChannelFeed (channelSlug, options) {
|
||||||
|
const { cache: cacheService } = this.dtp.services;
|
||||||
|
const cacheKey = `venue:ch:${channelSlug}`;
|
||||||
|
|
||||||
|
options = Object.assign({
|
||||||
|
allowCache: true,
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
let json;
|
||||||
|
if (options.allowCache) {
|
||||||
|
json = await cacheService.getObject(cacheKey);
|
||||||
|
if (json) {
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`https://shing.tv/channel/${channelSlug}/feed/json`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new SiteError(500, 'Failed to fetch Shing channel feed');
|
||||||
|
}
|
||||||
|
json = await response.json();
|
||||||
|
|
||||||
|
await cacheService.setObjectEx(cacheKey, CACHE_DURATION, json);
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
slug: 'venue',
|
||||||
|
name: 'venue',
|
||||||
|
create: (dtp) => { return new VenueService(dtp); },
|
||||||
|
};
|
@ -1,5 +1,6 @@
|
|||||||
extends ../layouts/main
|
extends ../layouts/main
|
||||||
block content
|
block content
|
||||||
|
|
||||||
- var shingBaseUrl = (process.env.NODE_ENV === 'production') ? 'https://shing.tv' : 'http://localhost:3333';
|
//- - var shingBaseUrl = (process.env.NODE_ENV === 'production') ? 'https://shing.tv' : 'http://localhost:3333';
|
||||||
|
- var shingBaseUrl = 'https://shing.tv';
|
||||||
iframe(src= `${shingBaseUrl}/channel/${site.shingChannelSlug}/embed/venue?k=${site.shingWidgetKey}`, style="width: 100%; height: 720px;", allowfullscreen)
|
iframe(src= `${shingBaseUrl}/channel/${site.shingChannelSlug}/embed/venue?k=${site.shingWidgetKey}`, style="width: 100%; height: 720px;", allowfullscreen)
|
Loading…
Reference in new issue