forked from Streamedian/html5_rtsp_player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.js
63 lines (58 loc) · 2.08 KB
/
player.js
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
import {LogLevel, getTagged, setDefaultLogLevel} from 'bp_logger';
import * as streamedian from 'streamedian/player.js';
import WebsocketTransport from 'streamedian/transport/websocket.js';
import RTSPClient from 'streamedian/client/rtsp/client.js';
import {isSafari} from "streamedian/core/util/browser.js";
setDefaultLogLevel(LogLevel.Error);
getTagged("transport:ws").setLevel(LogLevel.Error);
getTagged("client:rtsp").setLevel(LogLevel.Debug);
getTagged("mse").setLevel(LogLevel.Debug);
window.Streamedian = {
logger(tag) {
return getTagged(tag)
},
player(node, opts) {
if (!opts.socket) {
throw new Error("socket parameter is not set");
}
let _options = {
modules: [
{
client: RTSPClient,
transport: {
constructor: WebsocketTransport,
options: {
socket: opts.socket
}
}
}
],
errorHandler(e) {
if(opts.errorHandler) {
opts.errorHandler(e);
} else {
alert(`Failed to start player: ${e.message}`);
}
},
infoHandler(inf) {
if(opts.infoHandler) {
opts.infoHandler(inf);
}
},
redirectNativeMediaErrors: opts.redirectNativeMediaErrors,
bufferDuration : opts.bufferDuration,
queryCredentials(client) {
return new Promise((resolve, reject) => {
let c = prompt('input credentials in format user:password');
if (c) {
client.setCredentials.apply(client, c.split(':'));
resolve();
} else {
reject();
}
});
}
};
return new streamedian.WSPlayer(node, _options);
}
};