Skip to content

Commit

Permalink
Merge pull request #183 from LezdCS/develop
Browse files Browse the repository at this point in the history
StreamElements oauth2 + overlay support
  • Loading branch information
LezdCS authored May 22, 2024
2 parents 0873ba3 + f5e7e83 commit 4dfc0a5
Show file tree
Hide file tree
Showing 35 changed files with 1,012 additions and 324 deletions.
Binary file added lib/assets/streamelements/seLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions lib/src/bindings/home_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class HomeBindings extends Bindings {
settingsUseCase: SettingsUseCase(
settingsRepository: SettingsRepositoryImpl(),
),
streamelementsUseCase: StreamelementsUseCase(
streamelementsRepository: StreamelementsRepositoryImpl(),
),
),
),
);
Expand All @@ -48,6 +51,9 @@ class HomeBindings extends Bindings {
settingsUseCase: SettingsUseCase(
settingsRepository: SettingsRepositoryImpl(),
),
streamelementsUseCase: StreamelementsUseCase(
streamelementsRepository: StreamelementsRepositoryImpl(),
),
),
));

Expand All @@ -72,6 +78,9 @@ class HomeBindings extends Bindings {
settingsUseCase: SettingsUseCase(
settingsRepository: SettingsRepositoryImpl(),
),
streamelementsUseCase: StreamelementsUseCase(
streamelementsRepository: StreamelementsRepositoryImpl(),
),
),
));
Get.find<TwitchTabViewController>();
Expand Down
26 changes: 18 additions & 8 deletions lib/src/bindings/settings_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,36 @@ import 'package:get/get_core/src/get_main.dart';
import 'package:get/get_instance/src/bindings_interface.dart';
import 'package:get/get_instance/src/extension_instance.dart';
import 'package:irllink/src/data/repositories/settings_repository_impl.dart';
import 'package:irllink/src/data/repositories/streamelements_repository_impl.dart';
import 'package:irllink/src/data/repositories/twitch_repository_impl.dart';
import 'package:irllink/src/domain/usecases/settings_usecase.dart';
import 'package:irllink/src/domain/usecases/streamelements_usecase.dart';
import 'package:irllink/src/domain/usecases/twitch_usecase.dart';
import 'package:irllink/src/presentation/controllers/settings_view_controller.dart';
import 'package:irllink/src/presentation/events/settings_events.dart';
import 'package:irllink/src/presentation/events/streamelements_events.dart';

class SettingsBindings extends Bindings {
@override
void dependencies() {
Get.lazyPut<SettingsViewController>(
() => SettingsViewController(
settingsEvents: SettingsEvents(
settingsUseCase: SettingsUseCase(
settingsRepository: SettingsRepositoryImpl(),
settingsEvents: SettingsEvents(
settingsUseCase: SettingsUseCase(
settingsRepository: SettingsRepositoryImpl(),
),
twitchUseCase: TwitchUseCase(
twitchRepository: TwitchRepositoryImpl(),
),
),
twitchUseCase: TwitchUseCase(
twitchRepository: TwitchRepositoryImpl(),
),
),
),
streamelementsEvents: StreamelementsEvents(
streamelementsUseCase: StreamelementsUseCase(
streamelementsRepository: StreamelementsRepositoryImpl(),
),
settingsUseCase: SettingsUseCase(
settingsRepository: SettingsRepositoryImpl(),
),
)),
);
}
}
4 changes: 2 additions & 2 deletions lib/src/core/params/streamelements_auth_params.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class StreamelementsAuthParams {

const StreamelementsAuthParams({
this.clientId = kStreamelementsAuthClientId,
this.redirectUri = 'https://irllink.com/streamelements/auth',
this.redirectUri = 'https://www.irllink.com/api/streamelements/auth',
this.responseType = 'code',
this.scopes = 'activities:read activities:write tips:read',
this.scopes = 'channel:read tips:read activities:read overlays:read',
});
}
14 changes: 10 additions & 4 deletions lib/src/core/resources/data_state.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import 'package:irllink/src/core/utils/globals.dart' as globals;

abstract class DataState<T> {
final T? data;
final String? error;

const DataState({
DataState({
this.data,
this.error,
});
}) {
if(error != null) {
globals.talker?.error(error);
}
}
}

class DataSuccess<T> extends DataState<T> {
const DataSuccess(T data) : super(data: data);
DataSuccess(T data) : super(data: data);
}

class DataFailed<T> extends DataState<T> {
const DataFailed(String error) : super(error: error);
DataFailed(String error) : super(error: error);
}
2 changes: 1 addition & 1 deletion lib/src/core/utils/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ const kTwitchAuthUrlPath = '/oauth2/authorize';

const kRedirectScheme = 'dev.lezd.www.irllink';

const kStreamelementsAuthClientId = '';
const kStreamelementsAuthClientId = '77746eebf069856d';
const kStreamelementsUrlBase = 'api.streamelements.com';
const kStreamelementsAuthPath = '/oauth2/authorize';
6 changes: 3 additions & 3 deletions lib/src/core/utils/init_dio.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:talker_dio_logger/talker_dio_logger_interceptor.dart';
import 'package:talker_dio_logger/talker_dio_logger_settings.dart';
import 'package:irllink/src/core/utils/globals.dart' as globals;
Expand All @@ -11,8 +10,9 @@ Dio initDio() {
TalkerDioLogger(
talker: talker,
settings: TalkerDioLoggerSettings(
requestFilter: (RequestOptions options) => kDebugMode ? true : !options.path.contains('api.twitch.tv'),
responseFilter: (response) => kDebugMode ? true : ![200, 202].contains(response.statusCode),
requestFilter: (RequestOptions options) => !options.path.contains('api.twitch.tv'),
printRequestHeaders: true,
// responseFilter: (response) => ![200, 202].contains(response.statusCode),
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/core/utils/twitch_event_sub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class TwitchEventSub {
}

void _onDone() {
globals.talker?.debug("Twitch Sub Event: Connection closed");
globals.talker?.info("Twitch Sub Event: Connection closed");
close();
}

Expand Down
14 changes: 14 additions & 0 deletions lib/src/data/entities/settings/stream_elements_settings_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class StreamElementsSettingsDTO extends StreamElementsSettings {
required super.showRaidActivity,
required super.showHostActivity,
required super.showMerchActivity,
required super.jwt,
required super.overlayToken,
required super.mutedOverlays,
});

@override
Expand All @@ -21,6 +24,9 @@ class StreamElementsSettingsDTO extends StreamElementsSettings {
'showRaidActivity': showRaidActivity,
'showHostActivity': showHostActivity,
'showMerchActivity': showMerchActivity,
'jwt': jwt,
'overlayToken': overlayToken,
'mutedOverlays': mutedOverlays,
};

factory StreamElementsSettingsDTO.fromJson(Map<String, dynamic> map) {
Expand Down Expand Up @@ -53,6 +59,14 @@ class StreamElementsSettingsDTO extends StreamElementsSettings {
const Settings.defaultSettings()
.streamElementsSettings!
.showMerchActivity,
jwt: map['jwt'] ??
const Settings.defaultSettings().streamElementsSettings!.jwt,
overlayToken: map['overlayToken'] ??
const Settings.defaultSettings().streamElementsSettings!.overlayToken,
mutedOverlays: (List<String>.from(map['mutedOverlays'] ??
const Settings.defaultSettings()
.streamElementsSettings!
.mutedOverlays)),
);
}
}
6 changes: 0 additions & 6 deletions lib/src/data/entities/settings_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class SettingsDTO extends Settings {
required bool isObsConnected,
required String obsWebsocketUrl,
required String obsWebsocketPassword,
required String streamElementsAccessToken,
required List browserTabs,
required List obsConnectionsHistory,
required StreamElementsSettings streamElementsSettings,
Expand All @@ -50,7 +49,6 @@ class SettingsDTO extends Settings {
obsWebsocketUrl: obsWebsocketUrl,
obsWebsocketPassword: obsWebsocketPassword,
isObsConnected: isObsConnected,
streamElementsAccessToken: streamElementsAccessToken,
browserTabs: browserTabs,
obsConnectionsHistory: obsConnectionsHistory,
streamElementsSettings: streamElementsSettings,
Expand All @@ -73,7 +71,6 @@ class SettingsDTO extends Settings {
'isObsConnected': isObsConnected,
'obsWebsocketUrl': obsWebsocketUrl,
'obsWebsocketPassword': obsWebsocketPassword,
'streamElementsAccessToken': streamElementsAccessToken,
'browserTabs': browserTabs,
'obsConnectionsHistory': obsConnectionsHistory,
'streamElementsSettings': streamElementsSettings?.toJson(),
Expand Down Expand Up @@ -119,9 +116,6 @@ class SettingsDTO extends Settings {
obsWebsocketPassword: map['obsWebsocketPassword'] != null
? map['obsWebsocketPassword'] as String
: const Settings.defaultSettings().obsWebsocketPassword!,
streamElementsAccessToken: map['streamElementsAccessToken'] != null
? map['streamElementsAccessToken'] as String
: const Settings.defaultSettings().streamElementsAccessToken!,
browserTabs: map['browserTabs'] != null
? map['browserTabs'] as List
: const Settings.defaultSettings().browserTabs!,
Expand Down
27 changes: 27 additions & 0 deletions lib/src/data/entities/stream_elements/se_credentials_dto.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:irllink/src/domain/entities/stream_elements/se_credentials.dart';

class SeCredentialsDTO extends SeCredentials {
const SeCredentialsDTO({
required super.accessToken,
required super.refreshToken,
required super.expiresIn,
required super.scopes,
});

@override
Map toJson() => {
'accessToken': accessToken,
'refreshToken': refreshToken,
'expiresIn': expiresIn,
'scopes': scopes,
};

factory SeCredentialsDTO.fromJson(Map<String, dynamic> map) {
return SeCredentialsDTO(
accessToken: map['accessToken'] as String,
refreshToken: map['refreshToken'] as String,
expiresIn: map['expiresIn'] as int,
scopes: map['scopes'] as String,
);
}
}
2 changes: 1 addition & 1 deletion lib/src/data/repositories/settings_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SettingsRepositoryImpl extends SettingsRepository {
SettingsDTO settings = SettingsDTO.fromJson(settingsJson);
return DataSuccess(settings);
}
return const DataSuccess(Settings.defaultSettings());
return DataSuccess(const Settings.defaultSettings());
}

@override
Expand Down
Loading

0 comments on commit 4dfc0a5

Please sign in to comment.