IC.Video.Stream client js - imonology/ImonCloud-Doc GitHub Wiki

TOC
新增移除 Stream 來源


IC.Video.Stream (Client side library)

Client side (Viewer / Web) 使用的 Stream 函式庫


SYNOPSIS

var streamID = document.getElementById('vid').value;
var videoTagPlayer = document.getElementById('video');

// Stream should already been added and enabled by server.

IC.Video.Stream.start(
	streamID,
	videoTagPlayer,
	function ( err, ret ) {
		// ret === { type: 'xxx', originSource: 'xxx', streamID: 'xxx', status: 'streaming'}
	}
);

IC.Video.Stream.stop(
	streamID,
	videoTagPlayer,
	function ( err, ret ) {
		// ret === { type: 'xxx', originSource: 'xxx', streamID: 'xxx', status: 'enabled'}
	}
);

The returned status is Not a Must Have.


ATTRIBUTES

None.


METHODS

new

新增影音串流來源 (目前前端不使用)

new( args, onDone )

var originSource = document.getElementById('address').value;
// 'rtsp://10.20.30.40:554/video1.sdp';

IC.Video.Stream.new(
	{ type: 'rtsp', source: originSource},
	function ( err, ret ) {
		// ret === { type: 'xxx', originSource: 'xxx', streamID: 'xxx', status: 'disabled' }
	}
);
  • input
    args should contain at least type and source.
    type currently supports rtsp and custom.
    If type: 'custom', you must add format: {} in args.
  • callback
    If the stream already exists (identified by originSource), return the existing data. Newly added stream will have the status: 'disabled' by default.
  • return
    None.

delete

移除影音串流來源 (目前前端不使用)

delete( streamID, onDone )

var streamID = document.getElementById('vid').value;	// string
IC.Video.Stream.delete(
	streamID,
	function ( err, ret ) {
		// ret === { type: 'xxx', originSource: 'xxx', streamID: 'xxx', status: 'enabled'}
	}
);
  • input
  • callback
    status will be the last status before it's been deleted. If some clients are still streaming from this stream before the operation, they should be stopped and stream should be disabled by server.
  • return
    None.

enable

啟用影音串流 (目前前端不使用)

enable( streamID, onDone )

var streamID = 'an ID of an stream';
IC.Video.Stream.enable(
	streamID,
	function ( err, ret ) {
		// ret === { type: 'xxx', originSource: 'xxx', streamID: 'xxx', status: 'enabled' }
	}
);
  • input
  • callback
  • return
    None.

disable

停用影音串流 (目前前端不使用)

disable( streamID, onDone )

var streamID = 'an ID of an stream';
IC.Video.Stream.disable(
	streamID,
	function ( err, ret ) {
		// ret === { type: 'xxx', originSource: 'xxx', streamID: 'xxx', status: 'disabled' }
	}
);
  • input
  • callback
  • return
    None.

start

開始播放串流

start( streamID, player, onDone )

var streamID = document.getElementById('vid').value;	// string
var player = document.getElementById('video');	// video tag object
IC.Video.Stream.start(
	streamID,
	player,
	function ( err, ret ) {
		// ret === { type: 'xxx', originSource: 'xxx', streamID: 'xxx', status: 'streaming' }
	}
);

You must have a video object.

  • input
  • callback
  • return
    None.

stop

停止播放串流 (並釋放針對此 client 的 WebRTC 資源)

stop( streamID, onDone )

var streamID = document.getElementById('vid').value;	// string
var player = document.getElementById('video');	// video tag object
IC.Video.Stream.stop(
	streamID,
	player,
	function ( err, ret ) {
		// ret === { type: 'xxx', originSource: 'xxx', streamID: 'xxx', status: 'enabled' }
	}
);

You must have a video object currently streaming.

  • input
  • callback
    If there's anyone using the stream after this operation, status shows 'streaming', otherwise 'enabled'.
  • return
    None.

info

取得串流列表

info(streamIDs, onDone);

var streamID_1 = [document.getElementById('vid').value];
var streamIDs = ['streamID_1', 'streamID_2', 'streamID_3'];

IC.Video.Stream.info( [], function () {} );	// return all streams
IC.Video.Stream.info(
	streamIDs,
	function ( err, ret ) {
		// ret === [
		//	{ type: 'xxx', originSource: 'xxx', streamID: 'xxx', status: 'streaming' },
		//	{ type: 'yyy', originSource: 'yyy', streamID: 'yyy', status: 'enabled' },
		//	{ type: 'zzz', originSource: 'zzz', streamID: 'zzz', status: 'disabled' },
		//]
	}
);
  • input
    If streamIDs is an empty array, return all streams info. Otherwise return specified streams.
  • callback
  • return
    None.