summaryrefslogtreecommitdiff
path: root/init.js
blob: d8dc5ae61e0a09c093fbfd769d7c7896f506af2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
imports.gi.versions.GLib = '2.0';
imports.gi.versions.GObject = '2.0';
imports.gi.versions.Gio = '2.0';

imports.gi.versions.Gdk = '3.0';
imports.gi.versions.Gtk = '3.0';

imports.gi.versions.Clutter = '1.0';
imports.gi.versions.Gst = '0.10';
imports.gi.versions.GstBase = '0.10';
imports.gi.versions.GstVideo = '0.10';

const Mainloop = imports.mainloop;

const IcecastClient = imports.icecastClient;
const Panel = imports.panel;

const GLib = imports.gi.GLib;
const GObject = imports.gi.GObject;
const Gio = imports.gi.Gio;

const Gdk = imports.gi.Gdk;
const Gtk = imports.gi.Gtk;

const Clutter = imports.gi.Clutter;
const Mx = imports.gi.Mx;

const Gst = imports.gi.Gst;
const ClutterGst = imports.gi.ClutterGst;

let application = null;
let style = null;
let stage = null;
let stageLayout = null;

_init();

function _initApplication() {
    Gtk.init(null, null);

    let settings = Gtk.Settings.get_default();
    settings.gtk_application_prefer_dark_theme = true;

    application = new Gtk.Application({ application_id: 'org.gnome.LiveMeetFeed' });
}

function _initGStreamer() {
    Gst.init(null, null);
    Gst.debug_set_active(true);
    Gst.debug_set_default_threshold(Gst.DebugLevel.WARNING);
    Gst.debug_set_colored(false);
}

function _initStyle() {
    style = Mx.Style.get_default();
    style.load_from_file('default.css');
}

function _initStage() {
    Clutter.init(null, null);

    stage = Clutter.Stage.get_default();
    stage.set_size(512, 512);
    stage.set_user_resizable(true);
    stage.connect('delete-event',
                  function() {
                      Mainloop.quit('');
                      return true;
                  });
    stage.set_title("Live Meet Feed");

    stageLayout = new Mx.BoxLayout({ name: 'stage-layout',
                                     orientation: Mx.Orientation.VERTICAL });
    stage.add_actor(stageLayout);

    stageLayout.add_constraint(new Clutter.BindConstraint({ source:     stage,
                                                            coordinate: Clutter.BindCoordinate.SIZE }));
    stageLayout.add_constraint(new Clutter.BindConstraint({ source:     stage,
                                                            coordinate: Clutter.BindCoordinate.POSITION }));
}

function _init() {
    _initApplication();
    _initGStreamer();
    _initStyle();
    _initStage();

    let pipeline = Gst.Pipeline.new('feed-pipeline');

    let texture = new Clutter.Texture({ name: 'video-texture' });
    stageLayout.add_actor(texture, -1);
    stageLayout.child_set_expand(texture, true);
    stageLayout.child_set_y_fill(texture, true);
    stageLayout.child_set_y_align(texture, 0.0);
    texture.show();

    let source = Gst.ElementFactory.make('camerabin', 'camera-source');
    pipeline.add(source);

    let sink = new ClutterGst.VideoSink({ texture: texture });
    source.viewfinder_sink = sink;

    pipeline.set_state(Gst.State.PLAYING);

    let panel = new Panel.Panel();
    stageLayout.add_actor(panel.actor, -1);
    stageLayout.child_set_expand(panel.actor, false);
    stageLayout.child_set_x_align(panel.actor, 0.0);
    stageLayout.child_set_x_fill(panel.actor, true);
    stageLayout.child_set_y_align(panel.actor, 1.0);
    stageLayout.child_set_y_fill(panel.actor, false);

    panel.connect('toggle-fullscreen',
                  function () {
                      stage.set_fullscreen(!stage.get_fullscreen());
                  });

    stage.show_all();
    Mainloop.run('');
}