`,
link: (scope:any, element, attr) => {
var link = scope.$eval('podLink');
var name = scope.$eval('containerName');
if (!link) {
return;
}
scope.fetched = false;
scope.previous = false;
scope.messages = [];
link = UrlHelpers.join(masterApiUrl(), link, 'log');
link = KubernetesAPI.wsUrl(link);
link.search({
follow: true,
tailLines: 1000,
access_token: userDetails.token
});
var messages = [];
var pullMessages = _.debounce(() => {
scope.messages = scope.messages.concat(_.remove(messages, () => true).map((msg) => {
PodLogReplacements.forEach((replFunc:any) => {
if (angular.isFunction(replFunc)) {
msg = replFunc(msg);
}
});
return msg;
}));
if (!scope.fetched) {
scope.fetched = true;
}
Core.$apply(scope);
}, 1000);
function initSocket(link) {
scope.fetched = false;
messages.length = 0;
scope.messages.length = 0;
var ws = new WebSocket(link.toString(), 'base64.binary.k8s.io');
ws.onmessage = (event) => {
try {
var message = window.atob(event.data);
messages.push(message);
pullMessages();
} catch (err) {
// we'll just ignore these
//log.debug("Failed to decode message: ", event.data, " error: ", err);
}
}
return ws;
}
var ws = initSocket(link);
scope.$watch('previous', (value, old) => {
if (value !== old) {
if (link.hasSearch('previous')) {
link.removeSearch('previous').addSearch('previous', scope.previous);
} else {
link.addSearch('previous', scope.previous);
}
ws.close();
ws = initSocket(link);
}
});
element.on('$destroy', () => {
if (ws) {
try {
ws.close();
} catch (err) {
// nothing to do
}
delete ws;
}
});
}
}
});
_module.directive('podLogWindow', ($compile, TerminalService) => {
return {
restrict: 'A',
scope: false,
link: (scope:any, element, attr) => {
addWindowActions(scope, element, TerminalService);
scope.atBottom = true;
scope.$watch('atBottom', (val) => {
});
}
};
});
}