-
Notifications
You must be signed in to change notification settings - Fork 14
/
bitmovinCastManager.ts
87 lines (81 loc) · 3.06 KB
/
bitmovinCastManager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { NativeModules, Platform } from 'react-native';
const BitmovinCastManagerModule = NativeModules.BitmovinCastManagerModule;
/**
* The options to be used for initializing `BitmovinCastManager`
* @platform Android, iOS
*/
export interface BitmovinCastManagerOptions {
/**
* ID of receiver application.
* Using `null` value will result in using the default application ID
*/
applicationId?: string | null;
/**
* A custom message namespace to be used for communication between sender and receiver.
* Using `null` value will result in using the default message namespace
*/
messageNamespace?: string | null;
}
/**
* Singleton providing access to GoogleCast related features.
* The `BitmovinCastManager` needs to be initialized by calling `BitmovinCastManager.initialize`
* before `Player` creation to enable casting features.
*
* @platform Android, iOS
*/
export const BitmovinCastManager = {
/**
* Returns whether the `BitmovinCastManager` is initialized.
* @returns A promise that resolves with a boolean indicating whether the `BitmovinCastManager` is initialized
*/
isInitialized: async (): Promise<boolean> => {
if (Platform.OS === 'ios' && Platform.isTV) {
return false;
}
return BitmovinCastManagerModule.isInitialized();
},
/**
* Initialize `BitmovinCastManager` based on the provided `BitmovinCastManagerOptions`.
* This method needs to be called before `Player` creation to enable casting features.
* If no options are provided, the default options will be used.
*
* IMPORTANT: This should only be called when the Google Cast SDK is available in the application.
*
* @param options The options to be used for initializing `BitmovinCastManager`
* @returns A promise that resolves when the `BitmovinCastManager` was initialized successfully
*/
initialize: async (
options: BitmovinCastManagerOptions | null = null
): Promise<void> => {
if (Platform.OS === 'ios' && Platform.isTV) {
return Promise.resolve();
}
return BitmovinCastManagerModule.initializeCastManager(options);
},
/**
* Must be called in every Android Activity to update the context to the current one.
* Make sure to call this method on every Android Activity switch.
*
* @returns A promise that resolves when the context was updated successfully
* @platform Android
*/
updateContext: async (): Promise<void> => {
if (Platform.OS === 'ios') {
return Promise.resolve();
}
return BitmovinCastManagerModule.updateContext();
},
/**
* Sends the given message to the cast receiver.
*
* @param message The message to be sent
* @param messageNamespace The message namespace to be used, in case of null the default message namespace will be used
* @returns A promise that resolves when the message was sent successfully
*/
sendMessage: (message: String, messageNamespace: String | null = null) => {
if (Platform.OS === 'ios' && Platform.isTV) {
return Promise.resolve();
}
return BitmovinCastManagerModule.sendMessage(message, messageNamespace);
},
};