diff --git a/README.md b/README.md index 4a1adc4..bb0c4e7 100644 --- a/README.md +++ b/README.md @@ -180,15 +180,20 @@ local:127.0.0.1\ 127.0.0.1\ \# at the beginning of the line, comment +# +### MSX Install: +Open msx and goto: Settings -> Start Parameter -> Setup \ +Enter current ip address and port of server e.g. _127.0.0.1:8090_ # ### Donate: -[PayPal](https://www.paypal.me/yourok) +[PayPal](https://www.paypal.me/yourok) \ +[QIWI](qiwi.com/n/YOUROK85) \ +[YooMoney](https://yoomoney.ru/to/410013733697114/200) -[YooMoney](https://yoomoney.ru/to/410013733697114/200) -YooMoney card: 4048 4150 1812 8179 +SberBank card: **4276 4000 6707 2919** -SberBank card: 4276 4000 6707 2919 +YooMoney card: **4048 4150 1812 8179** # @@ -200,6 +205,8 @@ SberBank card: 4276 4000 6707 2919 ###### **dancheskus** [github.com/dancheskus](https://github.com/dancheskus) +###### **kolsys** [github.com/kolsys](https://github.com/kolsys) + ###### **Tw1cker Руслан Пахнев** [github.com/Nemiroff](https://github.com/Nemiroff) -###### **SpAwN_LMG** +###### **SpAwN_LMG** [github.com/spawnlmg](https://github.com/spawnlmg) diff --git a/build-all.sh b/build-all.sh index bae13b4..ee37d91 100755 --- a/build-all.sh +++ b/build-all.sh @@ -83,11 +83,6 @@ done ### Android build section ##### -if [ -z "$NDK_TOOLCHAIN" ]; then - echo "NDK_TOOLCHAIN is not defined. Android builds was skipped" - exit -fi - declare -a COMPILERS=( "arm7:armv7a-linux-androideabi21-clang" "arm64:aarch64-linux-android21-clang" diff --git a/server/dlna/dlna.go b/server/dlna/dlna.go index 9bdd7e4..5c03135 100644 --- a/server/dlna/dlna.go +++ b/server/dlna/dlna.go @@ -49,20 +49,6 @@ func Start() { NoProbe: true, StallEventSubscribe: true, Icons: []dms.Icon{ - // dms.Icon{ - // Width: 48, - // Height: 48, - // Depth: 24, - // Mimetype: "image/jpeg", - // ReadSeeker: bytes.NewReader(template.Dlnaicon48jpg), - // }, - // dms.Icon{ - // Width: 120, - // Height: 120, - // Depth: 24, - // Mimetype: "image/jpeg", - // ReadSeeker: bytes.NewReader(template.Dlnaicon120jpg), - // }, dms.Icon{ Width: 48, Height: 48, diff --git a/server/torr/apihelper.go b/server/torr/apihelper.go index a2a58ca..272f654 100644 --- a/server/torr/apihelper.go +++ b/server/torr/apihelper.go @@ -243,8 +243,8 @@ func Preload(torr *Torrent, index int) { cache := float32(sets.BTsets.CacheSize) preload := float32(sets.BTsets.PreloadCache) size := int64((cache / 100.0) * preload) - if size < 32*1024*1024 { - size = 32 * 1024 * 1024 + if size <= 0 { + return } if size > sets.BTsets.CacheSize { size = sets.BTsets.CacheSize diff --git a/server/web/cors/config.go b/server/web/cors/config.go new file mode 100644 index 0000000..d4fc118 --- /dev/null +++ b/server/web/cors/config.go @@ -0,0 +1,134 @@ +package cors + +import ( + "net/http" + "strings" + + "github.com/gin-gonic/gin" +) + +type cors struct { + allowAllOrigins bool + allowCredentials bool + allowOriginFunc func(string) bool + allowOrigins []string + exposeHeaders []string + normalHeaders http.Header + preflightHeaders http.Header + wildcardOrigins [][]string +} + +var ( + DefaultSchemas = []string{ + "http://", + "https://", + } + ExtensionSchemas = []string{ + "chrome-extension://", + "safari-extension://", + "moz-extension://", + "ms-browser-extension://", + } + FileSchemas = []string{ + "file://", + } + WebSocketSchemas = []string{ + "ws://", + "wss://", + } +) + +func newCors(config Config) *cors { + if err := config.Validate(); err != nil { + panic(err.Error()) + } + + return &cors{ + allowOriginFunc: config.AllowOriginFunc, + allowAllOrigins: config.AllowAllOrigins, + allowCredentials: config.AllowCredentials, + allowOrigins: normalize(config.AllowOrigins), + normalHeaders: generateNormalHeaders(config), + preflightHeaders: generatePreflightHeaders(config), + wildcardOrigins: config.parseWildcardRules(), + } +} + +func (cors *cors) applyCors(c *gin.Context) { + origin := c.Request.Header.Get("Origin") + if len(origin) == 0 { + // request is not a CORS request + return + } + host := c.Request.Host + + if origin == "http://"+host || origin == "https://"+host { + // request is not a CORS request but have origin header. + // for example, use fetch api + return + } + + if !cors.validateOrigin(origin) { + c.AbortWithStatus(http.StatusForbidden) + return + } + + if c.Request.Method == "OPTIONS" { + cors.handlePreflight(c) + defer c.AbortWithStatus(http.StatusNoContent) // Using 204 is better than 200 when the request status is OPTIONS + } else { + cors.handleNormal(c) + } + + if !cors.allowAllOrigins { + c.Header("Access-Control-Allow-Origin", origin) + } +} + +func (cors *cors) validateWildcardOrigin(origin string) bool { + for _, w := range cors.wildcardOrigins { + if w[0] == "*" && strings.HasSuffix(origin, w[1]) { + return true + } + if w[1] == "*" && strings.HasPrefix(origin, w[0]) { + return true + } + if strings.HasPrefix(origin, w[0]) && strings.HasSuffix(origin, w[1]) { + return true + } + } + + return false +} + +func (cors *cors) validateOrigin(origin string) bool { + if cors.allowAllOrigins { + return true + } + for _, value := range cors.allowOrigins { + if value == origin { + return true + } + } + if len(cors.wildcardOrigins) > 0 && cors.validateWildcardOrigin(origin) { + return true + } + if cors.allowOriginFunc != nil { + return cors.allowOriginFunc(origin) + } + return false +} + +func (cors *cors) handlePreflight(c *gin.Context) { + header := c.Writer.Header() + for key, value := range cors.preflightHeaders { + header[key] = value + } +} + +func (cors *cors) handleNormal(c *gin.Context) { + header := c.Writer.Header() + for key, value := range cors.normalHeaders { + header[key] = value + } +} diff --git a/server/web/cors/cors.go b/server/web/cors/cors.go new file mode 100644 index 0000000..709418f --- /dev/null +++ b/server/web/cors/cors.go @@ -0,0 +1,174 @@ +package cors + +import ( + "errors" + "strings" + "time" + + "github.com/gin-gonic/gin" +) + +// Config represents all available options for the middleware. +type Config struct { + AllowAllOrigins bool + + // AllowOrigins is a list of origins a cross-domain request can be executed from. + // If the special "*" value is present in the list, all origins will be allowed. + // Default value is [] + AllowOrigins []string + + // AllowOriginFunc is a custom function to validate the origin. It take the origin + // as argument and returns true if allowed or false otherwise. If this option is + // set, the content of AllowOrigins is ignored. + AllowOriginFunc func(origin string) bool + + // AllowMethods is a list of methods the client is allowed to use with + // cross-domain requests. Default value is simple methods (GET and POST) + AllowMethods []string + + // AllowHeaders is list of non simple headers the client is allowed to use with + // cross-domain requests. + AllowHeaders []string + + // AllowCredentials indicates whether the request can include user credentials like + // cookies, HTTP authentication or client side SSL certificates. + AllowCredentials bool + + // AllowPrivateNetwork + AllowPrivateNetwork bool + + // ExposedHeaders indicates which headers are safe to expose to the API of a CORS + // API specification + ExposeHeaders []string + + // MaxAge indicates how long (in seconds) the results of a preflight request + // can be cached + MaxAge time.Duration + + // Allows to add origins like http://some-domain/*, https://api.* or http://some.*.subdomain.com + AllowWildcard bool + + // Allows usage of popular browser extensions schemas + AllowBrowserExtensions bool + + // Allows usage of WebSocket protocol + AllowWebSockets bool + + // Allows usage of file:// schema (dangerous!) use it only when you 100% sure it's needed + AllowFiles bool +} + +// AddAllowMethods is allowed to add custom methods +func (c *Config) AddAllowMethods(methods ...string) { + c.AllowMethods = append(c.AllowMethods, methods...) +} + +// AddAllowHeaders is allowed to add custom headers +func (c *Config) AddAllowHeaders(headers ...string) { + c.AllowHeaders = append(c.AllowHeaders, headers...) +} + +// AddExposeHeaders is allowed to add custom expose headers +func (c *Config) AddExposeHeaders(headers ...string) { + c.ExposeHeaders = append(c.ExposeHeaders, headers...) +} + +func (c Config) getAllowedSchemas() []string { + allowedSchemas := DefaultSchemas + if c.AllowBrowserExtensions { + allowedSchemas = append(allowedSchemas, ExtensionSchemas...) + } + if c.AllowWebSockets { + allowedSchemas = append(allowedSchemas, WebSocketSchemas...) + } + if c.AllowFiles { + allowedSchemas = append(allowedSchemas, FileSchemas...) + } + return allowedSchemas +} + +func (c Config) validateAllowedSchemas(origin string) bool { + allowedSchemas := c.getAllowedSchemas() + for _, schema := range allowedSchemas { + if strings.HasPrefix(origin, schema) { + return true + } + } + return false +} + +// Validate is check configuration of user defined. +func (c *Config) Validate() error { + if c.AllowAllOrigins && (c.AllowOriginFunc != nil || len(c.AllowOrigins) > 0) { + return errors.New("conflict settings: all origins are allowed. AllowOriginFunc or AllowOrigins is not needed") + } + if !c.AllowAllOrigins && c.AllowOriginFunc == nil && len(c.AllowOrigins) == 0 { + return errors.New("conflict settings: all origins disabled") + } + for _, origin := range c.AllowOrigins { + if origin == "*" { + c.AllowAllOrigins = true + return nil + } else if !strings.Contains(origin, "*") && !c.validateAllowedSchemas(origin) { + return errors.New("bad origin: origins must contain '*' or include " + strings.Join(c.getAllowedSchemas(), ",")) + } + } + return nil +} + +func (c Config) parseWildcardRules() [][]string { + var wRules [][]string + + if !c.AllowWildcard { + return wRules + } + + for _, o := range c.AllowOrigins { + if !strings.Contains(o, "*") { + continue + } + + if c := strings.Count(o, "*"); c > 1 { + panic(errors.New("only one * is allowed").Error()) + } + + i := strings.Index(o, "*") + if i == 0 { + wRules = append(wRules, []string{"*", o[1:]}) + continue + } + if i == (len(o) - 1) { + wRules = append(wRules, []string{o[:i-1], "*"}) + continue + } + + wRules = append(wRules, []string{o[:i], o[i+1:]}) + } + + return wRules +} + +// DefaultConfig returns a generic default configuration mapped to localhost. +func DefaultConfig() Config { + return Config{ + AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"}, + AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"}, + AllowCredentials: false, + MaxAge: 12 * time.Hour, + } +} + +// Default returns the location middleware with default configuration. +func Default() gin.HandlerFunc { + config := DefaultConfig() + config.AllowAllOrigins = true + return New(config) +} + +// New returns the location middleware with user-defined custom configuration. +func New(config Config) gin.HandlerFunc { + cors := newCors(config) + return func(c *gin.Context) { + cors.applyCors(c) + } +} diff --git a/server/web/cors/utils.go b/server/web/cors/utils.go new file mode 100644 index 0000000..118e28e --- /dev/null +++ b/server/web/cors/utils.go @@ -0,0 +1,88 @@ +package cors + +import ( + "net/http" + "strconv" + "strings" + "time" +) + +type converter func(string) string + +func generateNormalHeaders(c Config) http.Header { + headers := make(http.Header) + if c.AllowCredentials { + headers.Set("Access-Control-Allow-Credentials", "true") + } + if c.AllowPrivateNetwork { + headers.Set("Access-Control-Allow-Private-Network", "true") + } + if len(c.ExposeHeaders) > 0 { + exposeHeaders := convert(normalize(c.ExposeHeaders), http.CanonicalHeaderKey) + headers.Set("Access-Control-Expose-Headers", strings.Join(exposeHeaders, ",")) + } + if c.AllowAllOrigins { + headers.Set("Access-Control-Allow-Origin", "*") + } else { + headers.Set("Vary", "Origin") + } + return headers +} + +func generatePreflightHeaders(c Config) http.Header { + headers := make(http.Header) + if c.AllowCredentials { + headers.Set("Access-Control-Allow-Credentials", "true") + } + if len(c.AllowMethods) > 0 { + allowMethods := convert(normalize(c.AllowMethods), strings.ToUpper) + value := strings.Join(allowMethods, ",") + headers.Set("Access-Control-Allow-Methods", value) + } + if len(c.AllowHeaders) > 0 { + allowHeaders := convert(normalize(c.AllowHeaders), http.CanonicalHeaderKey) + value := strings.Join(allowHeaders, ",") + headers.Set("Access-Control-Allow-Headers", value) + } + if c.MaxAge > time.Duration(0) { + value := strconv.FormatInt(int64(c.MaxAge/time.Second), 10) + headers.Set("Access-Control-Max-Age", value) + } + if c.AllowAllOrigins { + headers.Set("Access-Control-Allow-Origin", "*") + } else { + // Always set Vary headers + // see https://github.com/rs/cors/issues/10, + // https://github.com/rs/cors/commit/dbdca4d95feaa7511a46e6f1efb3b3aa505bc43f#commitcomment-12352001 + + headers.Add("Vary", "Origin") + headers.Add("Vary", "Access-Control-Request-Method") + headers.Add("Vary", "Access-Control-Request-Headers") + } + return headers +} + +func normalize(values []string) []string { + if values == nil { + return nil + } + distinctMap := make(map[string]bool, len(values)) + normalized := make([]string, 0, len(values)) + for _, value := range values { + value = strings.TrimSpace(value) + value = strings.ToLower(value) + if _, seen := distinctMap[value]; !seen { + normalized = append(normalized, value) + distinctMap[value] = true + } + } + return normalized +} + +func convert(s []string, c converter) []string { + var out []string + for _, i := range s { + out = append(out, c(i)) + } + return out +} diff --git a/server/web/msx/html.go b/server/web/msx/html.go index 394bbb6..8d241a7 100644 --- a/server/web/msx/html.go +++ b/server/web/msx/html.go @@ -2,11 +2,11 @@ package msx import _ "embed" +//go:embed pages/html5x.html +var Msxhtml5xhtml []byte + //go:embed pages/tizen.html var Msxtizenhtml []byte -//go:embed pages/tizen.js -var Msxtizenjs []byte - //go:embed pages/tvx-plugin.min.js var Msxtvxpluginminjs []byte diff --git a/server/web/msx/msx.go b/server/web/msx/msx.go index 912f90a..0dfdab8 100644 --- a/server/web/msx/msx.go +++ b/server/web/msx/msx.go @@ -66,6 +66,8 @@ type msxPage struct { Items []gin.H `json:"items,omitempty"` } +const ICON_OPTIONS = "tune" + func msxStart(c *gin.Context) { c.JSON(200, gin.H{ "name": "TorrServer", @@ -173,6 +175,7 @@ func msxPlaylist(c *gin.Context) { status := tor.Status() viewed := sets.ListViewed(hash) var list []msxItem + contentAction := "" for _, f := range status.FileStats { mime := utils.GetMimeType(f.Path) @@ -196,24 +199,16 @@ func msxPlaylist(c *gin.Context) { "uri": uri, "type": mime, } - } else if platform == "lg" { - // TODO - custom player needed - //item.Action = "system:lg:launch:com.webos.app.mediadiscovery" - //item.Data = gin.H{ - // "properties": gin.H{ - // "videoList": gin.H{ - // "result": [1]gin.H{ - // gin.H{ - // "url": uri, - // "thumbnail": tor.Poster, - // }, - // }, - // }, - // }, - //} + } else if platform == "tizen" { + contentAction = "content:request:interaction:init@" + host + "/msx/tizen.html" + } else if platform == "netcast" { + contentAction = "system:netcast:menu" } else if platform == "ios" || platform == "mac" { // TODO - for iOS and Mac the application must be defined in scheme but we don't know what user has installed item.Action = "system:tvx:launch:vlc://" + uri + } else { + item.Action = "video:plugin:" + host + "/msx/html5x.html?url= " + url.QueryEscape(uri) + contentAction = "panel:request:player:options" } if isViewed(viewed, f.Id) { @@ -247,23 +242,13 @@ func msxPlaylist(c *gin.Context) { Items: list, } - if platform == "tizen" { + if contentAction != "" { res.Template.Properties = gin.H{ - "button:content:icon": "tune", - "button:content:action": "content:request:interaction:init@" + host + "/msx/tizen.html", - } - } else if platform == "netcast" { - res.Template.Properties = gin.H{ - "button:content:icon": "tune", - "button:content:action": "system:netcast:menu", + "button:content:icon": ICON_OPTIONS, + "button:content:action": contentAction, } } - // If only one item start to play immediately but it not works - // if (len(list) == 1) { - // res.Action = "execute:" + list[0].Action - // } - c.JSON(200, res) } diff --git a/server/web/msx/pages/html5x.html b/server/web/msx/pages/html5x.html new file mode 100644 index 0000000..4478be4 --- /dev/null +++ b/server/web/msx/pages/html5x.html @@ -0,0 +1,763 @@ + + + + HTML5 Extended Video Plugin + + + + + + + + + + + + \ No newline at end of file diff --git a/server/web/msx/pages/tizen.html b/server/web/msx/pages/tizen.html index d4b31cc..c686a19 100644 --- a/server/web/msx/pages/tizen.html +++ b/server/web/msx/pages/tizen.html @@ -7,7 +7,373 @@ - + diff --git a/server/web/msx/pages/tizen.js b/server/web/msx/pages/tizen.js deleted file mode 100644 index 306b752..0000000 --- a/server/web/msx/pages/tizen.js +++ /dev/null @@ -1,365 +0,0 @@ -/******************************************************************************/ -//Tizen Interaction Plugin v0.0.1 -//(c) 2021 Benjamin Zachey -//Action syntax example: -//- "content:request:interaction:init@http://msx.benzac.de/interaction/tizen.html" -/******************************************************************************/ - -/******************************************************************************/ -//TizenPlayer -/******************************************************************************/ -function TizenPlayer() { - var pushToArray = function(array, items) { - if (array != null && items != null) { - if (Array.isArray(items)) { - for (var i = 0; i < items.length; i++) { - array.push(items[i]); - } - } else { - array.push(items); - } - } - }; - var getValueLabel = function(value) { - if (typeof value == "string") { - return TVXTools.strFullCheck(value, "-"); - } - return value != null ? TVXTools.strValue(value) : "-"; - }; - var getPropertyLabel = function(value, unit) { - if (TVXTools.isFullStr(value) && value.indexOf("|") >= 0) { - return value.split("|")[0]; - } - if (value != null) { - if (unit != null) { - return value + " " + unit; - } - return TVXTools.strValue(value); - } - return "Unknown"; - }; - var getPropertyValue = function(value) { - if (TVXTools.isFullStr(value) && value.indexOf("|") >= 0) { - value = value.split("|")[1]; - } - if (TVXTools.isFullStr(value) && value.indexOf("num:") == 0) { - return TVXTools.strToNum(value.substr(4)); - } - return value; - }; - var getTrackLabel = function(track) { - if (track != null) { - var prefix = "Track " + track.index; - var suffix = track.info != null ? track.info.language : null;//Audio track - if (suffix == null) { - suffix = track.info != null ? track.info.track_lang : null;//Text track - } - return TVXTools.isFullStr(suffix) ? prefix + " (" + suffix + ")" : prefix; - } - return "None"; - }; - var createPropertyControls = function(y, propertyIcon, propertyLabel, propertyKey, propertyValue, propertyUnit, availableValues, nextButton) { - var panelItems = []; - var selectedPropertyLabel = getPropertyLabel(propertyValue, propertyUnit); - var firstPropertyValue = null; - var nextPropertyValue = null; - var selectNext = false; - if (availableValues != null) { - for (var i = 0; i < availableValues.length; i++) { - var value = getPropertyValue(availableValues[i]); - var label = getPropertyLabel(availableValues[i], propertyUnit); - var selected = value === propertyValue; - if (firstPropertyValue == null) { - firstPropertyValue = value; - } - if (selected) { - selectNext = true; - selectedPropertyLabel = label; - } else if (selectNext) { - selectNext = false; - nextPropertyValue = value; - } - panelItems.push({ - focus: selected, - extensionIcon: selected ? "check" : "blank", - label: label, - action: selected ? "back" : "[invalidate:content|back|player:commit]", - data: { - key: propertyKey, - value: value, - action: "reload:content" - } - }); - } - } - if (nextPropertyValue == null) { - nextPropertyValue = firstPropertyValue; - } - return [{ - enable: panelItems.length > 0, - type: "control", - layout: "0," + y + "," + (nextButton ? "7,1" : "8,1"), - icon: propertyIcon, - label: propertyLabel, - extensionLabel: selectedPropertyLabel, - action: "panel:data", - data: { - headline: propertyLabel, - compress: panelItems.length > 6, - template: { - type: "control", - enumerate: false, - layout: panelItems.length > 8 ? "0,0,5,1" : panelItems.length > 6 ? "0,0,10,1" : "0,0,8,1" - }, - items: panelItems - } - }, { - display: nextButton, - enable: nextPropertyValue != null, - type: "button", - icon: "navigate-next", - iconSize: "small", - layout: "7," + y + ",1,1", - action: "[invalidate:content|player:commit]", - data: { - key: propertyKey, - value: nextPropertyValue, - action: "reload:content" - } - }]; - }; - var createTrackControl = function(y, propertyIcon, propertyLabel, propertyKey, currentTrack, availableTracks) { - var panelItems = []; - if (availableTracks != null) { - for (var i = 0; i < availableTracks.length; i++) { - var track = availableTracks[i]; - var selected = track.index === (currentTrack != null ? currentTrack.index : -1); - panelItems.push({ - focus: selected, - extensionIcon: selected ? "check" : "blank", - label: getTrackLabel(track), - action: selected ? "back" : "[invalidate:content|back|player:commit]", - data: { - key: propertyKey, - value: track.index, - action: "reload:content" - } - }); - } - } - return { - enable: panelItems.length > 0, - type: "control", - layout: "0," + y + ",8,1", - icon: propertyIcon, - label: propertyLabel, - extensionLabel: getTrackLabel(currentTrack), - action: "panel:data", - data: { - headline: propertyLabel, - compress: panelItems.length > 6, - template: { - type: "control", - enumerate: false, - layout: panelItems.length > 8 ? "0,0,5,1" : panelItems.length > 6 ? "0,0,10,1" : "0,0,8,1" - }, - items: panelItems - } - }; - }; - var createControlItems = function(infoData) { - var items = []; - pushToArray(items, createPropertyControls(0, "featured-video", "Display Area", "tizen:display:area", - infoData && infoData.display != null ? infoData.display.area : null, null, [ - "21x9|0,0.119,1,0.762", - "16x9 (Default)|0,0,1,1", - "4x3|0.125,0,0.75,1" - ], true)); - pushToArray(items, createPropertyControls(1, "aspect-ratio", "Display Mode", "tizen:display:mode", - infoData != null && infoData.display != null ? infoData.display.mode : null, null, [ - "Fit Screen (Default)|PLAYER_DISPLAY_MODE_LETTER_BOX", - "Fill Screen|PLAYER_DISPLAY_MODE_FULL_SCREEN", - "Auto Aspect Ratio|PLAYER_DISPLAY_MODE_AUTO_ASPECT_RATIO" - ], true)); - pushToArray(items, createPropertyControls(2, "av-timer", "Buffer Timeout", "tizen:buffer:timeout", - infoData != null && infoData.buffer != null ? infoData.buffer.timeout : null, "sec", [ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, "20 sec (Default)|num:20", 25, 30, 40 - ], false)); - pushToArray(items, createPropertyControls(3, "timelapse", "Buffer Size (Init)", "tizen:buffer:size:init", - infoData != null && infoData.buffer != null && infoData.buffer.size != null ? infoData.buffer.size.init : null, "sec", null, false)); - pushToArray(items, createPropertyControls(4, "timelapse", "Buffer Size (Resume)", "tizen:buffer:size:resume", - infoData != null && infoData.buffer != null && infoData.buffer.size != null ? infoData.buffer.size.resume : null, "sec", null, false)); - pushToArray(items, createTrackControl(5, "audiotrack", "Audio Track", "tizen:track:audio", - infoData != null && infoData.stream != null ? infoData.stream.audio : null, - infoData != null && infoData.tracks != null ? infoData.tracks.audio : null)); - pushToArray(items, createTrackControl(6, "subtitles", "Text Track", "tizen:track:text", - infoData != null && infoData.stream != null ? infoData.stream.text : null, - infoData != null && infoData.tracks != null ? infoData.tracks.text : null)); - return items; - }; - var createInfoItems = function(infoData) { - var infoKeys = "-"; - var infoValues = "-"; - if (infoData != null) { - infoKeys = "Version:{br}State:{br}{br}"; - infoValues = getValueLabel(infoData.version) + "{br}" + - getValueLabel(infoData.state) + "{br}{br}"; - if (infoData.stream != null) { - if (infoData.stream.video != null && infoData.stream.video.info != null) { - for (var key in infoData.stream.video.info) { - infoKeys += "Video [" + key + "]:{br}"; - infoValues += getValueLabel(infoData.stream.video.info[key]) + "{br}"; - } - infoKeys += "{br}"; - infoValues += "{br}"; - } - if (infoData.stream.audio != null && infoData.stream.audio.info != null) { - for (var key in infoData.stream.audio.info) { - infoKeys += "Audio [" + key + "]:{br}"; - infoValues += getValueLabel(infoData.stream.audio.info[key]) + "{br}"; - } - infoKeys += "{br}"; - infoValues += "{br}"; - } - if (infoData.stream.text != null && infoData.stream.text.info != null) { - for (var key in infoData.stream.text.info) { - infoKeys += "Text [" + key + "]:{br}"; - infoValues += getValueLabel(infoData.stream.text.info[key]) + "{br}"; - } - } - } - } - return [{ - type: "space", - layout: "8,0,3,8", - offset: "0.25,0,0,0", - truncation: "text", - text: infoKeys - }, { - type: "space", - layout: "11,0,5,8", - offset: "0.25,0,-0.25,0", - truncation: "text", - text: "{col:msx-white}" + infoValues, - live: { - type: "airtime", - duration: 2000, - over: { - action: "reload:content" - } - } - }]; - }; - var createContentItems = function(infoData) { - var items = []; - pushToArray(items, createControlItems(infoData)); - pushToArray(items, createInfoItems(infoData)); - return items; - }; - var createContent = function(infoData) { - return { - cache: false, - compress: true, - type: "pages", - headline: "Tizen Player", - extension: "{ico:msx-white:timer} " + TVXDateTools.getTimestamp(), - pages: [{ - items: createContentItems(infoData) - }] - }; - }; - var createWarningContent = function(playerInfo) { - return { - type: "pages", - headline: "Tizen Player", - pages: [{ - items: [{ - type: "default", - layout: "0,0,12,6", - color: "msx-glass", - headline: "{ico:msx-yellow:warning} Player Not Available", - text: "Tizen player is required for this plugin. Current player is: {txt:msx-white:" + playerInfo + "}." - }] - }] - }; - }; - var createDummyData = function() { - return { - version: "1.0", - state: "PLAYING", - display: { - area: "0,0,1,1", - mode: "PLAYER_DISPLAY_MODE_LETTER_BOX" - }, - buffer: { - timeout: 20, - size: { - init: 10, - resume: 10 - } - }, - stream: { - video: { - index: 0, - info: { - fourCC: "h264", - Width: 1280, - Height: 720, - Bit_rate: 128000 - } - } - } - }; - }; - this.handleRequest = function(playerInfo, dataId, callback) { - if (dataId == "init") { - if (TVXTools.isFullStr(playerInfo) && (playerInfo == "tizen" || playerInfo.indexOf("tizen/") == 0)) { - TVXInteractionPlugin.requestPlayerResponse("tizen:info", function(data) { - callback(createContent(data.response != null && data.response.tizen != null ? data.response.tizen.info : null)); - }); - } else { - callback(createWarningContent(playerInfo)); - } - return true; - } else if (dataId == "dummy") { - callback(createContent(createDummyData())); - return true; - } - return false; - }; -} -/******************************************************************************/ - -/******************************************************************************/ -//TizenHandler -/******************************************************************************/ -function TizenHandler() { - var playerInfo = null; - var readyService = new TVXBusyService(); - var player = new TizenPlayer(); - - this.ready = function() { - readyService.start(); - TVXInteractionPlugin.requestData("info:base", function(data) { - playerInfo = TVXTools.strFullCheck(data.info != null ? data.info.player : null, "unknown"); - readyService.stop(); - }); - }; - this.handleRequest = function(dataId, data, callback) { - readyService.onReady(function() { - if (!player.handleRequest(playerInfo, dataId, callback)) { - callback(); - } - }); - }; -} -/******************************************************************************/ - -/******************************************************************************/ -//Setup -/******************************************************************************/ -window.onload = function() { - TVXInteractionPlugin.setupHandler(new TizenHandler()); - TVXInteractionPlugin.init(); -}; -/******************************************************************************/ \ No newline at end of file diff --git a/server/web/msx/route.go b/server/web/msx/route.go index 7414da6..97259e0 100644 --- a/server/web/msx/route.go +++ b/server/web/msx/route.go @@ -8,12 +8,12 @@ func SetupRoute(route *gin.RouterGroup) { route.GET("/msx/playlist", msxPlaylist) route.GET("/msx/playlist/*fname", msxPlaylist) - route.GET("/msx/tizen.html", func(c *gin.Context) { - c.Data(200, "text/html; charset=utf-8", Msxtizenhtml) + route.GET("/msx/html5x.html", func(c *gin.Context) { + c.Data(200, "text/html; charset=utf-8", Msxhtml5xhtml) }) - route.GET("/msx/tizen.js", func(c *gin.Context) { - c.Data(200, "text/javascript; charset=utf-8", Msxtizenjs) + route.GET("/msx/tizen.html", func(c *gin.Context) { + c.Data(200, "text/html; charset=utf-8", Msxtizenhtml) }) route.GET("/msx/tvx-plugin.min.js", func(c *gin.Context) { diff --git a/server/web/server.go b/server/web/server.go index 76bee9c..e1c9ef4 100644 --- a/server/web/server.go +++ b/server/web/server.go @@ -3,11 +3,12 @@ package web import ( "net" - "github.com/gin-contrib/cors" "github.com/gin-contrib/location" "github.com/gin-gonic/gin" + "server/dlna" "server/settings" + "server/web/cors" "server/web/msx" "server/log" @@ -39,7 +40,9 @@ func Start(port string) { corsCfg := cors.DefaultConfig() corsCfg.AllowAllOrigins = true - corsCfg.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "X-Requested-With", "Accept", "Authorization"} + corsCfg.AllowHeaders = []string{"*"} + corsCfg.AllowMethods = []string{"*"} + corsCfg.AllowPrivateNetwork = true route := gin.New() route.Use(log.WebLogger(), blocker.Blocker(), gin.Recovery(), cors.New(corsCfg), location.Default()) diff --git a/web/src/components/About/index.jsx b/web/src/components/About/index.jsx index 67694a8..180cad2 100644 --- a/web/src/components/About/index.jsx +++ b/web/src/components/About/index.jsx @@ -64,6 +64,7 @@ export default function AboutDialog() { +