import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { mergeMap } from 'rxjs/operators' ; import { of , throwError } from 'rxjs' ; @ Injectable ( { providedIn : 'root' } ) export class DPlayerApiService { constructor ( private http ) { } sendDanmaku ( options ) { this . http . post ( options . url , options . data ) . pipe ( mergeMap ( ( data ) => data . code !== 0 ? throwError ( data . msg ) : of ( data . data ) ) ) . subscribe ( options . success , options . error ) ; } readDanmaku ( options ) { this . http . get ( options . url ) . pipe ( mergeMap ( ( data ) => data . code !== 0 ? throwError ( data . msg ) : of ( data . data . map ( ( item ) => ( { time : item [ 0 ] , type : item [ 1 ] , color : item [ 2 ] , author : item [ 3 ] , text : item [ 4 ] } ) ) ) ) ) . subscribe ( options . success , options . error ) ; } }