Skip to content

Commit

Permalink
refactor hls supporting
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostya Bats committed Mar 23, 2024
1 parent 2ea160b commit 482d9fa
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 20 deletions.
22 changes: 11 additions & 11 deletions schemas/advanced.schema.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"$ref": "#/$defs/ICPC live advanced settings",
"$defs": {
"M2tsVideo": {
"HLSVideo": {
"type": "object",
"properties": {
"type": {
"const": "M2tsVideo",
"default": "M2tsVideo"
"const": "HLSVideo",
"default": "HLSVideo"
},
"url": {
"type": "string"
},
"jwtToken": {
"type": "string"
},
"isMedia": {
"type": "boolean"
}
Expand All @@ -20,21 +23,18 @@
"type",
"url"
],
"title": "M2tsVideo"
"title": "HLSVideo"
},
"HLSVideo": {
"M2tsVideo": {
"type": "object",
"properties": {
"type": {
"const": "HLSVideo",
"default": "HLSVideo"
"const": "M2tsVideo",
"default": "M2tsVideo"
},
"url": {
"type": "string"
},
"jwtToken": {
"type": "string"
},
"isMedia": {
"type": "boolean"
}
Expand All @@ -44,7 +44,7 @@
"type",
"url"
],
"title": "HLSVideo"
"title": "M2tsVideo"
},
"Object": {
"type": "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private fun MediaType.toClicsMedia() = when (this) {
is MediaType.TaskStatus -> null
is MediaType.Video -> Media("video", url)
is MediaType.M2tsVideo -> Media("video/m2ts", url)
is MediaType.HLSVideo -> Media("application/vnd.apple.mpegurl", url)
is MediaType.WebRTCGrabberConnection -> null
is MediaType.WebRTCProxyConnection -> null
}
Expand Down Expand Up @@ -487,4 +488,4 @@ object ClicsExporter {
))
}
}
}
}
32 changes: 32 additions & 0 deletions src/cds/core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,38 @@ public final class org/icpclive/cds/api/MediaType$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class org/icpclive/cds/api/MediaType$HLSVideo : org/icpclive/cds/api/MediaType {
public static final field Companion Lorg/icpclive/cds/api/MediaType$HLSVideo$Companion;
public fun <init> (Ljava/lang/String;Ljava/lang/String;Z)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Z
public final fun copy (Ljava/lang/String;Ljava/lang/String;Z)Lorg/icpclive/cds/api/MediaType$HLSVideo;
public static synthetic fun copy$default (Lorg/icpclive/cds/api/MediaType$HLSVideo;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Lorg/icpclive/cds/api/MediaType$HLSVideo;
public fun equals (Ljava/lang/Object;)Z
public final fun getJwtToken ()Ljava/lang/String;
public final fun getUrl ()Ljava/lang/String;
public fun hashCode ()I
public fun isMedia ()Z
public fun toString ()Ljava/lang/String;
}

public synthetic class org/icpclive/cds/api/MediaType$HLSVideo$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Lorg/icpclive/cds/api/MediaType$HLSVideo$$serializer;
public final fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public final fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lorg/icpclive/cds/api/MediaType$HLSVideo;
public final fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public final fun serialize (Lkotlinx/serialization/encoding/Encoder;Lorg/icpclive/cds/api/MediaType$HLSVideo;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class org/icpclive/cds/api/MediaType$HLSVideo$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class org/icpclive/cds/api/MediaType$M2tsVideo : org/icpclive/cds/api/MediaType {
public static final field Companion Lorg/icpclive/cds/api/MediaType$M2tsVideo$Companion;
public fun <init> (Ljava/lang/String;Z)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,3 @@ public data class ContestInfo(
val problems: Map<ProblemId, ProblemInfo> by lazy { problemList.associateBy { it.id } }
val scoreboardProblems: List<ProblemInfo> by lazy { problemList.sortedBy { it.ordinal }.filterNot { it.isHidden } }
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public sealed class MediaType {
@SerialName("M2tsVideo")
public data class M2tsVideo(val url: String, override val isMedia: Boolean = true) : MediaType()

@Serializable
@SerialName("HLSVideo")
public data class HLSVideo(val url: String, val jwtToken: String? = null, override val isMedia: Boolean = true) : MediaType()

/**
* WebRTC proxy connection
* @see <a href="https://github.com/kbats183/webrtc-proxy">https://github.com/kbats183/webrtc-proxy</a>
Expand Down Expand Up @@ -65,4 +69,4 @@ public sealed class MediaType {
is WebRTCGrabberConnection -> copy(isMedia = false)
else -> this
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ internal class ClicsModel(private val addTeamNames: Boolean) {
if (mime.startsWith("video/m2ts")) {
return MediaType.M2tsVideo(href)
}
if (mime.startsWith("application/vnd.apple.mpegurl")) {
return MediaType.HLSVideo(href)
}
if (mime.startsWith("video")) {
return MediaType.Video(href)
}
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/generated/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ export namespace MediaType {
jwtToken?: string | null;
isMedia?: boolean;
}

export interface M2tsVideo {
type: MediaType.Type.M2tsVideo;
url: string;
isMedia?: boolean;
}

export interface Object {
type: MediaType.Type.Object;
url: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const TeamM2tsVideoWrapper = ({ url, setIsLoaded }) => {
if (videoRef.current) {
videoRef.current.srcObject = null;
}
}
};
}, [url]);
return (<VideoWrapper
ref={videoRef}
Expand Down Expand Up @@ -235,10 +235,10 @@ function HlsPlayer({
}, [autoPlay, src, jwtToken]);

// If Media Source is supported, use HLS.js to play video
if (Hls.isSupported()) return <video ref={playerRef} autoPlay={autoPlay} controls={false} {...props} />;
if (Hls.isSupported()) return <VideoWrapper ref={playerRef} autoPlay={autoPlay} controls={false} {...props} />;

// Fallback to using a regular video player if HLS is supported by default in the user's browser
return <video ref={playerRef} src={src} autoPlay={autoPlay} controls={false} {...props} />;
return <VideoWrapper ref={playerRef} src={src} autoPlay={autoPlay} controls={false} {...props} />;
}

export const FullWidthWrapper = styled.div`
Expand Down Expand Up @@ -303,7 +303,6 @@ const teamViewComponentRender: {
autoPlay
loop
muted

/>
</FullWidthWrapper>;
},
Expand Down

0 comments on commit 482d9fa

Please sign in to comment.