Custom Signalling in a Nutshell

If you are interested in integrating your own (or a third-party) signalling solution we provide some excellent resources to guide you. All of our IceLink example applications provide a working implementation of custom (manual) signalling. They use the WebSync signalling client (because that is our signalling product), but they do so to demonstrate how to provide signalling for IceLink with a client agnostic approach. Additionally, we provide a more in depth discussion of custom signalling in our IceLink 3 Advanced Guide article entitled Using Manual Signalling.

In general the signalling process is as follows for all versions of IceLink: send/receive offer, answer, and candidates. The following pseudocode snippet demonstrates the basics.

private void Initialize()
{
    Signalling.OnReceiveMessage = (peerId, tag, json) =>
    {
        var connection = GetConnection(peerId);
        if (message.Type == "candidate")
        {
            var candidate = Candidate.FromJson(json);
            connection.AddRemoteCandidate(candidate);
        }
        else if (message.Type == "offer")
        {
            var offer = SessionDescription.FromJson(json);
            connection.SetRemoteDescription(offer).Then((remoteDescription) =>
            {
                return connection.CreateAnswer();
            }).Then((answer) =>
            {
                return connection.SetLocalDescription(answer);
            }).Then((localDescription) =>
            {
                Signalling.SendMessage(peerId, "answer", localDescription.ToJson());
            });
        }
        else if (message.Type == "answer")
        {
            var answer = SessionDescription.FromJson(json);
            connection.SetRemoteDescription(answer);
        }
    };
}    
    
private void Offer(string peerId)
{
    var connection = GetConnection(peerId);
    connection.CreateOffer().Then((offer) =>
    {
        return connection.SetLocalDescription(offer);
    }).Then((localDescription) =>
    {
        Signalling.SendMessage(peerId, "offer", localDescription.ToJson());
    });
}

private Connection GetConnection(string peerId)
{
    if (Connections.ContainsKey(peerId))
    {
      return Connections[peerId];
    }
    var connection = new Connection(new Stream[] { ... });
    ...
    connection.OnLocalCandidate += (c, candidate) =>
    {
        Signalling.SendMessage(peerId, "candidate", candidate.ToJson());
    };
    Connections[peerId] = connection;
    return connection;
}

Lastly, please note that supporting custom, or third-party, signalling solutions falls outside the scope of Product Support. Signalling is an advanced concept, and while you are welcome to provide your own solution, we will only support our own signalling product WebSync. We do not support custom, or third-party, signalling solutions.