UNPKG

react-native-theoplayer

Version:

A THEOplayer video component for react-native.

46 lines (45 loc) 1.43 kB
"use strict"; import { CastEventType, CastState, PlayerEventType } from 'react-native-theoplayer'; import { NativeModules } from 'react-native'; const NativeCastModule = NativeModules.THEORCTCastModule; export class THEOplayerNativeChromecast { _casting = false; _state = CastState.available; constructor(player, view) { this._player = player; this._view = view; this._player.addEventListener(PlayerEventType.CAST_EVENT, this._onCastStateChange); } async init_() { this._casting = await NativeCastModule.chromecastCasting(this._view.nativeHandle); this._state = await NativeCastModule.chromecastState(this._view.nativeHandle); } _onCastStateChange = event => { if (event.subType === CastEventType.CHROMECAST_STATE_CHANGE) { this._state = event.state; this._casting = event.state === 'connected'; } }; get casting() { return this._casting; } get state() { return this._state; } start() { NativeCastModule.chromecastStart(this._view.nativeHandle); } stop() { NativeCastModule.chromecastStop(this._view.nativeHandle); } join() { NativeCastModule.chromecastJoin(this._view.nativeHandle); } leave() { NativeCastModule.chromecastLeave(this._view.nativeHandle); } unload_() { this._player.removeEventListener(PlayerEventType.CAST_EVENT, this._onCastStateChange); } } //# sourceMappingURL=THEOplayerNativeChromecast.js.map