Skip to content

Commit

Permalink
Widget-Sources fixes (stream-labs#899)
Browse files Browse the repository at this point in the history
  • Loading branch information
holiber authored Oct 11, 2018
1 parent b27fce4 commit b20810d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
2 changes: 2 additions & 0 deletions app/services/scene-collections/scene-collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ export class SceneCollectionsService extends Service
* Should be called before any loading operations
*/
private startLoadingOperation() {
this.windowsService.closeChildWindow();
this.windowsService.closeAllOneOffs();
this.appService.startLoading();
this.disableAutoSave();
}
Expand Down
10 changes: 8 additions & 2 deletions app/services/sources/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,14 @@ export class Source implements ISourceApi {
// is always up-to-date, and essentially acts
// as a view into the store. It also enforces
// the read-only nature of this data
this.sourceState = this.sourcesService.state.sources[sourceId];
Utils.applyProxy(this, this.sourcesService.state.sources[sourceId]);
const isTemporarySource = !!this.sourcesService.state.temporarySources[sourceId];
if (isTemporarySource) {
this.sourceState = this.sourcesService.state.temporarySources[sourceId];
Utils.applyProxy(this, this.sourcesService.state.temporarySources[sourceId]);
} else {
this.sourceState = this.sourcesService.state.sources[sourceId];
Utils.applyProxy(this, this.sourcesService.state.sources[sourceId]);
}
}

@mutation()
Expand Down
2 changes: 2 additions & 0 deletions app/services/sources/sources-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface ISourceCreateOptions {
sourceId?: string; // A new ID will be generated if one is not specified
propertiesManager?: TPropertiesManager;
propertiesManagerSettings?: Dictionary<any>;
isTemporary?: boolean;
}

export type TSourceType =
Expand Down Expand Up @@ -112,6 +113,7 @@ export type TPropertiesManager =

export interface ISourcesState {
sources: Dictionary<ISource>;
temporarySources: Dictionary<ISource>;
}

export interface IActivePropertyManager {
Expand Down
19 changes: 12 additions & 7 deletions app/services/sources/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export const PROPERTIES_MANAGER_TYPES = {
export class SourcesService extends StatefulService<ISourcesState> implements ISourcesServiceApi {

static initialState = {
sources: {}
sources: {},
temporarySources: {} // don't save temporarySources in the config file
} as ISourcesState;

sourceAdded = new Subject<ISource>();
Expand Down Expand Up @@ -101,7 +102,7 @@ export class SourcesService extends StatefulService<ISourcesState> implements IS
}

@mutation()
private ADD_SOURCE(id: string, name: string, type: TSourceType, channel?: number) {
private ADD_SOURCE(id: string, name: string, type: TSourceType, channel?: number, isTemporary?: boolean) {
const sourceModel: ISource = {
sourceId: id,
name,
Expand All @@ -123,7 +124,11 @@ export class SourcesService extends StatefulService<ISourcesState> implements IS
channel
};

Vue.set(this.state.sources, id, sourceModel);
if (isTemporary) {
Vue.set(this.state.temporarySources, id, sourceModel);
} else {
Vue.set(this.state.sources, id, sourceModel);
}
}

@mutation()
Expand All @@ -143,7 +148,7 @@ export class SourcesService extends StatefulService<ISourcesState> implements IS
settings: Dictionary<any> = {},
options: ISourceCreateOptions = {}
): Source {


const id: string = options.sourceId || `${type}_${uuid()}`;

Expand All @@ -164,13 +169,13 @@ export class SourcesService extends StatefulService<ISourcesState> implements IS
}

addSource(obsInput: obs.IInput, name: string, options: ISourceCreateOptions = {}) {

if (options.channel !== void 0) {
obs.Global.setOutputSource(options.channel, obsInput);
}
const id = obsInput.name;
const type: TSourceType = obsInput.id as TSourceType;
this.ADD_SOURCE(id, name, type, options.channel);
this.ADD_SOURCE(id, name, type, options.channel, options.isTemporary);
const source = this.getSource(id);
const muted = obsInput.muted;
this.UPDATE_SOURCE({ id, muted });
Expand Down Expand Up @@ -375,7 +380,7 @@ export class SourcesService extends StatefulService<ISourcesState> implements IS


getSource(id: string): Source {
return this.state.sources[id] ? new Source(id) : void 0;
return this.state.sources[id] || this.state.temporarySources[id] ? new Source(id) : void 0;
}


Expand Down
5 changes: 3 additions & 2 deletions app/services/widgets/widget-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export class WidgetSource implements IWidgetSource {
const previewSourceSettings = {
...source.getSettings(),
shutdown: false,
url: apiSettings.previewUrl
url: apiSettings.previewUrl,
isTemporary: true
};

const previewSource = this.sourcesService.createSource(
Expand Down Expand Up @@ -79,4 +80,4 @@ export class WidgetSource implements IWidgetSource {
private SET_PREVIEW_SOURCE_ID(previewSourceId: string) {
Object.assign(this.widgetSourceState, { previewSourceId });
}
}
}
2 changes: 1 addition & 1 deletion app/services/widgets/widgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class WidgetsService extends StatefulService<IWidgetSourcesState> impleme
}

getWidgetSource(sourceId: string): WidgetSource {
return this.sourcesService.state.sources[sourceId] ? new WidgetSource(sourceId) : null;
return this.state.widgetSources[sourceId] ? new WidgetSource(sourceId) : null;
}

getWidgetUrl(type: WidgetType) {
Expand Down

0 comments on commit b20810d

Please sign in to comment.