yjz-web-sdk 1.0.10 → 1.0.11-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/RemotePlayer/index.vue.d.ts +1 -73
- package/lib/composables/useCursorStyle.d.ts +1 -1
- package/lib/composables/useKeyboardControl.d.ts +1 -1
- package/lib/composables/useMouseTouchControl.d.ts +4 -4
- package/lib/composables/useRemoteVideo.d.ts +8 -25
- package/lib/composables/useResizeObserver.d.ts +1 -1
- package/lib/core/data/WebRtcError.d.ts +1 -2
- package/lib/core/data/WebrtcDataType.d.ts +1 -11
- package/lib/core/groupctrl/SdkController.d.ts +2 -2
- package/lib/core/rtc/WebRTCClient.d.ts +2 -5
- package/lib/core/rtc/WebRTCConfig.d.ts +1 -1
- package/lib/core/rtc/WebRtcNegotiate.d.ts +2 -2
- package/lib/core/signal/SignalingClient.d.ts +1 -1
- package/lib/core/util/TurnTestUtil.d.ts +2 -2
- package/lib/yjz-web-sdk.js +496 -1236
- package/package.json +5 -16
- package/lib/components/RemotePlayer/type.d.ts +0 -9
- package/lib/core/util/MapCache.d.ts +0 -20
- package/lib/render/Canvas2DRenderer.d.ts +0 -10
- package/lib/render/WebGLRenderer.d.ts +0 -16
- package/lib/render/WebGPURenderer.d.ts +0 -18
- package/lib/types/index.d.ts +0 -13
- package/lib/util/WasmUtil.d.ts +0 -17
- package/lib/worker/worker.d.ts +0 -1
- package/src/assets/icon/circle.svg +0 -1
- package/src/assets/icon/triangle.svg +0 -1
- package/src/assets/wasm/h264-atomic.wasm +0 -0
- package/src/assets/wasm/h264-simd.wasm +0 -0
- package/src/components/RemotePlayer/index.vue +0 -170
- package/src/components/RemotePlayer/type.ts +0 -11
- package/src/composables/useCursorStyle.ts +0 -15
- package/src/composables/useKeyboardControl.ts +0 -32
- package/src/composables/useMouseTouchControl.ts +0 -158
- package/src/composables/useRemoteVideo.ts +0 -248
- package/src/composables/useResizeObserver.ts +0 -27
- package/src/core/WebRTCSdk.ts +0 -561
- package/src/core/data/MessageType.ts +0 -70
- package/src/core/data/TurnType.ts +0 -25
- package/src/core/data/WebRtcError.ts +0 -93
- package/src/core/data/WebrtcDataType.ts +0 -354
- package/src/core/groupctrl/GroupCtrlSocketManager.ts +0 -94
- package/src/core/groupctrl/SdkController.ts +0 -96
- package/src/core/rtc/WebRTCClient.ts +0 -862
- package/src/core/rtc/WebRTCConfig.ts +0 -86
- package/src/core/rtc/WebRtcNegotiate.ts +0 -164
- package/src/core/signal/SignalingClient.ts +0 -221
- package/src/core/util/FileTypeUtils.ts +0 -75
- package/src/core/util/KeyCodeUtil.ts +0 -162
- package/src/core/util/Logger.ts +0 -83
- package/src/core/util/MapCache.ts +0 -135
- package/src/core/util/ScreenControlUtil.ts +0 -174
- package/src/core/util/TurnTestUtil.ts +0 -123
- package/src/env.d.ts +0 -30
- package/src/index.ts +0 -61
- package/src/render/Canvas2DRenderer.ts +0 -38
- package/src/render/WebGLRenderer.ts +0 -150
- package/src/render/WebGPURenderer.ts +0 -194
- package/src/types/index.ts +0 -15
- package/src/types/webgpu.d.ts +0 -1158
- package/src/util/WasmUtil.ts +0 -291
- package/src/worker/worker.ts +0 -292
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
export class WebGLRenderer {
|
|
2
|
-
private canvas: HTMLCanvasElement | OffscreenCanvas | null = null;
|
|
3
|
-
private ctx: WebGLRenderingContext | WebGL2RenderingContext | null = null;
|
|
4
|
-
private program: WebGLProgram | null = null;
|
|
5
|
-
private texture: WebGLTexture | null = null;
|
|
6
|
-
private vertexBuffer: WebGLBuffer | null = null;
|
|
7
|
-
|
|
8
|
-
static vertexShaderSource = `
|
|
9
|
-
attribute vec2 xy;
|
|
10
|
-
varying highp vec2 uv;
|
|
11
|
-
void main(void) {
|
|
12
|
-
gl_Position = vec4(xy, 0.0, 1.0);
|
|
13
|
-
uv = vec2((1.0 + xy.x) / 2.0, (1.0 - xy.y) / 2.0);
|
|
14
|
-
}
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
|
-
static fragmentShaderSource = `
|
|
18
|
-
varying highp vec2 uv;
|
|
19
|
-
uniform sampler2D texture;
|
|
20
|
-
void main(void) {
|
|
21
|
-
gl_FragColor = texture2D(texture, uv);
|
|
22
|
-
}
|
|
23
|
-
`;
|
|
24
|
-
|
|
25
|
-
constructor(type: "webgl" | "webgl2", canvas: HTMLCanvasElement | OffscreenCanvas) {
|
|
26
|
-
this.canvas = canvas;
|
|
27
|
-
const gl = canvas.getContext(type) as
|
|
28
|
-
| WebGLRenderingContext
|
|
29
|
-
| WebGL2RenderingContext
|
|
30
|
-
| null;
|
|
31
|
-
if (!gl) throw new Error("Failed to get WebGL context");
|
|
32
|
-
this.ctx = gl;
|
|
33
|
-
|
|
34
|
-
// ===== 编译 & 链接程序 =====
|
|
35
|
-
const program = this.createProgram(gl);
|
|
36
|
-
gl.useProgram(program);
|
|
37
|
-
this.program = program;
|
|
38
|
-
|
|
39
|
-
// ===== 顶点缓冲 =====
|
|
40
|
-
const vertexBuffer = gl.createBuffer()!;
|
|
41
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
|
42
|
-
gl.bufferData(
|
|
43
|
-
gl.ARRAY_BUFFER,
|
|
44
|
-
new Float32Array([
|
|
45
|
-
-1.0, -1.0,
|
|
46
|
-
-1.0, +1.0,
|
|
47
|
-
+1.0, +1.0,
|
|
48
|
-
+1.0, -1.0
|
|
49
|
-
]),
|
|
50
|
-
gl.STATIC_DRAW
|
|
51
|
-
);
|
|
52
|
-
const xyLocation = gl.getAttribLocation(program, "xy");
|
|
53
|
-
gl.vertexAttribPointer(xyLocation, 2, gl.FLOAT, false, 0, 0);
|
|
54
|
-
gl.enableVertexAttribArray(xyLocation);
|
|
55
|
-
this.vertexBuffer = vertexBuffer;
|
|
56
|
-
|
|
57
|
-
// ===== 创建纹理 =====
|
|
58
|
-
const texture = gl.createTexture()!;
|
|
59
|
-
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
60
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
61
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
62
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
63
|
-
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
64
|
-
this.texture = texture;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private createProgram(gl: WebGLRenderingContext | WebGL2RenderingContext): WebGLProgram {
|
|
68
|
-
const vertexShader = gl.createShader(gl.VERTEX_SHADER)!;
|
|
69
|
-
gl.shaderSource(vertexShader, WebGLRenderer.vertexShaderSource);
|
|
70
|
-
gl.compileShader(vertexShader);
|
|
71
|
-
if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
|
|
72
|
-
throw new Error(gl.getShaderInfoLog(vertexShader) || "Vertex shader error");
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER)!;
|
|
76
|
-
gl.shaderSource(fragmentShader, WebGLRenderer.fragmentShaderSource);
|
|
77
|
-
gl.compileShader(fragmentShader);
|
|
78
|
-
if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
|
|
79
|
-
throw new Error(gl.getShaderInfoLog(fragmentShader) || "Fragment shader error");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const program = gl.createProgram()!;
|
|
83
|
-
gl.attachShader(program, vertexShader);
|
|
84
|
-
gl.attachShader(program, fragmentShader);
|
|
85
|
-
gl.linkProgram(program);
|
|
86
|
-
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
87
|
-
throw new Error(gl.getProgramInfoLog(program) || "Program link error");
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// 删除 shader,释放显存
|
|
91
|
-
gl.deleteShader(vertexShader);
|
|
92
|
-
gl.deleteShader(fragmentShader);
|
|
93
|
-
|
|
94
|
-
return program;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
render(frame: VideoFrame) {
|
|
98
|
-
if (!this.ctx || !this.canvas || !this.texture) return;
|
|
99
|
-
const gl = this.ctx;
|
|
100
|
-
|
|
101
|
-
// 调整 canvas 尺寸
|
|
102
|
-
this.canvas.width = frame.displayWidth;
|
|
103
|
-
this.canvas.height = frame.displayHeight;
|
|
104
|
-
|
|
105
|
-
// 上传纹理
|
|
106
|
-
gl.bindTexture(gl.TEXTURE_2D, this.texture);
|
|
107
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, frame);
|
|
108
|
-
frame.close();
|
|
109
|
-
|
|
110
|
-
// viewport
|
|
111
|
-
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
|
|
112
|
-
|
|
113
|
-
// 清屏并绘制
|
|
114
|
-
gl.clearColor(0, 0, 0, 1);
|
|
115
|
-
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
116
|
-
gl.drawArrays(gl.TRIANGLE_FAN, 0, 4);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** 清空画布,但不销毁资源 */
|
|
120
|
-
clear() {
|
|
121
|
-
if (!this.ctx) return;
|
|
122
|
-
const gl = this.ctx;
|
|
123
|
-
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
|
|
124
|
-
gl.clearColor(0, 0, 0, 1);
|
|
125
|
-
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** 销毁 WebGLRenderer,释放所有资源 */
|
|
129
|
-
destroy() {
|
|
130
|
-
if (!this.ctx) return;
|
|
131
|
-
const gl = this.ctx;
|
|
132
|
-
|
|
133
|
-
if (this.texture) {
|
|
134
|
-
gl.deleteTexture(this.texture);
|
|
135
|
-
this.texture = null;
|
|
136
|
-
}
|
|
137
|
-
if (this.vertexBuffer) {
|
|
138
|
-
gl.deleteBuffer(this.vertexBuffer);
|
|
139
|
-
this.vertexBuffer = null;
|
|
140
|
-
}
|
|
141
|
-
if (this.program) {
|
|
142
|
-
gl.deleteProgram(this.program);
|
|
143
|
-
this.program = null;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// 清空 canvas 引用
|
|
147
|
-
this.canvas = null;
|
|
148
|
-
this.ctx = null;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
export class WebGPURenderer {
|
|
2
|
-
private canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
3
|
-
private ctx: GPUCanvasContext | null = null;
|
|
4
|
-
|
|
5
|
-
private started: Promise<void>;
|
|
6
|
-
|
|
7
|
-
private format: GPUTextureFormat | null = null;
|
|
8
|
-
private device: GPUDevice | null = null;
|
|
9
|
-
private pipeline: GPURenderPipeline | null = null;
|
|
10
|
-
private sampler!: GPUSampler;
|
|
11
|
-
|
|
12
|
-
// ------------------------------
|
|
13
|
-
// WGSL Shader
|
|
14
|
-
// ------------------------------
|
|
15
|
-
static vertexShaderSource = `
|
|
16
|
-
struct VertexOutput {
|
|
17
|
-
@builtin(position) Position: vec4<f32>,
|
|
18
|
-
@location(0) uv: vec2<f32>,
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@vertex
|
|
22
|
-
fn vert_main(@builtin(vertex_index) VertexIndex: u32) -> VertexOutput {
|
|
23
|
-
var pos = array<vec2<f32>, 6>(
|
|
24
|
-
vec2<f32>( 1.0, 1.0),
|
|
25
|
-
vec2<f32>( 1.0, -1.0),
|
|
26
|
-
vec2<f32>(-1.0, -1.0),
|
|
27
|
-
vec2<f32>( 1.0, 1.0),
|
|
28
|
-
vec2<f32>(-1.0, -1.0),
|
|
29
|
-
vec2<f32>(-1.0, 1.0)
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
var uv = array<vec2<f32>, 6>(
|
|
33
|
-
vec2<f32>(1.0, 0.0),
|
|
34
|
-
vec2<f32>(1.0, 1.0),
|
|
35
|
-
vec2<f32>(0.0, 1.0),
|
|
36
|
-
vec2<f32>(1.0, 0.0),
|
|
37
|
-
vec2<f32>(0.0, 1.0),
|
|
38
|
-
vec2<f32>(0.0, 0.0)
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
var output : VertexOutput;
|
|
42
|
-
output.Position = vec4<f32>(pos[VertexIndex], 0.0, 1.0);
|
|
43
|
-
output.uv = uv[VertexIndex];
|
|
44
|
-
return output;
|
|
45
|
-
}
|
|
46
|
-
`;
|
|
47
|
-
|
|
48
|
-
static fragmentShaderSource = `
|
|
49
|
-
@group(0) @binding(1) var mySampler: sampler;
|
|
50
|
-
@group(0) @binding(2) var myTexture: texture_external;
|
|
51
|
-
|
|
52
|
-
@fragment
|
|
53
|
-
fn frag_main(@location(0) uv : vec2<f32>) -> @location(0) vec4<f32> {
|
|
54
|
-
return textureSampleBaseClampToEdge(myTexture, mySampler, uv);
|
|
55
|
-
}
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
constructor(canvas: HTMLCanvasElement | OffscreenCanvas) {
|
|
59
|
-
this.canvas = canvas;
|
|
60
|
-
this.started = this.start();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// -------------------------------------
|
|
64
|
-
// WebGPU 初始化
|
|
65
|
-
// -------------------------------------
|
|
66
|
-
async start() {
|
|
67
|
-
const adapter: GPUAdapter | null = await navigator.gpu.requestAdapter();
|
|
68
|
-
if (!adapter) throw new Error("WebGPU adapter not found");
|
|
69
|
-
|
|
70
|
-
this.device = await adapter.requestDevice();
|
|
71
|
-
this.format = navigator.gpu.getPreferredCanvasFormat();
|
|
72
|
-
|
|
73
|
-
this.ctx = this.canvas.getContext("webgpu") as GPUCanvasContext;
|
|
74
|
-
this.ctx.configure({
|
|
75
|
-
device: this.device,
|
|
76
|
-
format: this.format,
|
|
77
|
-
alphaMode: "opaque",
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
this.pipeline = this.device.createRenderPipeline({
|
|
81
|
-
layout: "auto",
|
|
82
|
-
vertex: {
|
|
83
|
-
module: this.device.createShaderModule({
|
|
84
|
-
code: WebGPURenderer.vertexShaderSource,
|
|
85
|
-
}),
|
|
86
|
-
entryPoint: "vert_main",
|
|
87
|
-
buffers: [] // 必须添加
|
|
88
|
-
},
|
|
89
|
-
fragment: {
|
|
90
|
-
module: this.device.createShaderModule({
|
|
91
|
-
code: WebGPURenderer.fragmentShaderSource,
|
|
92
|
-
}),
|
|
93
|
-
entryPoint: "frag_main",
|
|
94
|
-
targets: [{ format: this.format }],
|
|
95
|
-
},
|
|
96
|
-
primitive: { topology: "triangle-list" },
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
this.sampler = this.device.createSampler({});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// frame 类型兼容:HTMLVideoElement 或 VideoFrame 或 CanvasImageSource
|
|
103
|
-
async render(frame: VideoFrame | HTMLVideoElement | HTMLCanvasElement | HTMLImageElement) {
|
|
104
|
-
await this.started;
|
|
105
|
-
|
|
106
|
-
if (!this.device || !this.ctx || !this.pipeline)
|
|
107
|
-
throw new Error("WebGPURenderer not initialized");
|
|
108
|
-
|
|
109
|
-
// 如果是 VideoFrame 才有 displayWidth/Height
|
|
110
|
-
const width =
|
|
111
|
-
(frame as VideoFrame).displayWidth ??
|
|
112
|
-
(frame as HTMLVideoElement).videoWidth ??
|
|
113
|
-
(frame as HTMLImageElement).naturalWidth ??
|
|
114
|
-
this.canvas.width;
|
|
115
|
-
|
|
116
|
-
const height =
|
|
117
|
-
(frame as VideoFrame).displayHeight ??
|
|
118
|
-
(frame as HTMLVideoElement).videoHeight ??
|
|
119
|
-
(frame as HTMLImageElement).naturalHeight ??
|
|
120
|
-
this.canvas.height;
|
|
121
|
-
|
|
122
|
-
this.canvas.width = width;
|
|
123
|
-
this.canvas.height = height;
|
|
124
|
-
|
|
125
|
-
const externalTexture = this.device.importExternalTexture({
|
|
126
|
-
source: frame as any, // WebGPU spec 接受 CanvasImageSource/VideoFrame
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
const bindGroup = this.device.createBindGroup({
|
|
130
|
-
layout: this.pipeline.getBindGroupLayout(0),
|
|
131
|
-
entries: [
|
|
132
|
-
{ binding: 1, resource: this.sampler },
|
|
133
|
-
{ binding: 2, resource: externalTexture },
|
|
134
|
-
],
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
const encoder = this.device.createCommandEncoder();
|
|
138
|
-
const view = this.ctx.getCurrentTexture().createView();
|
|
139
|
-
|
|
140
|
-
const pass = encoder.beginRenderPass({
|
|
141
|
-
colorAttachments: [
|
|
142
|
-
{
|
|
143
|
-
view,
|
|
144
|
-
clearValue: [1, 0, 0, 1],
|
|
145
|
-
loadOp: "clear",
|
|
146
|
-
storeOp: "store",
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
pass.setPipeline(this.pipeline);
|
|
152
|
-
pass.setBindGroup(0, bindGroup);
|
|
153
|
-
pass.draw(6);
|
|
154
|
-
pass.end();
|
|
155
|
-
|
|
156
|
-
this.device.queue.submit([encoder.finish()]);
|
|
157
|
-
|
|
158
|
-
// VideoFrame 需要 close(),HTMLVideoElement 不需要
|
|
159
|
-
if (frame instanceof VideoFrame) frame.close();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/** 清空画布 */
|
|
163
|
-
async clear() {
|
|
164
|
-
await this.started;
|
|
165
|
-
if (!this.device || !this.ctx || !this.pipeline) return;
|
|
166
|
-
|
|
167
|
-
const encoder = this.device.createCommandEncoder();
|
|
168
|
-
const view = this.ctx.getCurrentTexture().createView();
|
|
169
|
-
|
|
170
|
-
const pass = encoder.beginRenderPass({
|
|
171
|
-
colorAttachments: [
|
|
172
|
-
{
|
|
173
|
-
view,
|
|
174
|
-
clearValue: [0, 0, 0, 1], // 清屏黑色
|
|
175
|
-
loadOp: "clear",
|
|
176
|
-
storeOp: "store",
|
|
177
|
-
},
|
|
178
|
-
],
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
pass.end();
|
|
182
|
-
this.device.queue.submit([encoder.finish()]);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/** 销毁 WebGPURenderer,释放所有 GPU 资源 */
|
|
186
|
-
destroy() {
|
|
187
|
-
// WebGPU 没有显式 destroy pipeline/texture 的统一接口
|
|
188
|
-
// 手动释放引用,便于 GC 回收
|
|
189
|
-
this.pipeline = null;
|
|
190
|
-
this.ctx = null;
|
|
191
|
-
this.device = null;
|
|
192
|
-
this.started = Promise.resolve();
|
|
193
|
-
}
|
|
194
|
-
}
|
package/src/types/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export interface RenderingCapabilities {
|
|
2
|
-
webgpu: boolean
|
|
3
|
-
webgl2: boolean
|
|
4
|
-
webgl1: boolean
|
|
5
|
-
canvas2d: boolean
|
|
6
|
-
best: RendererType
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type RendererType = 'webgpu' | 'webgl2' | 'webgl1' | 'canvas2d' | 'none'
|
|
10
|
-
|
|
11
|
-
export interface DecoderSupportResult {
|
|
12
|
-
supported: boolean; // 是否可解码
|
|
13
|
-
hardware: boolean; // 是否是硬件解码
|
|
14
|
-
software: boolean; // 是否是软件解码
|
|
15
|
-
}
|