UNPKG

react-native-theoplayer

Version:

A THEOplayer video component for react-native.

39 lines (38 loc) 1.24 kB
"use strict"; import { CastEventType, CastState, PlayerEventType } from 'react-native-theoplayer'; import { NativeModules } from 'react-native'; const NativeCastModule = NativeModules.THEORCTCastModule; export class THEOplayerNativeAirplay { _casting = false; _state = CastState.available; constructor(player) { this._player = player; this._player.addEventListener(PlayerEventType.CAST_EVENT, this._onCastStateChange); } async init_() { this._casting = await NativeCastModule.airplayCasting(this._player.nativeHandle); this._state = await NativeCastModule.airplayState(this._player.nativeHandle); } _onCastStateChange = event => { if (event.subType === CastEventType.AIRPLAY_STATE_CHANGE) { this._state = event.state; this._casting = event.state === CastState.connected; } }; get casting() { return this._casting; } get state() { return this._state; } start() { NativeCastModule.airplayStart(this._player.nativeHandle); } stop() { NativeCastModule.airplayStop(this._player.nativeHandle); } unload_() { this._player.removeEventListener(PlayerEventType.CAST_EVENT, this._onCastStateChange); } } //# sourceMappingURL=THEOplayerNativeAirplay.js.map