Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PeerConnectionのCreate/Closeでエラーが発生しても処理を継続するように変更 #9

Merged
merged 17 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions Runtime/NativePeerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private static void LogIceServers(RTCConfiguration pcConfig)
{
if (pcConfig.iceServers is null)
{
// Not covered by testing due to defensive implementation
Logger.LogDebug("Ice server: None");
}
else
Expand Down Expand Up @@ -371,10 +372,22 @@ private void CreatePc(string id, bool isOffer)
}
};

pcCreateHooks.ForEach(hook => hook.Invoke(id, isOffer, pc));
pcCreateHooks.ForEach(hook => HandleHook(nameof(CreatePc),() => hook.Invoke(id, isOffer, pc)));
sus-taguchi-t marked this conversation as resolved.
Show resolved Hide resolved
pcDict.Add(id, pc);
}

private static void HandleHook(string name, Action hook)
{
try
{
hook.Invoke();
}
catch (Exception e)
{
Logger.LogError($"Error has occured at {name}", e);
}
}

private async UniTask SendSdpByCompleteOrTimeoutAsync(string to, RTCPeerConnection pc)
{
var isTimeout = false;
Expand Down Expand Up @@ -402,7 +415,7 @@ private void ClosePc(string from)
from,
pc =>
{
pcCloseHooks.ForEach(hook => hook.Invoke(from));
pcCloseHooks.ForEach(hook => HandleHook(nameof(ClosePc), () => hook.Invoke(from)));
pc.Close();
pcDict.Remove(from);
});
Expand Down
5 changes: 5 additions & 0 deletions Samples~/MVS/ClientControl/ClientControlScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SocketIOClient;
using VContainer;
using VContainer.Unity;
using Extreal.Integration.P2P.WebRTC;

namespace Extreal.Integration.P2P.WebRTC.MVS.ClientControl
{
Expand Down Expand Up @@ -33,9 +34,13 @@ protected override void Configure(IContainerBuilder builder)
builder.RegisterComponent(peerClient);

#if !UNITY_WEBGL || UNITY_EDITOR
new NativeFailureClient(peerClient as NativePeerClient);
sus-taguchi-t marked this conversation as resolved.
Show resolved Hide resolved
builder.RegisterComponent<DataChannelClient>(new NativeDataChannelClient(peerClient as NativePeerClient));
new NativeFailureClient(peerClient as NativePeerClient);
#else
new WebGLFailureClient();
builder.RegisterComponent<DataChannelClient>(new WebGLDataChannelClient());
new WebGLFailureClient();
#endif

builder.RegisterEntryPoint<ClientControlPresenter>();
Expand Down
16 changes: 16 additions & 0 deletions Samples~/MVS/ClientControl/NativeFailureClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#if !UNITY_WEBGL || UNITY_EDITOR
using System.Collections.Generic;
using Unity.WebRTC;

namespace Extreal.Integration.P2P.WebRTC.MVS.ClientControl
{
public class NativeFailureClient
{
public NativeFailureClient(NativePeerClient peerClient)
{
peerClient.AddPcCreateHook((id, isOffer, pc) => throw new System.Exception("PeerClient Create Error Test"));
peerClient.AddPcCloseHook(id => throw new System.Exception("PeerClient Close Error Test"));
}
}
}
#endif
3 changes: 3 additions & 0 deletions Samples~/MVS/ClientControl/NativeFailureClient.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Samples~/MVS/ClientControl/WebGLFailureClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#if UNITY_WEBGL && !UNITY_EDITOR
using Extreal.Integration.Web.Common;

namespace Extreal.Integration.P2P.WebRTC.MVS.ClientControl
{
public class WebGLFailureClient
{
public WebGLFailureClient() => WebGLHelper.CallAction("failure");
}
}
#endif
3 changes: 3 additions & 0 deletions Samples~/MVS/ClientControl/WebGLFailureClient.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions Samples~/MVS/WebGLScripts~/src/FailureClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { PeerClientProvider } from "@extreal-dev/extreal.integration.p2p.webrtc";

class FailureClient {
private readonly getPeerClient: PeerClientProvider;

constructor(getPeerClient: PeerClientProvider) {
this.getPeerClient = getPeerClient;
sus-taguchi-t marked this conversation as resolved.
Show resolved Hide resolved
this.getPeerClient().addPcCreateHook(this.createPc);
this.getPeerClient().addPcCloseHook(this.closePc);
}

private createPc = (id: string, isOffer: boolean, pc: RTCPeerConnection) => {
throw new Error("CreatePeerClient Error Test");
};

private closePc = (id: string) => {
throw new Error("ClosePeerClient Error Test");
};
}

export { FailureClient };
3 changes: 3 additions & 0 deletions Samples~/MVS/WebGLScripts~/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { addAction } from "@extreal-dev/extreal.integration.web.common";
import { PeerAdapter } from "@extreal-dev/extreal.integration.p2p.webrtc";
import { DataChannelClient } from "./DataChannelClient";
import { FailureClient } from "./FailureClient";


const peerAdapter = new PeerAdapter();
peerAdapter.adapt();

let dataChannelClient: DataChannelClient;
addAction("start", () => dataChannelClient = new DataChannelClient(peerAdapter.getPeerClient));
addAction("clear", () => dataChannelClient.clear);
addAction("failure", () => new FailureClient(peerAdapter.getPeerClient));
sus-taguchi-t marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 16 additions & 6 deletions WebScripts~/src/PeerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,18 @@ class PeerClient {
this.socket = null;
};

private handleHook = async (hook: Function, ...args: any[]) => {
try {
if (isAsync(hook)){
await hook(...args)
} else {
hook(...args)
}
} catch (e) {
console.error(e);
}
}

private createPcAsync = async (id: string, isOffer: boolean) => {
if (this.pcMap.has(id)) {
return;
Expand Down Expand Up @@ -288,11 +300,7 @@ class PeerClient {
};

for (const hook of this.pcCreateHooks) {
if (isAsync(hook)) {
await hook(id, isOffer, pc);
} else {
hook(id, isOffer, pc);
}
await this.handleHook(hook, id, isOffer, pc);
}
this.pcMap.set(id, pc);
};
Expand All @@ -315,7 +323,9 @@ class PeerClient {

private closePc = (from: string) => {
this.handlePc("closePc", from, (pc: RTCPeerConnection) => {
this.pcCloseHooks.forEach((hook) => hook(from));
this.pcCloseHooks.forEach((hook) => {
this.handleHook(hook, from);
});
pc.close();
this.pcMap.delete(from);
});
Expand Down
8 changes: 4 additions & 4 deletions WebScripts~/yarn.lock
sus-taguchi-t marked this conversation as resolved.
Show resolved Hide resolved
sus-taguchi-t marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@extreal-dev/extreal.integration.web.common@^0.0.9":
version "0.0.9"
resolved "https://registry.yarnpkg.com/@extreal-dev/extreal.integration.web.common/-/extreal.integration.web.common-0.0.9.tgz#10e5674e744e6d835bbc6f197fbf14790eae608e"
integrity sha512-HVtXEX7ukxv265SKcHfk1y1FefeWlQrotF7YnJn/gyPw9qp9hTjZ/qVXr0byk8hIC0pXrFYOux/sqgAbrAupiw==
"@extreal-dev/extreal.integration.web.common@^1.0.0":
version "1.0.0"
sus-taguchi-t marked this conversation as resolved.
Show resolved Hide resolved
resolved "https://registry.yarnpkg.com/@extreal-dev/extreal.integration.web.common/-/extreal.integration.web.common-1.0.0.tgz#3113ecaf48e44cf6712d18fc6b40991b4cd82d3a"
integrity sha512-aH5A5ClpaKVUFE1DbvYVy4L7J81wo+oQmBJJmc6geR5CQTa7942CUYW11jnPp5hCq1QXG+jz/yVpU26p00I+Qw==

"@jridgewell/gen-mapping@^0.3.0":
version "0.3.3"
Expand Down