Connecting to the Signalling Server

The IceLink SDK allows users to participate in peer to peer video conferences, but before users can communicate with each other, they have to agree on how to communicate. Participants must use some other mechanism to negotiate the details of their session before they can start sending audio and video data. This is known as signalling. You may use whatever framework you like for your application's signalling, but this guide assumes that you will use WebSync. Configuring a WebSync server is beyond the scope of this guide. Refer to the WebSync Documentation if you need help with this.

Connecting to the WebSync Server

The application component that connects to the WebSync server is known as a WebSync client. To connect to the WebSync server, create a new instance of the FM.WebSync.Client class. Specify the WebSync server URL as the first parameter; this should be a full URL, including a scheme and a path, as shown below.

var client = new FM.WebSync.Client("https://v4.websync.fm/websync.ashx");
fm.websync.Client client = new fm.websync.Client("https://v4.websync.fm/websync.ashx");
FMWebSyncClient *client = [FMWebSyncClient clientWithRequestUrl:@"https://v4.websync.fm/websync.ashx"];
var client = FMWebSyncClient(requestUrl: "https://v4.websync.fm/websync.ashx")
var client = new fm.websync.client("https://v4.websync.fm/websync.ashx");


Once you have created your Client instance, you connect to the WebSync server by invoking its Connect method. You may specify OnSuccess and OnFailure callbacks for this action, which will be called when the connection attempt either succeeds or fails. This is demonstrated below.

client.Connect(new ConnectArgs
{
 OnSuccess = (FM.WebSync.ConnectSuccessArgs e) =>
    {
        Console.WriteLine("connected to websync");
    },
    OnFailure = (FM.WebSync.ConnectFailureArgs e) =>
    {
        Console.WriteLine("failed to connect to websync");
    }
});

fm.websync.ConnectArgs args = new fm.websync.ConnectArgs();

args.setOnSuccess(new fm.SingleAction<fm.websync.ConnectSuccessArgs>() {
    public void invoke(fm.websync.ConnectSuccessArgs e) {
        System.out.println("connected to websync");
    }
});

args.setOnFailure(new fm.SingleAction<fm.websync.ConnectFailureArgs>() {
    public void invoke(fm.websync.ConnectFailureArgs e) {
        System.out.println("failed to connect to websync");
    }
});

client.connect(args);
FMWebSyncConnectArgs* args = [FMWebSyncConnectArgs connectArgs];

[args setOnSuccessBlock: ^(FMWebSyncConnectSuccessArgs* e) {
    NSLog(@"connected to websync");
}];

[args setOnFailureBlock:^(FMWebSyncConnectFailureArgs* e) {
    NSLog(@"failed to connect to websync");
}];

[client connectWithConnectArgs: args];
var connectArgs = FMWebSyncConnectArgs()

connectArgs.setOnSuccess { (e:FMWebSyncConnectSuccessArgs) in
    print("connected to websync")
}

connectArgs.setOnFailure { (e:FMWebSyncConnectFailureArgs) in
    print("failed to connect to websync")
}

client.connectWithConnectArgs(FMWebSyncConnectArgs())
client.connect({
    onSuccess: function(e) {
        console.log("connected to websync");
    },
    onFailure: function(e) {
        console.log("failed to connect to websync");
    }
});


You have now successfully connected to your WebSync server. Next, you'll learn how to associate a username with a connected client.

Specifying a Username

With WebSync, you can bind arbitrary pieces of metadata to a particular client. Each piece of metadata is a key-value pair known as a record. These records will be available to other clients remotely. This is commonly used to associate a name for a client, so that other clients have something to refer to them by. To bind a record, you invoke the Bind method as shown below. The BindArgs parameter object takes two parameters, a string representing the data record's key and a string representing the data record's JSON-encoded value. As with the Connect method, you can specify success and failure callbacks.

client.Bind(new FM.WebSync.BindArgs("name", @"""Clark Kent""")
{
    OnSuccess = (FM.WebSync.BindSuccessArgs e) =>
    {
        Console.WriteLine("bound a record");
    },
    OnFailure = (FM.WebSync.BindFailureArgs e) =>
    {
        Console.WriteLine("failed to bind a record");
    }
}
fm.websync.BindArgs args = new fm.websync.BindArgs("name", "\"Bruce Wayne\"");

args.setOnSuccess(new fm.SingleAction<fm.websync.BindSuccessArgs>() {
    public void invoke(fm.websync.BindSuccessArgs e) {
        System.out.println("bound a record");
    }
});

args.setOnFailure(new fm.SingleAction<fm.webysnc.BindFailureArgs>() {
    public void invoke(fm.websync.BindSuccessArgs e) {
        System.out.println("failed to bind a record");
    }
});

client.bind(args);

FMWebSyncBindArgs* args = [FMWebSyncBindArgs bindArgsWithKey:@"name" valueJson:@"\"Peter Parker\""];

[args setOnSuccessBlock: ^(FMWebSyncBindSuccessArgs* e) {
    NSLog(@"bound a record");
}];

[args setOnFailureBlock: ^(FMWebSyncBindFailureArgs* e) {
    NSLog(@"failed to bind a record");
}];

[client bindWithBindArgs:args];
var args = FMWebSyncBindArgs(record: FMWebSyncRecord(key: "name", valueJson: "\"Barry Allen\""))

args.setOnSuccess { (e:FMWebSyncBindSuccessArgs) in
    print("bound a record")
}

args.setOnFailure { (e:FMWebSyncBindFailureArgs) in
    print("failed to bind a record")
}

client.bind(bindArgs: args)
client.bind({
    record: {
        key: "name",
        value: "\"Diana Prince\""
    },

    onSuccess: function(e) {
        console.log("bound a record");
    },
    onFailure: function(e) {
        console.log("failed to bind a record");
    }
});

The name you specified above will now be available to all other clients, as will any other records that you bound to the client. You can associate as many records with a specific client as your application requires.

Disconnecting from WebSync

When a client has no more media sessions to participate in, it should disconnect from the media server. To disconnect, invoke the Disconnect method of your Client instance. You can add an OnComplete event handler to be notified with this is complete. This is demonstrated below.

client.Disconnect(new FM.WebSync.DisconnectArgs {
    OnComplete = (FM.WebSync.DisconnectCompleteArgs e) =>
    {
        Console.WriteLine("disconnected");
    }
});

fm.websync.DisconnectArgs args = new fm.websync.DisconnectArgs();

args.setOnComplete(new fm.SingleAction<fm.websync.DisconnectCompleteArgs>() {
    public void invoke(fm.websync.DisconnectCompleteArgs e) {
        System.out.println("disconnected");
    }
});

client.disconnect(args);
FMWebSyncDisconnectArgs* args = [FMWebSyncDisconnectArgs disconnectArgs]; 
[args setOnOnCompleteBlock: ^(FMWebSyncDisconnectCompleteArgs* e) {
    NSLog(@"disconnected");
}];

[client disconnect:args];
var args = new FMWebSyncDisconnectArgs()

args.setOnComplete { (e:FMWebSyncDisconnectCompleteArgs) in
    print("disconnected");
}

client.disconnect(args);
client.disconnect({
    onComplete: function(e) {
        console.log("disconnected");
    }
});

Wrapping Up

You now know how to setup WebSync signalling in your application. The next sections will focus on working with users' audio and video data. Even further on, you will learn how to use this signalling to help send this audio and video data to other users.