diff --git a/Mamoth/Mamoth.njsproj b/Mamoth/Mamoth.njsproj index bc3fc611..23ec0aa5 100644 --- a/Mamoth/Mamoth.njsproj +++ b/Mamoth/Mamoth.njsproj @@ -111,6 +111,7 @@ + diff --git a/Mamoth/src/app/app.module.ts b/Mamoth/src/app/app.module.ts index a81f69ee..c4819559 100644 --- a/Mamoth/src/app/app.module.ts +++ b/Mamoth/src/app/app.module.ts @@ -16,6 +16,7 @@ import { RegisterNewAccountComponent } from "./pages/register-new-account/regist import { AuthService } from "./services/auth.service"; import { AccountsService } from "./services/accounts.service"; import { StreamsService } from "./services/streams.service"; +import { StreamingService } from "./services/streaming.service"; const routes: Routes = [ { path: "", redirectTo: "home", pathMatch: "full" }, @@ -41,7 +42,7 @@ const routes: Routes = [ NgxElectronModule, RouterModule.forRoot(routes) ], - providers: [AuthService, AccountsService, StreamsService, { provide: APP_INITIALIZER, useFactory: settingsServiceFactory, deps: [AccountsService], multi: true }], + providers: [AuthService, AccountsService, StreamsService, StreamingService, { provide: APP_INITIALIZER, useFactory: settingsServiceFactory, deps: [AccountsService], multi: true }], bootstrap: [AppComponent] }) export class AppModule { } diff --git a/Mamoth/src/app/models/stream.models.ts b/Mamoth/src/app/models/stream.models.ts index 87d46c97..aacdfc44 100644 --- a/Mamoth/src/app/models/stream.models.ts +++ b/Mamoth/src/app/models/stream.models.ts @@ -5,6 +5,7 @@ import { AccountWrapper } from "./account.models"; import { LocalAccount } from "../services/accounts.service"; import { ApiRoutes } from "../services/models/api.settings"; import { Account, Status } from "../services/models/mastodon.interfaces"; +import { StreamingService, StreamingWrapper } from "../services/streaming.service"; export class Stream { private apiRoutes = new ApiRoutes(); @@ -20,7 +21,13 @@ export class Stream { this.retrieveToots(); //TODO change this for WebSockets } + private test: StreamingWrapper; private retrieveToots(): void { + //TEST + const service = new StreamingService(); + this.test = service.getStreaming(this.account.mastodonInstance, this.account.tokenData.access_token); + //END TEST + const route = this.getTimelineRoute(); const header = new Headers(); @@ -60,8 +67,6 @@ export enum StreamTypeEnum { export class TootWrapper { constructor(status: Status) { - console.warn(status); - this.account = new AccountWrapper(); this.account.username = status.account.username; this.account.display_name = status.account.display_name; diff --git a/Mamoth/src/app/services/streaming.service.ts b/Mamoth/src/app/services/streaming.service.ts new file mode 100644 index 00000000..f0c59295 --- /dev/null +++ b/Mamoth/src/app/services/streaming.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from "@angular/core"; + +@Injectable() +export class StreamingService { + + constructor() { } + + //TODO restructure this to handle real domain objects + getStreaming(mastodonInstance: string, accessToken: string): StreamingWrapper { + return new StreamingWrapper(mastodonInstance.replace("https://", "wss://") + `/api/v1/streaming//?access_token=${accessToken}&stream=public`) + } + +} + +export class StreamingWrapper { + + constructor(private readonly domain: string) { + const eventSource = new WebSocket(domain); + eventSource.onmessage = x => console.warn(JSON.parse(x.data)); + eventSource.onerror = x => console.error(x); + eventSource.onopen = x => console.log(x); + eventSource.onclose = x => console.log(x); + } +}