cast.
            管理投屏互动。使用 getInstance 获取的单例对象。管理状态 - 提供投放图标和会话对象的状态。 在 setOptions 提供投射选项之前,不支持投射互动。
构造函数
CastContext
new CastContext()
方法
getInstance
getInstance() returns cast.framework.CastContext
返回 CastContext 单例实例。
- 返回
- 
                  cast.framework.CastContextCastContext 的单例实例。
addEventListener
addEventListener(type, handler)
添加事件侦听器。
| 参数 | |
|---|---|
| 类型 | cast.framework.CastContextEventType 事件类型。 值不能为 null。 | 
| handler | (non-null function(non-null cast.framework.CastStateEventData) or non-null function(non-null cast.framework.SessionStateEventData)) | 
endCurrentSession
endCurrentSession(stopCasting)
结束当前会话。
| 参数 | |
|---|---|
| stopCasting | boolean 接收器应用是停止还是断开连接。 | 
getCastState
getCastState() 返回 cast.framework.CastState
- 返回
- 
                  non-null cast.framework.CastState:当前的投放图标状态。
getCurrentSession
getCurrentSession() 会返回 cast.framework.CastSession
- 返回
- 
                  nullable cast.framework.CastSession当前会话。
getSessionState
getSessionState() 会返回 cast.framework.SessionState
- 返回
- 
                  non-null cast.framework.SessionState:当前会话状态。
removeEventListener
removeEventListener(type, handler)
删除事件监听器。
| 参数 | |
|---|---|
| 类型 | cast.framework.CastContextEventType 事件类型。 值不能为 null。 | 
| handler | (non-null function(non-null cast.framework.CastStateEventData) or non-null function(non-null cast.framework.SessionStateEventData)) | 
requestSession
requestSession() 返回包含可为 null 的 chrome.cast.ErrorCode 的 Promise
打开投射选择界面,以便用户启动或停止会话。
- 抛出
- 
                  Error:如果尚未提供上下文选项。
- 返回
- 
                  non-null Promise containing nullable chrome.cast.ErrorCode:一个 promise,用于指示会话正在启动或失败(被拒绝,并显示错误代码)。
setLaunchCredentialsData
setLaunchCredentialsData(credentialsData)
设置用户凭据数据。如果在 setOptions 之前调用,则会被忽略。在 setLaunchCredentialsData 之后调用 setOptions 将清除 setLaunchCredentialsData 中设置的值。
| 参数 | |
|---|---|
| credentialsData | 凭据数据,用于识别发送者的凭据。 值不能为 null。 | 
setOptions
setOptions(options)
设置投射选项。 只有在提供配置后,系统才会发送事件。
| 参数 | |
|---|---|
| 选项 | 网页的投放选项。 值不能为 null。 | 
- 抛出
- 
                  non-null Error如果选项中缺少应用 ID。