Channels
A channel is an established connection between two VT modules.
Start channel/output.
public void Start(string device = null)
{
var message = new
{
type = "command",
to = Manager.Id,
command = new
{
command = "channel_start",
channel = Name,
props = Manager.Name == "_VT_MNG_RCV_" ? $"mode='{device ?? "NDI"}'" : "",
},
};
Action<SocketIOResponse> callback = (response) => Console.WriteLine($"<-- response: {response}");
Client.Emit("request", message, callback);
}
Stop channel/output.
public void Stop()
{
var message = new
{
type = "command",
to = Manager.Id,
command = new
{
command = "channel_stop",
channel = Name,
props = "",
},
};
Action<SocketIOResponse> callback = (response) => Console.WriteLine($"<-- response: {response}");
Client.Emit("request", message, callback);
}
message, callback);
}
Get channel properties values (statistics).
callback
[
{
"channel": "mp://mplaylist",
"channelState": 3,
"channelType": 3,
"objectName": "VT_Publisher [hpH4R3SLtsNp5NCT]",
"previewURL": "[<https://vt08.medialooks.com:8080/CDqjLuf4CFwkkeW+>]",
"props": [ // props values
{
"type": "mp"
},
{
"video_format": "[email protected] 48.0:4ch"
},
{
"video_fps": "24.00"
},
{
"stat::status": "(Web20:0) Ready for connect VT20 GW:3 W:0 C:0 "
}
],
"type": "info"
},
null
]
ppublic async Task<string> GetProps(string name)
{
var request = new
{
type = "command",
to = Manager.Id,
command = new
{
command = "channel_info_get",
channel = Name,
props = new string[] { name },
},
};
string value = null;
Action<SocketIOResponse> callback = (response) =>
{
Console.WriteLine($"<-- response: {response}");
try
{
value = response.GetValue(0)
.GetProperty("props")
.EnumerateArray()
.Select(i => i.EnumerateObject().FirstOrDefault())
.First()
.Value
.ToString();
}
catch (Exception e)
{
Console.WriteLine($"exception: {e.Message}");
}
};
Client.Emit("request", request, callback);
await Task.Delay(500);
return value;
}
Set channel props values
Remove channel props.
Get a picture from the channel.
callback
[
{
"binary": {
"type": "Buffer",
"data": [...] // byte array of frame image in JPG format
},
"payload": {
"channel": "USB Video Device",
"msec_updated": "0.087000",
"objectName": "VT_Publisher [VO0Ero58L6lA8iub]",
"type": "image",
"vt_getimage_msec": "922",
"vt_time": "1653593491843"
},
"to": [],
"type": "command"
},
null
]
public void GetFrame()
{
var request = new
{
type = "command",
to = Manager.Id,
command = new
{
command = "channel_frame_get",
channel = Name,
maxWidth = 300,
maxHeight = 250,
},
};
Action<SocketIOResponse> callback = (response) =>
{
Console.WriteLine($"<-- response: {response}");
try
{
if (response.GetValue(0).TryGetProperty("binary", out var binary))
{
byte[] buffer = binary.GetProperty("data")
.EnumerateArray()
.Select(i => i.GetByte())
.ToArray();
using var stream = new MemoryStream(buffer);
Application.Current.Dispatcher.Invoke(() =>
{
var window = new FrameWindow() { Owner = Application.Current.MainWindow };
var image = new BitmapImage();
image.BeginInit();
image.StreamSource = stream;
image.EndInit();
window.Image.Source = image;
window.ShowDialog();
});
}
}
catch (Exception e)
{
Console.WriteLine($"exception: {e.Message}");
}
};
Client.Emit("request", request, callback);
}
Get the Web Guest settings.
callback
[
null,
{
"type": "command:response",
"command": {
"type": "webguest:control:get"
},
"response": [ // setting collection
{
"name": "Name", // display name (to show on UI)
"fieldName": "name", // inner field name
"value": "Guest1178" // value
},
{
"name": "Location",
"fieldName": "location",
"value": "Web"
},
{
"name": "Resolution",
"fieldName": "resolution",
"value": "640x480",
"options": [ // collection of possible values for selectors
{
"value": "320x240", // value
"label": "320x240" // label to show on UI
},
{
"value": "640x360",
"label": "640x360"
},
...
]
},
...
]
}
]
public async Task<string> GetWebGuestSettings()
{
string peerId = await GetProps("peer::id");
var request = new
{
type = "command",
to = peerId,
command = new
{
type = "webguest:control:get",
},
};
string settings = null;
Action<SocketIOResponse> callback = (response) =>
{
Console.WriteLine($"<-- response: {response}");
try
{
if (response.GetValue(0).GetString() == null)
{
settings = response.GetValue(1).GetProperty("response").GetRawText();
}
}
catch (Exception e)
{
Console.WriteLine($"exception: {e.Message}");
}
};
Client.Emit("request", request, callback);
await Task.Delay(200);
return settings;
}
Set the Web Guest settings.
message
{
"type": "command",
"to": "YaQ2BMnUvaw7vzMJSI5SP", // channel peer id from "peer:id" props value
"command": { // settings collection (see settings format in webguest:control:get)
"type": "webguest:control:set",
"settings": [
{
"name": "Name",
"fieldName": "name",
"value": "GuestTest"
},
{
"name": "Location",
"fieldName": "location",
"value": "Web"
},
{
"name": "Resolution",
"fieldName": "resolution",
"value": "640x480",
"options": [
{
"value": "320x240",
"label": "320x240"
},
{
"value": "640x360",
"label": "640x360"
},
{
"value": "640x480",
"label": "640x480"
},
...
]
},
...
]
}
}
Last modified 1yr ago