public void Attach(FM.IceLink.Conference conference, string sessionId, Action<string> callback)
{
Conference = conference;
SessionId = sessionId;
if (UseWebSyncExtension)
{
// Manage the conference automatically using a WebSync
// channel. P2P links will be created automatically to
// peers that join the same channel.
WebSyncClient.JoinConference(new JoinConferenceArgs("/" + SessionId, conference)
{
OnFailure = (e) =>
{
callback(string.Format("Could not join conference {0}. {1}", e.ConferenceChannel, e.Exception.Message));
},
OnSuccess = (e) =>
{
callback(null);
}
});
}
else
{
// When the conference generates an offer/answer or candidate,
// we want to send it to the remote peer immediately.
Conference.OnLinkOfferAnswer += SendOfferAnswer;
Conference.OnLinkCandidate += SendCandidate;
// When we receive an offer/answer or candidate, we want to
// inform the conference immediately.
WebSyncClient.OnNotify += ReceiveOfferAnswerOrCandidate;
// Subscribe to a WebSync channel. When another client joins the same
// channel, create a P2P link. When a client leaves, destroy it.
WebSyncClient.Subscribe(new SubscribeArgs("/" + SessionId)
{
OnFailure = (e) =>
{
callback(string.Format("Could not attach signalling to conference {0}. {1}", SessionId, e.Exception.Message));
},
OnReceive = (e) => { },
OnSuccess = (e) =>
{
callback(null);
}
}
.SetOnClientSubscribe((e) =>
{
// Kick off a P2P link.
var peerId = e.SubscribedClient.ClientId.ToString();
var peerState = e.SubscribedClient.BoundRecords;
Conference.Link(peerId, peerState);
})
.SetOnClientUnsubscribe((e) =>
{
// Tear down a P2P link.
var peerId = e.UnsubscribedClient.ClientId.ToString();
Conference.Unlink(peerId);
}));
}
}