first test with websockets (quick and dirty)
This commit is contained in:
parent
a52a26e6b5
commit
36657eb3cf
|
@ -111,6 +111,7 @@
|
||||||
<TypeScriptCompile Include="src\app\services\auth.service.ts" />
|
<TypeScriptCompile Include="src\app\services\auth.service.ts" />
|
||||||
<TypeScriptCompile Include="src\app\services\models\api.settings.ts" />
|
<TypeScriptCompile Include="src\app\services\models\api.settings.ts" />
|
||||||
<TypeScriptCompile Include="src\app\services\models\mastodon.interfaces.ts" />
|
<TypeScriptCompile Include="src\app\services\models\mastodon.interfaces.ts" />
|
||||||
|
<TypeScriptCompile Include="src\app\services\streaming.service.ts" />
|
||||||
<TypeScriptCompile Include="src\app\services\streams.service.ts" />
|
<TypeScriptCompile Include="src\app\services\streams.service.ts" />
|
||||||
<TypeScriptCompile Include="src\environments\environment.prod.ts" />
|
<TypeScriptCompile Include="src\environments\environment.prod.ts" />
|
||||||
<TypeScriptCompile Include="src\environments\environment.ts" />
|
<TypeScriptCompile Include="src\environments\environment.ts" />
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { RegisterNewAccountComponent } from "./pages/register-new-account/regist
|
||||||
import { AuthService } from "./services/auth.service";
|
import { AuthService } from "./services/auth.service";
|
||||||
import { AccountsService } from "./services/accounts.service";
|
import { AccountsService } from "./services/accounts.service";
|
||||||
import { StreamsService } from "./services/streams.service";
|
import { StreamsService } from "./services/streams.service";
|
||||||
|
import { StreamingService } from "./services/streaming.service";
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: "", redirectTo: "home", pathMatch: "full" },
|
{ path: "", redirectTo: "home", pathMatch: "full" },
|
||||||
|
@ -41,7 +42,7 @@ const routes: Routes = [
|
||||||
NgxElectronModule,
|
NgxElectronModule,
|
||||||
RouterModule.forRoot(routes)
|
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]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
export class AppModule { }
|
export class AppModule { }
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { AccountWrapper } from "./account.models";
|
||||||
import { LocalAccount } from "../services/accounts.service";
|
import { LocalAccount } from "../services/accounts.service";
|
||||||
import { ApiRoutes } from "../services/models/api.settings";
|
import { ApiRoutes } from "../services/models/api.settings";
|
||||||
import { Account, Status } from "../services/models/mastodon.interfaces";
|
import { Account, Status } from "../services/models/mastodon.interfaces";
|
||||||
|
import { StreamingService, StreamingWrapper } from "../services/streaming.service";
|
||||||
|
|
||||||
export class Stream {
|
export class Stream {
|
||||||
private apiRoutes = new ApiRoutes();
|
private apiRoutes = new ApiRoutes();
|
||||||
|
@ -20,7 +21,13 @@ export class Stream {
|
||||||
this.retrieveToots(); //TODO change this for WebSockets
|
this.retrieveToots(); //TODO change this for WebSockets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private test: StreamingWrapper;
|
||||||
private retrieveToots(): void {
|
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 route = this.getTimelineRoute();
|
||||||
|
|
||||||
const header = new Headers();
|
const header = new Headers();
|
||||||
|
@ -60,8 +67,6 @@ export enum StreamTypeEnum {
|
||||||
|
|
||||||
export class TootWrapper {
|
export class TootWrapper {
|
||||||
constructor(status: Status) {
|
constructor(status: Status) {
|
||||||
console.warn(status);
|
|
||||||
|
|
||||||
this.account = new AccountWrapper();
|
this.account = new AccountWrapper();
|
||||||
this.account.username = status.account.username;
|
this.account.username = status.account.username;
|
||||||
this.account.display_name = status.account.display_name;
|
this.account.display_name = status.account.display_name;
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue