-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: CI | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
release: | ||
if: "!contains(github.event.head_commit.message, 'skip ci')" | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Semantic Release | ||
id: semantic | ||
uses: cycjimmy/semantic-release-action@v2.1.3 | ||
with: | ||
extra_plugins: | | ||
@semantic-release/changelog | ||
@semantic-release/git | ||
@semantic-release/npm | ||
branch: master | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
- name: Create UPM branch | ||
run: | | ||
git branch -d upm &> /dev/null || echo upm branch not found | ||
git subtree split -P "$PKG_ROOT" -b upm | ||
git checkout upm | ||
if [[ -d "Samples" ]]; then | ||
git mv Samples Samples~ | ||
rm -f Samples.meta | ||
git config --global user.name 'github-bot' | ||
git config --global user.email 'github-bot@users.noreply.github.com' | ||
git commit -am "fix: Samples => Samples~" | ||
fi | ||
git push -f -u origin upm | ||
env: | ||
PKG_ROOT: "Assets/Adrenak.AirPeer" | ||
|
||
- name: Create UPM git tag | ||
if: steps.semantic.outputs.new_release_published == 'true' | ||
run: | | ||
git tag $TAG upm | ||
git push origin --tags | ||
env: | ||
TAG: upm/v${{ steps.semantic.outputs.new_release_version }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"tagFormat": "v${version}", | ||
"plugins": [ | ||
["@semantic-release/commit-analyzer", { "preset": "angular" }], | ||
"@semantic-release/release-notes-generator", | ||
["@semantic-release/changelog", { | ||
"preset": "angular", | ||
"changelogFile":"Assets/Adrenak.AirPeer/CHANGELOG.md" | ||
}], | ||
["@semantic-release/npm", { | ||
"npmPublish": true, | ||
"pkgRoot":"Assets/Adrenak.AirPeer/" | ||
}], | ||
["@semantic-release/git", { | ||
"assets": ["Assets/Adrenak.AirPeer/CHANGELOG.md", "Assets/Adrenak.AirPeer/package.json"], | ||
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" | ||
}], | ||
"@semantic-release/github" | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Vatsal Ambastha | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# AirPeer | ||
A WebRTC based networking plugin for Unity3D. | ||
|
||
## Intro | ||
AirPeer allows Unity applications to communicate in a peer to peer manner using [WebRTC technology](https://webrtc.org/). | ||
|
||
Built on top of [Christoph Kutza's WebRTC project](https://www.because-why-not.com/webrtc/) with added features such as | ||
- Differentiating peers into server and clients | ||
- For client to client communication (via server) | ||
- Event based API | ||
- Message (de)serialization features | ||
|
||
## Signalling Server | ||
A directory called `server` in the repository root contains a node implementation for a signalling server. This can be run using NPM. Find the README inside the folder. | ||
|
||
## ParellSync | ||
Includes [ParellSync](https://github.com/VeriorPies/ParrelSync) to help test within the editor. | ||
|
||
## Contact | ||
[@github](https://www.github.com/adrenak) | ||
[@www](http://www.vatsalambastha.com) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
using Byn.Net; | ||
|
||
using System; | ||
using System.Linq; | ||
|
||
using UnityEngine; | ||
|
||
namespace Adrenak.AirPeer { | ||
/// <summary> | ||
/// Provides access to the WebRTC Network Plugin | ||
/// </summary> | ||
public class APNetwork : MonoBehaviour { | ||
/// <summary> | ||
/// Fired when the server successfully starts | ||
/// </summary> | ||
public event Action<NetworkEvent> OnServerStartSuccess; | ||
|
||
/// <summary> | ||
/// Fired when the server fails to start along with the exception | ||
/// </summary> | ||
public event Action<NetworkEvent> OnServerStartFailure; | ||
|
||
/// <summary> | ||
/// Fired when the server stops | ||
/// </summary> | ||
public event Action<NetworkEvent> OnServerStopped; | ||
|
||
/// <summary> | ||
/// Fired when a new connection is formed. Called on both the server and client | ||
/// </summary> | ||
public event Action<NetworkEvent> OnNewConnection; | ||
|
||
/// <summary> | ||
/// Fired when a connection attempt failed. | ||
/// </summary> | ||
public event Action<NetworkEvent> OnConnectionFailed; | ||
|
||
/// <summary> | ||
/// Fired when a connection is closed. Called on both the server and client | ||
/// </summary> | ||
public event Action<NetworkEvent> OnDisconnection; | ||
|
||
/// <summary> | ||
/// Fired when a message is receipted | ||
/// </summary> | ||
public event Action<NetworkEvent, bool> OnMessageReceived; | ||
|
||
IBasicNetwork network; | ||
|
||
APNetwork() { } | ||
|
||
/// <summary> | ||
/// Creates a new APNetwork instance | ||
/// </summary> | ||
/// <param name="signalingServer">The URL of the signaling server</param> | ||
/// <param name="iceServers">List of ICE server URLs</param> | ||
public static APNetwork New(string signalingServer, string[] iceServers) { | ||
var go = new GameObject("Peer Network [" + signalingServer + "]"); | ||
DontDestroyOnLoad(go); | ||
var instance = go.AddComponent<APNetwork>(); | ||
|
||
instance.network = WebRtcNetworkFactory.Instance.CreateDefault( | ||
signalingServer, | ||
iceServers.Select(x => new IceServer(x)).ToList().ToArray() | ||
); | ||
|
||
if (instance.network == null) { | ||
Destroy(go); | ||
return null; | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
/// <summary> | ||
/// Starts a server for the given address | ||
/// </summary> | ||
/// <param name="address">Address at which the server will start</param> | ||
public void StartServer(string address) => network.StartServer(address); | ||
|
||
/// <summary> | ||
/// Stops the server (if it's running) | ||
/// </summary> | ||
public void StopServer() => network.StopServer(); | ||
|
||
/// <summary> | ||
/// Connects to a server using the address | ||
/// </summary> | ||
/// <param name="address">The address at which the server is running</param> | ||
public void Connect(string address) => network.Connect(address); | ||
|
||
/// <summary> | ||
/// Disconnects using a ConnectionId | ||
/// </summary> | ||
/// <param name="id">The Id from which to disconnect</param> | ||
public void Disconnect(ConnectionId id) => network.Disconnect(id); | ||
|
||
/// <summary> | ||
/// Sends data over a connection | ||
/// </summary> | ||
/// <param name="id">The Id of the connection over which data is send</param> | ||
/// <param name="data">The data to be sent</param> | ||
/// <param name="offset">Offset from the byte array data</param> | ||
/// <param name="length">Length of the data starting from offset in data</param> | ||
/// <param name="reliable">Whether data is sent UDP or TCP style</param> | ||
public void SendData(ConnectionId id, byte[] data, int offset, int length, bool reliable) => | ||
network.SendData(id, data, offset, length, reliable); | ||
|
||
void Update() { | ||
if (network != null) { | ||
network.Update(); | ||
network.Flush(); | ||
|
||
// Dequeue while we have something | ||
do { | ||
network.Dequeue(out NetworkEvent e); | ||
if(e.Type != NetEventType.Invalid) | ||
ProcessNetworkEvent(e); | ||
} while (network.Peek(out NetworkEvent e2)); | ||
} | ||
} | ||
|
||
void ProcessNetworkEvent(NetworkEvent e) { | ||
switch (e.Type) { | ||
case NetEventType.ServerInitialized: | ||
OnServerStartSuccess?.Invoke(e); | ||
break; | ||
|
||
case NetEventType.ServerInitFailed: | ||
OnServerStartFailure?.Invoke(e); | ||
break; | ||
|
||
// Received after network.StopServer | ||
case NetEventType.ServerClosed: | ||
OnServerStopped?.Invoke(e); | ||
break; | ||
|
||
|
||
case NetEventType.NewConnection: | ||
OnNewConnection?.Invoke(e); | ||
break; | ||
|
||
case NetEventType.ConnectionFailed: | ||
OnConnectionFailed?.Invoke(e); | ||
break; | ||
|
||
case NetEventType.Disconnected: | ||
OnDisconnection?.Invoke(e); | ||
break; | ||
|
||
|
||
case NetEventType.ReliableMessageReceived: | ||
OnMessageReceived?.Invoke(e, true); | ||
break; | ||
|
||
case NetEventType.UnreliableMessageReceived: | ||
OnMessageReceived?.Invoke(e, false); | ||
break; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.