Skip to content

Commit

Permalink
Display Page Events on Scheduler (stream-labs#4489)
Browse files Browse the repository at this point in the history
* Display page events on schedule calendar

* Remove game field from scheduler
  • Loading branch information
gettinToasty authored Mar 3, 2023
1 parent 24d3d47 commit 4ef50b0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function EventSettingsModal() {
description={
selectedPlatform === 'facebook'
? $t(
'Please note that while you can schedule streams to Facebook, they will not appear on this calendar due to API limitations',
'Please note that while you can schedule streams to Facebook, some will not appear on this calendar due to API limitations',
)
: undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,7 @@ function convertFBLiveVideoToEvent(fbLiveVideo: IFacebookLiveVideoExtended): ISt
return {
platform: 'facebook',
id: fbLiveVideo.id,
date: new Date(
fbLiveVideo.event_params?.start_time || fbLiveVideo.broadcast_start_time,
).valueOf(),
date: new Date(fbLiveVideo.broadcast_start_time).valueOf(),
title: fbLiveVideo.title,
status: 'scheduled',
facebook: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class FacebookEditStreamInfoModule {
}

get shouldShowGame() {
return !this.isUpdateMode;
return !this.isUpdateMode && !this.props.isScheduleMode;
}

get shouldShowPrivacy() {
Expand Down
2 changes: 1 addition & 1 deletion app/i18n/en-US/facebook.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
"Only Me": "Only Me",
"Do not change privacy settings": "Do not change privacy settings",
"Install %{overlayName}": "Install %{overlayName}",
"Please note that while you can schedule streams to Facebook, they will not appear on this calendar due to API limitations": "Please note that while you can schedule streams to Facebook, they will not appear on this calendar due to API limitations"
"Please note that while you can schedule streams to Facebook, some will not appear on this calendar due to API limitations": "Please note that while you can schedule streams to Facebook, some will not appear on this calendar due to API limitations"
}
86 changes: 34 additions & 52 deletions app/services/platforms/facebook.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import moment from 'moment';
import flatten from 'lodash/flatten';
import * as remote from '@electron/remote';
import { mutation, InheritMutations, ViewHandler } from '../core/stateful-service';
import { IPlatformService, IGame, TPlatformCapability, IPlatformRequest, IPlatformState } from '.';
import { HostsService } from 'services/hosts';
Expand All @@ -10,8 +13,6 @@ import { throwStreamError } from 'services/streaming/stream-error';
import { BasePlatformService } from './base-platform';
import { WindowsService } from '../windows';
import { assertIsDefined, getDefined } from '../../util/properties-type-guards';
import flatten from 'lodash/flatten';
import * as remote from '@electron/remote';

interface IFacebookPage {
access_token: string;
Expand All @@ -29,8 +30,17 @@ interface IFacebookGroup {
administrator: boolean;
}

interface IFacebookEvent {
description: string;
name: string;
start_time: string;
id: string;
}

type TFacebookStatus = 'UNPUBLISHED' | 'SCHEDULED_UNPUBLISHED' | 'LIVE_STOPPED' | 'LIVE';

export interface IFacebookLiveVideo {
status: 'UNPUBLISHED' | 'SCHEDULED_UNPUBLISHED' | 'LIVE_STOPPED' | 'LIVE';
status: TFacebookStatus;
id: string;
stream_url: string;
title: string;
Expand All @@ -39,11 +49,7 @@ export interface IFacebookLiveVideo {
permalink_url: string;
video: { id: string };
broadcast_start_time: string;
event_params: {
start_time?: number;
cover?: string;
status?: 'UNPUBLISHED' | 'SCHEDULED_UNPUBLISHED' | 'LIVE_STOPPED' | 'LIVE';
};
event_params: { start_time?: number; cover?: string; status?: TFacebookStatus };
}

/**
Expand Down Expand Up @@ -82,11 +88,7 @@ export interface IFacebookStartStreamOptions {
description?: string;
liveVideoId?: string;
privacy?: { value: TFacebookStreamPrivacy };
event_params: {
start_time?: number;
cover?: string;
status?: 'UNPUBLISHED' | 'SCHEDULED_UNPUBLISHED' | 'LIVE_STOPPED' | 'LIVE';
};
event_params: { start_time?: number; cover?: string; status?: TFacebookStatus };
}

export type TDestinationType = 'me' | 'page' | 'group' | '';
Expand Down Expand Up @@ -493,8 +495,6 @@ export class FacebookService
const timeRange = 1000 * 60 * 60 * 24;
const maxDate = Date.now() + timeRange;
const minDate = Date.now() - timeRange;
const maxDateUnix = Math.floor(maxDate / 1000);
const minDateUnix = Math.floor(minDate / 1000);
const token = this.views.getDestinationToken(destinationType, destinationId);
let sourceParam = '';
if (destinationType === 'page' || destinationType === 'me') {
Expand All @@ -504,22 +504,36 @@ export class FacebookService
}

let videos = (
await this.requestFacebook<{ data: IFacebookLiveVideo[] }>(
`${this.apiBase}/${destinationId}/live_videos?status=["UNPUBLISHED","SCHEDULED_UNPUBLISHED"]&fields=title,description,status,event_params,permalink_url,from${sourceParam}&since=${minDateUnix}&until=${maxDateUnix}`,
await this.requestFacebook<{ data: IFacebookEvent[] }>(
`${this.apiBase}/${destinationId}/events`,
token,
)
).data;

if (onlyUpcoming) {
videos = videos.filter(v => {
// some videos created in the new Live Producer don't have `planned_start_time`
if (!v.event_params?.start_time) return true;
if (!v.start_time) return true;

const videoDate = new Date(v.event_params.start_time).valueOf();
const videoDate = new Date(v.start_time).valueOf();
return videoDate >= minDate && videoDate <= maxDate;
});
}
return videos;
return videos.map(v => ({
id: v.id,
title: v.name,
stream_url: '',
permalink_url: '',
event_params: {
start_time: moment(v.start_time).unix(),
status: 'SCHEDULED_UNPUBLISHED',
},
description: v.description,
status: 'SCHEDULED_UNPUBLISHED',
game: '',
video: { id: v.id },
broadcast_start_time: v.start_time,
}));
}

/**
Expand All @@ -529,38 +543,6 @@ export class FacebookService
// perform all requests simultaneously
const requests: Promise<IFacebookLiveVideoExtended[]>[] = [];

// fetch videos from the timeline and groups
if (this.state.grantedPermissions.includes('publish_video')) {
const destinationType = 'me';
const destinationId = 'me';
requests.push(
this.fetchScheduledVideos(destinationType, destinationId, onlyUpcoming).then(videos =>
videos.map(video => ({
...video,
destinationType,
destinationId,
})),
),
);
}

// fetch videos from group
if (this.state.grantedPermissions.includes('publish_to_groups')) {
const destinationType = 'group';
this.state.facebookGroups.forEach(group => {
const destinationId = group.id;
requests.push(
this.fetchScheduledVideos(destinationType, destinationId, onlyUpcoming).then(videos =>
videos.map(video => ({
...video,
destinationType,
destinationId,
})),
),
);
});
}

// fetch videos from pages
this.state.facebookPages.forEach(page => {
const destinationType = 'page';
Expand Down

0 comments on commit 4ef50b0

Please sign in to comment.